Skip to content

Commit

Permalink
Merge pull request #49 from 7Factor/clayton/user-data-template-fix
Browse files Browse the repository at this point in the history
Adding a hash to the user data scripts so terraform will see changes exist and replace them as needed
  • Loading branch information
dumptruckman committed Apr 26, 2024
2 parents 80f8002 + 5026bfb commit 2113729
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
locals {
web_user_data_content = sensitive(templatefile("${path.module}/templates/web_user_data.sh", local.web_interpolation_vars))
worker_user_data_content = sensitive(templatefile("${path.module}/templates/worker_user_data.sh", local.worker_interpolation_vars))
}

resource "aws_s3_bucket" "user_data" {
bucket = var.user_data_bucket_name
}
Expand Down Expand Up @@ -55,14 +60,17 @@ resource "aws_s3_object" "cw_agent_prometheus_init" {
})
}


resource "aws_s3_object" "web_user_data" {
bucket = aws_s3_bucket.user_data.id
key = "web_user_data.sh"
content = sensitive(templatefile("${path.module}/templates/web_user_data.sh", local.web_interpolation_vars))
bucket = aws_s3_bucket.user_data.id
key = "web_user_data.sh"
content = local.web_user_data_content
source_hash = md5(local.web_user_data_content)
}

resource "aws_s3_object" "worker_user_data" {
bucket = aws_s3_bucket.user_data.id
key = "worker_user_data.sh"
content = sensitive(templatefile("${path.module}/templates/worker_user_data.sh", local.worker_interpolation_vars))
bucket = aws_s3_bucket.user_data.id
key = "worker_user_data.sh"
content = local.worker_user_data_content
source_hash = md5(local.worker_user_data_content)
}

0 comments on commit 2113729

Please sign in to comment.