-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Create required resources prior initialising terraform state file #18597
Comments
Hi @vutoff, Terraform doesn't automatically create things during Users usually resolve this "chicken and egg" problem by either manually creating the few required basic resources (AWS account, S3 Bucket, DynamoDB table) either via the UI or via a CLI tool. Given that these objects will never need to change again and they have well-known names (as opposed to generated ids) a lot of users just let these objects remain untracked by Terraform indefinitely and just document the special names as part of a recovery guide. If having everything managed by Terraform is important to you, you can bootstrap like this:
We may be able to smooth this later by having a module on Terraform Registry for each of the backends that contains the necessary objects for it to work and then have a special mode in Terraform init to perform the above steps with that module. For now though, I expect it'd be more straightforward to just update the backend documentation to explain how to do the above bootstrapping flow. |
I'm also facing the same issue here |
in the meanwhile, if you are using AWS, I would use a Cloudformation stack for the bucket and the dynamoDB. |
I have been dealing with this as well. I ended up having a repo called
Those are all duplicated across multiple environments. |
Terraform Version
Terraform Configuration Files
Context
First, I only use AWS so I'm not sure how this is solved in other backend providers.
I think it's a common problem that Terraform requires that all the resources part of the initial configuration should exist prior invoking
terraform init
. And that producechicken-egg
situation where something should be created and part of the state prior being able to initialise the same state.Such resources are S3 bucket holding the state as well as DynamoDB table for managing locks.
Possible solution
Now it'd be great if we could tell terraform to create those resources for us prior initialising the state and further put those resources into the state.
Creating a bucket is usually idempotent operation (if the bucket already exist it will simply return true).
Same should apply to DynamoDB tables, though configuration there might differ for different use cases.
The text was updated successfully, but these errors were encountered: