Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a hash to the user data scripts so terraform will see changes exist and replace them as needed #49

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions s3.tf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you store the loaded template file contents into a local car so we're not loading it twice? Small thing, but I think it will make this read slightly better and require changes in less places in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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))
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you happen to double check that using sensitive here translates to the value being obfuscated when used in the terraforming of the s3 object below?

Copy link
Author

@cbailey6079 cbailey6079 Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did see that the values were obfuscated in the terraform or what i believe was this file. Obviously the file has all the keys in plain text in s3.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

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)
}
Loading