Fix: s3 terraform state bucket naming#74
Draft
cstirry wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a new deployer runs
uv run opencontext authenticate, all checks pass cleanly — Python, uv, AWS CLI, credentials, and Terraform. But then when they runuv run opencontext configureand complete the CLI wizard, it fails at the end with no useful explanation:The root cause is that the S3 bucket name for Terraform state was hardcoded to
opencontext-terraform-state. S3 bucket names are globally/regionally? unique across all AWS accounts — this name is already owned by another account, so any new deployer hits a 403 with no actionable error message.How to reproduce the original bug
uv run opencontext authenticate— all checks passuv run opencontext configureand complete the wizardPotential Fix
1. Interactive bucket name prompt with immediate validation
Instead of silently using a hardcoded bucket name, the wizard now prompts the user during the AWS Settings step. The default suggestion is
opencontext-terraform-statebut the user can change it. The bucket is validated immediately — if it's owned by another account, the user is told right away and re-prompted before continuing.2. Always run
terraform init -reconfigureThe original code skipped
terraform initif a.terraformdirectory already existed. This caused a failure on re-runs when the bucket name changed — Terraform detected a backend config change and refused to proceed. Replacing the existence check with-reconfigureensures the backend config is always in sync.3. New
_check_state_bucket()helperExtracted bucket validation into a clean helper that returns
"ok","missing", or"taken"without crashing Rich's markup renderer with raw AWS error text.Files changed
cli/commands/configure.py— all logic changestests/test_cli_configure.py— updated wizard responses and assertionstests/test_cli_configure_extended.py— addedboto3.clientmock and bucket prompt response to all wizard testsNote on Terraform files
terraform/bootstrap/variables.tfandterraform/aws/main.tfstill containthe hardcoded default
opencontext-terraform-state. These are not changed inthis PR because
configure.pypasses the bucket name to Terraform at init timevia
-backend-config=bucket=<name>, which overrides the hardcoded default atruntime.
However, anyone running
terraform initdirectly (bypassing the CLI) wouldstill hit the same naming collision. May want to consider updating those files
to remove the hardcoded default if that could be an issue.
Screenshot Before
Screenshot After