Skip to content

Use terraform's native s3 state locking#1476

Merged
cadmiumcat merged 4 commits into
mainfrom
native-s3-object-locking
Apr 16, 2025
Merged

Use terraform's native s3 state locking#1476
cadmiumcat merged 4 commits into
mainfrom
native-s3-object-locking

Conversation

@cadmiumcat
Copy link
Copy Markdown
Contributor

@cadmiumcat cadmiumcat commented Mar 25, 2025

What problem does this pull request solve?

In this PR we have enabled state locking for S3 backend so that we can stop using Dynamodb based locking, as it will be deprecated by terraform in future releases.

We have added permissions to ECS, the github runner and the engineer support role so that they can release state file locks.

We also introduced a default temporary name for existing dynamodb_table to help us remove it in future PRs.

Things that will happen in future PRs:

Trello card:

Things to consider when reviewing

I tested this by manually applying the changes to the ECS permissions in dev, then allowing the pipelines to apply the forms deployment to dev. I could see for each deployment, the terraform apply step creates a tflock file in the same bucket as the tfstate file. When the command finishes, terraform deletes the tflock file, which releases the lock.
Screenshot 2025-04-07 at 14 23 54

  • Have I missed any places where we're still using dynamodb?
  • Are there any missing permissions? and do the current ones make sense?

Reminders

If you've made changes to the deployer role (files in modules/deployer-access):

  • Remember to run make <environment> forms/account apply on the relevant environments (dev, staging, user-research, and/or prod)
  • Check the #govuk-forms-deployment-notifications Slack channel to ensure the apply-forms-terraform-<environment> pipelines have run successfully

@cadmiumcat cadmiumcat force-pushed the native-s3-object-locking branch 3 times, most recently from d84d448 to 3de1625 Compare March 25, 2025 12:10
@cadmiumcat cadmiumcat force-pushed the native-s3-object-locking branch 8 times, most recently from b70091c to 79ab7cc Compare April 11, 2025 12:14
@cadmiumcat cadmiumcat changed the title Native s3 object locking Use terraform's native s3 object locking Apr 11, 2025
@cadmiumcat cadmiumcat changed the title Use terraform's native s3 object locking Use terraform's native s3 state locking Apr 11, 2025
@cadmiumcat cadmiumcat force-pushed the native-s3-object-locking branch from 79ab7cc to 0b6460f Compare April 11, 2025 12:36
cadmiumcat added a commit that referenced this pull request Apr 11, 2025
Since we are using terraform's native s3 state locking
(#1476) we no longer need have
dynamodb tables or the permissions associated with it
@cadmiumcat cadmiumcat marked this pull request as ready for review April 11, 2025 13:36
Comment thread infra/deployments/integration/review/github_actions_runner.tf
cadmiumcat added a commit to govuk-forms/forms-admin that referenced this pull request Apr 14, 2025
@cadmiumcat cadmiumcat force-pushed the native-s3-object-locking branch from 0b6460f to 9c08bf5 Compare April 14, 2025 14:02
cadmiumcat added a commit that referenced this pull request Apr 14, 2025
Since we are using terraform's native s3 state locking
(#1476) we no longer need have
dynamodb tables or the permissions associated with it
cadmiumcat added a commit to govuk-forms/forms-admin that referenced this pull request Apr 15, 2025
Copy link
Copy Markdown
Contributor

@sarahseewhy sarahseewhy left a comment

Choose a reason for hiding this comment

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

This is a comprehensive, well thought out and well presented pull request. Thank you so much! Let's give it a whirl 🪄

Instead of using a dynamodb table we want to use terraform's new native locking
for s3 by enabling "use_lockfile".

We had previously introduced a dynamodb table to help the `init.sh` script to solve a
chicken and egg problem
(ff3c65c)
but we should be able to remove this now.
We'll want to delete the dynamodb tables after we have enabled native state
locking. For now we are renaming them with a default value so that they do not
depend on values we have removed.

This PR makes sure that the policies are still allowed to modify the dynamodb
tables
We do this by allowing them to delete the `.tflock` object. They should not be
allowed to delete state files
We need the support role to be able to `terraform apply`, therefore it needs to
be able to get/release the lock on state files.

The role also needs to be able to put objects in and get objects from the state
file buckets, but we already gave it those permissions as part of allowing it to
manage_maintenance_page.
@cadmiumcat cadmiumcat force-pushed the native-s3-object-locking branch from 8059c3b to 10e8f86 Compare April 16, 2025 07:20
@cadmiumcat cadmiumcat merged commit 698554b into main Apr 16, 2025
3 checks passed
@cadmiumcat cadmiumcat deleted the native-s3-object-locking branch April 16, 2025 07:45
cadmiumcat added a commit that referenced this pull request Apr 16, 2025
Since we are using terraform's native s3 state locking
(#1476) we no longer need have
dynamodb tables or the permissions associated with it
cadmiumcat added a commit that referenced this pull request Apr 17, 2025
Since we are using terraform's native s3 state locking
(#1476) we no longer need have
dynamodb tables or the permissions associated with it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants