Explorar o código

feat(terraform): Add the terraform stack

Signed-off-by: Jeremy MAURO <jeremy.mauro@gmail.com>
Jeremy MAURO %!s(int64=3) %!d(string=hai) anos
pai
achega
3d688a06bb

+ 4 - 0
base.rb

@@ -37,6 +37,10 @@ named_run_list :user, [
   'workstation::_user',
 ]
 
+named_run_list :terraform, [
+  'workstation::_terraform',
+]
+
 named_run_list :genie, [
   'resolver_config::_dokken',
   'workstation::_genie',

+ 35 - 0
cookbooks/apt_repositories/recipes/_terraform.rb

@@ -0,0 +1,35 @@
+#
+# Cookbook:: apt_repositories
+# Recipe:: _terraform
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+#
+# Cookbook:: workstation
+# Recipe:: _podman
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+
+include_recipe 'apt_repositories::_packages'
+
+remote_file ::File.join(Chef::Config['file_cache_path'], 'hashicorp.key') do
+  source 'https://apt.releases.hashicorp.com/gpg'
+  action :create_if_missing
+end
+
+key_path = '/etc/apt/trusted.gpg.d'
+keygpg = ::File.join(key_path, 'hashicorp.gpg')
+
+execute 'GPG key for Hashicorp' do
+  command "cat #{::File.join(Chef::Config['file_cache_path'], 'hashicorp.key')} | gpg --dearmor | tee #{keygpg} > /dev/null"
+  not_if { ::File.exist?(keygpg) }
+end
+
+apt_repository 'hashicorp' do
+  arch 'amd64'
+  uri 'https://apt.releases.hashicorp.com'
+  distribution lazy { Mixlib::ShellOut.new('lsb_release -cs').run_command.stdout.chomp }
+  components %w{main}
+  deb_src false
+  action :add
+end

+ 12 - 0
cookbooks/workstation/recipes/_terraform.rb

@@ -0,0 +1,12 @@
+#
+# Cookbook:: workstation
+# Recipe:: _terraform
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+#
+
+include_recipe 'apt_repositories::_terraform'
+
+package %w{
+  terraform
+}

+ 3 - 0
cookbooks/workstation/recipes/default.rb

@@ -29,6 +29,9 @@ include_recipe 'workstation::_genie'
 # Add defaut packages
 include_recipe 'workstation::_packages'
 
+# Setup terraform
+include_recipe 'workstation::_terraform'
+
 # END: Setup etckeeper
 include_recipe 'etckeeper'
 include_recipe 'etckeeper::commit'

+ 29 - 0
cookbooks/workstation/spec/unit/recipes/_terraform_spec.rb

@@ -0,0 +1,29 @@
+#
+# Cookbook:: workstation
+# Spec:: _terraform
+#
+# Copyright:: 2022, The Authors, All Rights Reserved.
+
+require 'spec_helper'
+
+describe 'workstation::_terraform' do
+  context 'When all attributes are default, on Ubuntu 20.04' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'ubuntu', '20.04'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+
+  context 'When all attributes are default, on CentOS 8' do
+    # for a complete list of available platforms and versions see:
+    # https://github.com/chefspec/fauxhai/blob/main/PLATFORMS.md
+    platform 'centos', '8'
+
+    it 'converges successfully' do
+      expect { chef_run }.to_not raise_error
+    end
+  end
+end

+ 16 - 0
cookbooks/workstation/test/integration/default/_terraform_test.rb

@@ -0,0 +1,16 @@
+# Chef InSpec test for recipe workstation::_terraform
+
+# The Chef InSpec reference, with examples and extensive documentation, can be
+# found at https://docs.chef.io/inspec/resources/
+
+unless os.windows?
+  # This is an example test, replace with your own test.
+  describe user('root'), :skip do
+    it { should exist }
+  end
+end
+
+# This is an example test, replace it with your own test.
+describe port(80), :skip do
+  it { should_not be_listening }
+end