-
Notifications
You must be signed in to change notification settings - Fork 0
[PLT-890] add legacy variable to tfstate service and create backends #212
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
Conversation
|
AB2D SBX TF plan is failing, looks like aws_iam_account_alias doesn't exist in that account? |
gfreeman-navapbc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but these buckets seem to only exist in the non-prod account atm, just something to be aware of
I see now that there's a resource we're creating for these before the data call, disregard |
gsf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform/modules/bucket/main.tf
Outdated
| bucket = "${data.aws_caller_identity.current.account_id}-bucket-access-logs" | ||
| bucket = (var.legacy == true ? "${data.aws_caller_identity.current.account_id}-bucket-access-logs" : | ||
| data.aws_iam_account_alias.current.account_alias == "aws-cms-oeda-bcda-non-prod" ? "bucket-access-logs-20250409172631068600000001" : | ||
| "bucket-access-logs-tbd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "tbd" can be replaced with the suffix for the access logs bucket created in the prod account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
gsf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also switch out the deprecated dynamodb_table for use_lockfile in these new backends (see https://developer.hashicorp.com/terraform/language/backend/s3#state-locking). Those dynamodb tables will also need to be removed, and the tfstate terraform will need to be updated to avoid creating tables in greenfield.
…use_lockfile = true in tfstate/terraform
gsf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| role-to-assume: arn:aws:iam::${{ secrets.BCDA_ACCOUNT }}:role/delegatedadmin/developer/bcda-mgmt-github-actions | ||
| aws-region: ${{ vars.AWS_REGION }} | ||
| - run: terraform init -backend-config=../../backends/bcda-mgmt.s3.tfbackend | ||
| - run: terraform init -backend-config=../../backends/bcda-test.s3.tfbackend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be kept at bcda-mgmt for now to support the legacy accounts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
terraform/.terraform-version
Outdated
| @@ -1 +1 @@ | |||
| 1.5.5 | |||
| 1.10.0 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we're updating, we should switch to the latest patch under 1.10, which would be 1.10.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| @@ -0,0 +1 @@ | |||
| bucket = "ab2d-dev-tfstate" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have a suffix on the bucket name? Also, please run terraform fmt over these files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| @@ -1,2 +1 @@ | |||
| bucket = "ab2d-dev-tfstate" | |||
| dynamodb_table = "ab2d-dev-tfstate" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dynamodb_table attribute should be kept for legacy backends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update your editor configuration to end files with a newline.
| @@ -0,0 +1,3 @@ | |||
| bucket = "ab2d-prod-tfstate-20250411202936776600000001" | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop these extra newlines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| backend "s3" { | ||
| key = "tfstate/terraform.tfstate" | ||
| key = "tfstate/terraform.tfstate" | ||
| use_lockfile = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use_lockfile attribute should be in the backend files for greenfield.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| key = "github-actions/terraform.tfstate" | ||
| } | ||
| required_version = "~> 1.5.5" | ||
| required_version = "~> 1.10.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop this required_version
Remove mgmt env in greenfield
revert workflow changes
gsf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and should be ready to merge once tfstate resources are all created (and extras cleaned up).
# Conflicts: # terraform/backends/ab2d-sandbox-gf.s3.tfbackend # terraform/backends/bcda-sandbox-gf.s3.tfbackend # terraform/backends/dpc-sandbox-gf.s3.tfbackend
|
|
||
| terraform { | ||
| # Comment out backend block and init without -backend-config for initial creation of resources | ||
| # # Comment out backend block and init without -backend-config for initial creation of resources |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # # Comment out backend block and init without -backend-config for initial creation of resources | |
| # Comment out backend block and init without -backend-config for initial creation of resources |
terraform/modules/bucket/main.tf
Outdated
| bucket = data.aws_s3_bucket.bucket_access_logs.bucket | ||
|
|
||
| target_bucket = data.aws_s3_bucket.bucket_access_logs.bucket |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sets the wrong bucket as the source bucket for logging. Patch incoming.
terraform/modules/bucket/main.tf
Outdated
| module "bucket_key" { | ||
| source = "../key" | ||
| name = "${var.name}-bucket" | ||
| name = data.aws_s3_bucket.bucket_access_logs.bucket |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key is for the bucket created in this module, not the access logs bucket. Patch incoming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think we may run into issues if we start renaming all of the kms keys in legacy.
gsf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're good to merge
🎫 Ticket
https://jira.cms.gov/browse/PLT-890
🛠 Changes
backend files defining s3 state buckets for greenfield apps
ℹ️ Context
Add backends to the TF in the platform repo (each backend is a 2-line file for each of the vpcs). We expect to have 12 new VPCs.
🧪 Validation
Buckets are created in S3 with tfstate files for each new backend definition file.