Skip to content

Commit 86eee59

Browse files
MukeshMukesh
authored andcommitted
update
1 parent d0f074c commit 86eee59

2 files changed

Lines changed: 56 additions & 58 deletions

File tree

modules/vault/install.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Update and install dependencies
5+
sudo apt update -y
6+
sudo apt install -y unzip jq
7+
8+
# Install Vault
9+
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
10+
echo "deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
11+
sudo apt update && sudo apt install -y vault
12+
13+
# Create Vault configuration file
14+
cat <<EOT | sudo tee /etc/vault.hcl
15+
storage "s3" {
16+
bucket = "custom-vault-data-bucket"
17+
region = "us-west-2"
18+
}
19+
20+
listener "tcp" {
21+
address = "0.0.0.0:8200"
22+
tls_disable = 1
23+
}
24+
25+
ui = true
26+
EOT
27+
28+
# Set Vault environment variables
29+
echo 'export VAULT_ADDR="http://127.0.0.1:8200"' | sudo tee -a /etc/profile
30+
echo 'export PATH=$PATH:/usr/local/bin' | sudo tee -a /etc/profile
31+
source /etc/profile
32+
33+
# Create systemd service for Vault
34+
sudo tee /etc/systemd/system/vault.service <<EOT
35+
[Unit]
36+
Description=Vault Server
37+
Requires=network-online.target
38+
After=network-online.target
39+
40+
[Service]
41+
User=root
42+
Group=root
43+
ExecStart=/usr/bin/vault server -config=/etc/vault.hcl
44+
ExecReload=/bin/kill --signal HUP \$MAINPID
45+
Restart=on-failure
46+
LimitNOFILE=65536
47+
48+
[Install]
49+
WantedBy=multi-user.target
50+
EOT
51+
52+
# Reload systemd and start Vault
53+
sudo systemctl daemon-reload
54+
sudo systemctl enable vault
55+
sudo systemctl start vault

modules/vault/main.tf

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -119,64 +119,7 @@ resource "aws_instance" "vault" {
119119
subnet_id = var.subnet_id
120120

121121

122-
user_data = <<-EOF
123-
#!/bin/bash
124-
set -e
125-
126-
# Update and install dependencies
127-
sudo apt update -y
128-
sudo apt install -y unzip jq
129-
130-
# Install Vault
131-
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
132-
echo "deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
133-
sudo apt update && sudo apt install -y vault
134-
135-
# Create Vault configuration file
136-
cat <<EOT | sudo tee /etc/vault.hcl
137-
storage "s3" {
138-
bucket = "custom-vault-data-bucket"
139-
region = "us-west-2"
140-
}
141-
142-
listener "tcp" {
143-
address = "0.0.0.0:8200"
144-
tls_disable = 1
145-
}
146-
147-
ui = true
148-
EOT
149-
150-
# Set Vault environment variables
151-
echo 'export VAULT_ADDR="http://127.0.0.1:8200"' | sudo tee -a /etc/profile
152-
echo 'export PATH=$PATH:/usr/local/bin' | sudo tee -a /etc/profile
153-
source /etc/profile
154-
155-
# Create systemd service for Vault
156-
sudo tee /etc/systemd/system/vault.service <<EOT
157-
[Unit]
158-
Description=Vault Server
159-
Requires=network-online.target
160-
After=network-online.target
161-
162-
[Service]
163-
User=root
164-
Group=root
165-
ExecStart=/usr/bin/vault server -config=/etc/vault.hcl
166-
ExecReload=/bin/kill --signal HUP \$MAINPID
167-
Restart=on-failure
168-
LimitNOFILE=65536
169-
170-
[Install]
171-
WantedBy=multi-user.target
172-
EOT
173-
174-
# Reload systemd and start Vault
175-
sudo systemctl daemon-reload
176-
sudo systemctl enable vault
177-
sudo systemctl start vault
178-
179-
EOF
122+
user_data = "${file("install.sh")}"
180123

181124
tags = {
182125
Name = "Vault-Server"

0 commit comments

Comments
 (0)