@@ -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