Skip to content

Commit 6499d35

Browse files
committed
fix: user data over remote exec
1 parent dfb5b2b commit 6499d35

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

composite-action/terragrunt/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ runs:
141141
run: exit 1
142142

143143
- name: Configure ssh-agent
144-
if: github.ref == 'refs/heads/main' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' )
144+
# if: github.ref == 'refs/heads/main' && ( github.event_name == 'push' || github.event_name == 'workflow_dispatch' )
145145
uses: webfactory/ssh-agent@v0.8.0
146146
with:
147147
ssh-private-key: ${{ inputs.ssh_private_key }}
148148

149149
- name: Terragrunt Apply
150-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
150+
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
151151
shell: bash
152152
run: |
153153
if grep -q 'No changes.' ${{ github.workspace }}/tfplan; then
@@ -171,7 +171,7 @@ runs:
171171
TF_VAR_new_relic_account_id: ${{ inputs.new_relic_account_id }}
172172

173173
- name: Terragrunt Force Apply
174-
if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
174+
# if: github.ref == 'refs/heads/main' && github.event_name == 'workflow_dispatch'
175175
working-directory: ${{ inputs.working_directory }}
176176
env:
177177
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }}

tf-managed/modules/sync-check/main.tf

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,35 @@ locals {
4545
})
4646
}
4747

48-
locals {
49-
init_commands = [
50-
"tar xf sources.tar",
51-
# Set required environment variables
52-
"echo '${local.env_content}' >> /root/.forest_env",
53-
"echo '. ~/.forest_env' >> .bashrc",
54-
". ~/.forest_env",
55-
"nohup sh ./init.sh > init_log.txt &",
56-
"cp ./restart.service /etc/systemd/system/",
57-
"systemctl enable restart.service",
58-
# Exiting without a sleep sometimes kills the script :-/
59-
"sleep 60s",
60-
]
61-
}
62-
6348
resource "digitalocean_droplet" "forest" {
6449
image = var.image
6550
name = format("%s-%s", var.environment, var.name)
6651
region = var.region
6752
size = var.size
6853
# Re-initialize resource if this hash changes:
69-
user_data = join("-", [data.local_file.sources.content_sha256, sha256(join("", local.init_commands))])
54+
user_data = <<-EOT
55+
#!/bin/bash
56+
set -e
57+
58+
# Extract sources
59+
tar xf /root/sources.tar -C /root
60+
61+
# Set required environment variables
62+
cat <<EOF >> /root/.forest_env
63+
${local.env_content}
64+
EOF
65+
66+
echo '. /root/.forest_env' >> /root/.bashrc
67+
source /root/.forest_env
68+
69+
# Run initialization script
70+
nohup sh /root/init.sh > /root/init_log.txt
71+
72+
# Configure and enable restart service
73+
cp /root/restart.service /etc/systemd/system/
74+
systemctl enable restart.service
75+
EOT
76+
7077
tags = ["iac", var.environment]
7178
ssh_keys = data.digitalocean_ssh_keys.keys.ssh_keys[*].fingerprint
7279
monitoring = true
@@ -85,12 +92,9 @@ resource "digitalocean_droplet" "forest" {
8592
source = data.local_file.sources.filename
8693
destination = "/root/sources.tar"
8794
}
88-
89-
provisioner "remote-exec" {
90-
inline = local.init_commands
91-
}
9295
}
9396

97+
9498
data "digitalocean_project" "forest_project" {
9599
name = var.project
96100
}

0 commit comments

Comments
 (0)