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

Commit 0d5bcae

Browse files
author
Riaan Nolan
committed
Merge branch 'features/arm64-support' into 'master'
fix packer and default provision, uplift localstack/variables.tf See merge request all-staff/hashiqube!113
1 parent 2b6a192 commit 0d5bcae

File tree

5 files changed

+111
-51
lines changed

5 files changed

+111
-51
lines changed

hashicorp/packer.sh

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

33
function packer-install() {
4+
5+
arch=$(lscpu | grep "Architecture" | awk '{print $NF}')
6+
if [[ $arch == x86_64* ]]; then
7+
ARCH="amd64"
8+
elif [[ $arch == aarch64 ]]; then
9+
ARCH="arm64"
10+
fi
11+
echo -e '\e[38;5;198m'"CPU is $ARCH"
12+
13+
if pgrep -x "vault" >/dev/null
14+
then
15+
echo "Vault is running"
16+
else
17+
echo -e '\e[38;5;198m'"++++ Ensure Vault is running.."
18+
sudo bash /vagrant/hashicorp/vault.sh
19+
fi
20+
421
grep -q "PACKER_LOG=1" /etc/environment
522
if [ $? -eq 1 ]; then
623
echo "PACKER_LOG=1" >> /etc/environment
@@ -11,15 +28,15 @@ function packer-install() {
1128
if [ $? -eq 1 ]; then
1229
echo "PACKER_LOG_PATH=/var/log/packer.log" >> /etc/environment
1330
else
14-
sudo sed 's/PACKER_LOG_PATH=.*/PACKER_LOG_PATH=/var/log/packer.log/g' /etc/environment
31+
sudo sed 's/PACKER_LOG_PATH=.*/PACKER_LOG_PATH=\/var\/log\/packer.log/g' /etc/environment
1532
fi
1633
sudo touch /var/log/packer.log
1734
sudo chmod 777 /var/log/packer.log
1835
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install curl unzip jq python3-hvac
1936
if [ -f /usr/local/bin/packer ]; then
2037
echo -e '\e[38;5;198m'"++++ `/usr/local/bin/packer version` already installed at /usr/local/bin/packer"
2138
else
22-
LATEST_URL=$(curl --silent https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "linux_amd.*64" | sort -rh | head -1 | awk -F[\"] '{print $4}')
39+
LATEST_URL=$(curl --silent https://releases.hashicorp.com/index.json | jq '{packer}' | egrep "linux.*$ARCH" | sort -rh | head -1 | awk -F[\"] '{print $4}')
2340
wget -q $LATEST_URL -O /tmp/packer.zip
2441
sudo mkdir -p /usr/local/bin
2542
(cd /usr/local/bin && unzip /tmp/packer.zip)
@@ -95,16 +112,10 @@ EOF
95112
if [ -f /usr/bin/docker ]; then
96113
echo -e '\e[38;5;198m'"++++ `/usr/bin/docker -v` already installed at /usr/bin/docker"
97114
else
98-
sudo DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes apt-transport-https ca-certificates curl gnupg-agent software-properties-common
99-
sudo -i
100-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
101-
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
102-
sudo apt-get update
103-
sudo DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes docker-ce docker-ce-cli containerd.io
104-
sudo usermod -aG docker vagrant
115+
sudo bash /vagrant/docker/docker.sh
105116
fi
106117
echo -e '\e[38;5;198m'"++++ Packer build Linux Docker container configured with Ansible"
107-
packer build /vagrant/hashicorp/packer/linux/ubuntu/ubuntu16.04.json
118+
packer build /vagrant/hashicorp/packer/linux/ubuntu/ubuntu20.04.json
108119
}
109120

110121
packer-install

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=s.4iQgdlmLwXQUFFxTsM9gLQtg url=http://localhost:8200') }}"
12+
msg: "{{ lookup('hashi_vault', 'secret=kv/ansible token=hvs.CAESIK2fsE_LCBTs3Ikw0d0O4QD9acJSMHZBA873CMnkMOGVGh4KHGh2cy5uOTFGQUFESkhsOWI4RUY5UHFoYlY3U1c url=http://localhost:8200') }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"variables": {
3+
"ansible_host": "default",
4+
"ansible_connection": "docker"
5+
},
6+
"builders": [
7+
{
8+
"type": "docker",
9+
"image": "ubuntu:20.04",
10+
"commit": "false",
11+
"discard": "true",
12+
"run_command": [
13+
"-d",
14+
"-i",
15+
"-t",
16+
"--name",
17+
"{{user `ansible_host`}}",
18+
"{{.Image}}",
19+
"/bin/bash"
20+
]
21+
}
22+
],
23+
"provisioners": [
24+
{
25+
"type": "shell",
26+
"inline": [
27+
"apt-get update",
28+
"apt-get install apt-utils python -yq"
29+
]
30+
},
31+
{
32+
"type": "ansible",
33+
"user": "root",
34+
"playbook_file": "/vagrant/hashicorp/packer/linux/ubuntu/playbook.yml",
35+
"extra_arguments": [
36+
"--extra-vars",
37+
"ansible_host={{user `ansible_host`}} ansible_connection={{user `ansible_connection`}}"
38+
]
39+
}
40+
]
41+
}

hashicorp/sentinel.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#!/bin/bash
22

33
function sentinel-install() {
4-
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install curl unzip jq
4+
arch=$(lscpu | grep "Architecture" | awk '{print $NF}')
5+
if [[ $arch == x86_64* ]]; then
6+
ARCH="amd64"
7+
elif [[ $arch == aarch64 ]]; then
8+
ARCH="arm64"
9+
fi
10+
echo -e '\e[38;5;198m'"CPU is $ARCH"
11+
12+
sudo DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install curl unzip jq
513
if [ -f /usr/local/bin/sentinel ]; then
614
echo -e '\e[38;5;198m'"++++ `/usr/local/bin/sentinel version` already installed at /usr/local/bin/sentinel"
715
else
8-
LATEST_URL=$(curl --silent https://releases.hashicorp.com/index.json | jq '{sentinel}' | egrep "linux_amd.*64" | sort -rh | head -1 | awk -F[\"] '{print $4}')
16+
LATEST_URL=$(curl --silent https://releases.hashicorp.com/index.json | jq '{sentinel}' | egrep "linux.*$ARCH" | sort -rh | head -1 | awk -F[\"] '{print $4}')
917
wget -q $LATEST_URL -O /tmp/sentinel.zip
1018
mkdir -p /usr/local/bin
1119
(cd /usr/local/bin && unzip /tmp/sentinel.zip)

localstack/variables.tf

+38-38
Original file line numberDiff line numberDiff line change
@@ -19,86 +19,86 @@ variable "ec2_instance" {
1919
)
2020
default = [
2121
{
22-
ami_id = 123
22+
ami_id = "ami-02e8cbf7681c3ae51"
2323
instance_type = "t1.micro"
24-
az = 123
24+
az = "ap-southeast-2"
2525
set_public_ip = false
26-
subnet_id = "oneal3j42rawefz"
26+
subnet_id = "subnet-07e73ebcae662e4a3"
2727
security_group = [
28-
"onealwijer"
28+
"dev-node"
2929
]
3030
tags = {
31-
apple = "onebanana"
32-
pear = "onepear"
31+
Name = "dev-node"
32+
Environment = "dev"
3333
}
3434
ebs_disks = [
3535
{
36-
disksize = 123
36+
disksize = 128
3737
encryption = true
38-
disktype = "oneone342ewrgs4"
39-
devicename = "oneonealij32krwe"
38+
disktype = "gp3"
39+
devicename = "/dev/sdg"
4040
},
4141
{
42-
disksize = 12
42+
disksize = 64
4343
encryption = false
44-
disktype = "onetwo342ewrgs4"
45-
devicename = "onetwoalij32krwe"
44+
disktype = "gp2"
45+
devicename = "/dev/sdf"
4646
}
4747
]
4848
},
4949
{
50-
ami_id = 123333
51-
instance_type = "t1.micro"
52-
az = 123333
50+
ami_id = "ami-02e8cbf7681c3ae51"
51+
instance_type = "t2.micro"
52+
az = "ap-southeast-2"
5353
set_public_ip = false
54-
subnet_id = "twoal3j42rawefz"
54+
subnet_id = "subnet-07e73ebcae662e4a3"
5555
security_group = [
56-
"twoalwijer"
56+
"dev-node"
5757
]
5858
tags = {
59-
apple = "twobanana"
60-
pear = "twopear"
59+
Name = "dev-node"
60+
Environment = "dev"
6161
}
6262
ebs_disks = [
6363
{
64-
disksize = 123
64+
disksize = 128
6565
encryption = true
66-
disktype = "twoone342ewrgs4"
67-
devicename = "twoonealij32krwe"
66+
disktype = "gp3"
67+
devicename = "/dev/sdf"
6868
},
6969
{
70-
disksize = 12
70+
disksize = 64
7171
encryption = false
72-
disktype = "twotwo342ewrgs4"
73-
devicename = "twotwoalij32krwe"
72+
disktype = "gp2"
73+
devicename = "/dev/sdg"
7474
}
7575
]
7676
},
7777
{
78-
ami_id = 126666
79-
instance_type = "t1.micro"
80-
az = 126666
78+
ami_id = "ami-02e8cbf7681c3ae51"
79+
instance_type = "t3.micro"
80+
az = "ap-southeast-2"
8181
set_public_ip = false
82-
subnet_id = "threeal3j42rawefz"
82+
subnet_id = "subnet-07e73ebcae662e4a3"
8383
security_group = [
84-
"threealwijer"
84+
"dev-node"
8585
]
8686
tags = {
87-
apple = "threebanana"
88-
pear = "threepear"
87+
Name = "dev-node"
88+
Environment = "dev"
8989
}
9090
ebs_disks = [
9191
{
92-
disksize = 123
92+
disksize = 128
9393
encryption = true
94-
disktype = "threene342ewrgs4"
95-
devicename = "threeonealij32krwe"
94+
disktype = "gp3"
95+
devicename = "/dev/sdf"
9696
},
9797
{
98-
disksize = 12
98+
disksize = 64
9999
encryption = false
100-
disktype = "threetwo342ewrgs4"
101-
devicename = "threetwoalij32krwe"
100+
disktype = "gp2"
101+
devicename = "/dev/sdg"
102102
}
103103
]
104104
}

0 commit comments

Comments
 (0)