Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 978cc2a

Browse files
author
Riaan Nolan
committed
Merge branch 'features/terraform-with-localstack-refactor' into 'master'
update terraform and localstack providers See merge request all-staff/hashiqube!114
1 parent 0d5bcae commit 978cc2a

File tree

4 files changed

+34
-35
lines changed

4 files changed

+34
-35
lines changed

Vagrantfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ Vagrant::configure("2") do |config|
200200
# vagrant up --provision-with docsify to only run this on vagrant up
201201
config.vm.provision "docsify", type: "shell", preserve_order: true, privileged: false, path: "docsify/docsify.sh"
202202

203-
# install terraform
204-
# vagrant up --provision-with terraform to only run this on vagrant up
205-
config.vm.provision "terraform", preserve_order: true, type: "shell", privileged: true, path: "hashicorp/terraform.sh"
206-
207203

208204
# blast-radius
209205

@@ -243,6 +239,10 @@ Vagrant::configure("2") do |config|
243239
# vagrant up --provision-with sentinel to only run this on vagrant up
244240
config.vm.provision "sentinel", type: "shell", preserve_order: true, privileged: true, path: "hashicorp/sentinel.sh"
245241

242+
# install terraform
243+
# vagrant up --provision-with terraform to only run this on vagrant up
244+
config.vm.provision "terraform", preserve_order: true, type: "shell", privileged: true, path: "hashicorp/terraform.sh"
245+
246246
# install localstack
247247
# vagrant up --provision-with localstack to only run this on vagrant up
248248
config.vm.provision "localstack", run: "never", type: "shell", preserve_order: true, privileged: false, path: "localstack/localstack.sh"

hashicorp/packer/linux/ubuntu/playbook.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
owner: root
1010
- name: Return all kv v2 secrets from a path
1111
debug:
12-
msg: "{{ lookup('hashi_vault', 'secret=kv/ansible token=hvs.CAESIK2fsE_LCBTs3Ikw0d0O4QD9acJSMHZBA873CMnkMOGVGh4KHGh2cy5uOTFGQUFESkhsOWI4RUY5UHFoYlY3U1c url=http://localhost:8200') }}"
12+
msg: "{{ lookup('hashi_vault', 'secret=kv/ansible token=hvs.CAESIK_jalLHH-zeL02jowquVi9yQ1ZzSdnELVLJPDZcYuM4Gh4KHGh2cy52emtKM0VuMkNrOXpKMTBLSVlEZDYxSUE url=http://localhost:8200') }}"

hashicorp/terraform.sh

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/bin/bash
22

33
function terraform-install() {
4-
5-
# ensure localstack is running
6-
# echo -e '\e[38;5;198m'"++++ Ensure Localstack is running.."
7-
# sudo bash /vagrant/localstack/localstack.sh
84

95
arch=$(lscpu | grep "Architecture" | awk '{print $NF}')
106
if [[ $arch == x86_64* ]]; then
@@ -24,34 +20,19 @@ function terraform-install() {
2420
(cd /usr/local/bin && unzip /tmp/terraform.zip)
2521
echo -e '\e[38;5;198m'"++++ Installed: `/usr/local/bin/terraform version`"
2622
fi
27-
sudo -i -u vagrant
2823
pip3 install --upgrade awscli-local
29-
rm awscliv2.zip
24+
export PATH=$HOME/.local/bin:$PATH
25+
sudo rm -rf awscliv2.zip
3026
# https://aws.amazon.com/blogs/developer/aws-cli-v2-now-available-for-linux-arm/ aarch64
3127
curl -s "https://awscli.amazonaws.com/awscli-exe-linux-${arch}.zip" -o "awscliv2.zip"
32-
rm -rf aws
33-
unzip -q awscliv2.zip
28+
sudo unzip -q awscliv2.zip
3429
yes | sudo ./aws/install --update
3530
echo -e '\e[38;5;198m'"++++ aws --version"
3631
aws --version
37-
cd /vagrant/localstack/
38-
echo -e '\e[38;5;198m'"++++ terraform init.."
39-
terraform init
40-
echo -e '\e[38;5;198m'"++++ terraform fmt.."
41-
terraform fmt
42-
echo -e '\e[38;5;198m'"++++ terraform validate.."
43-
terraform validate
44-
echo -e '\e[38;5;198m'"++++ terraform destroy.."
45-
terraform destroy --auto-approve
46-
echo -e '\e[38;5;198m'"++++ terraform plan.."
47-
terraform plan
48-
echo -e '\e[38;5;198m'"++++ terraform apply.."
49-
terraform apply --auto-approve
50-
echo -e '\e[38;5;198m'"++++ awslocal s3 ls.."
51-
sudo -i -u vagrant
52-
cd /vagrant/localstack/
53-
export PATH=$HOME/.local/bin:$PATH
54-
awslocal s3 ls || true
32+
33+
# ensure localstack is running
34+
echo -e '\e[38;5;198m'"++++ To Terraform plan, and apply using Localstack, run the following command: vagrant up --provision-with localstack"
35+
echo -e '\e[38;5;198m'"++++ See Localstack folder for Terraform files"
5536
}
5637

5738
terraform-install

localstack/localstack.sh

+22-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ elif [[ $arch == aarch64 ]]; then
1212
fi
1313
echo -e '\e[38;5;198m'"CPU is $ARCH"
1414

15-
sudo -i -u vagrant
1615
pip3 install --upgrade awscli-local
17-
rm awscliv2.zip
16+
sudo rm -rf awscliv2.zip
1817
# https://aws.amazon.com/blogs/developer/aws-cli-v2-now-available-for-linux-arm/ aarch64
1918
curl -s "https://awscli.amazonaws.com/awscli-exe-linux-${arch}.zip" -o "awscliv2.zip"
20-
rm -rf aws
21-
unzip -q awscliv2.zip
19+
sudo rm -rf aws
20+
sudo unzip -q awscliv2.zip
2221
yes | sudo ./aws/install --update
2322
echo -e '\e[38;5;198m'"aws --version"
2423
aws --version
@@ -28,3 +27,22 @@ sudo -E docker stop localstack_main
2827
yes | sudo docker system prune --volumes
2928
sudo docker run --rm -it -d -p 4566:4566 -p 4571:4571 --rm --privileged --memory 256M --name localstack_main localstack/localstack
3029
sudo docker ps | grep localstack
30+
31+
cd /vagrant/localstack/
32+
export PATH=$HOME/.local/bin:$PATH
33+
echo -e '\e[38;5;198m'"++++ removing previous state files.."
34+
rm -rf ./terraform.tfstate*
35+
echo -e '\e[38;5;198m'"++++ terraform init.."
36+
terraform init
37+
echo -e '\e[38;5;198m'"++++ terraform fmt.."
38+
terraform fmt
39+
echo -e '\e[38;5;198m'"++++ terraform validate.."
40+
terraform validate
41+
echo -e '\e[38;5;198m'"++++ terraform plan.."
42+
terraform plan
43+
echo -e '\e[38;5;198m'"++++ terraform apply.."
44+
terraform apply --auto-approve
45+
echo -e '\e[38;5;198m'"++++ awslocal s3 ls.."
46+
awslocal s3 ls || true
47+
echo -e '\e[38;5;198m'"++++ terraform destroy.."
48+
terraform destroy --auto-approve

0 commit comments

Comments
 (0)