terraform-aws-tfstate-backend icon indicating copy to clipboard operation
terraform-aws-tfstate-backend copied to clipboard

Bucket replication managed by this module

Open schollii opened this issue 5 years ago • 2 comments

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Currently the bucket for replicating tf state as backup must be created manually. It would be really useful to have the module create it, since it is inherently tied to the backend setup.

Expected Behavior

When bucket replication is turned on, the module requires another region to be specified in the file, and a bucket name. It will create that bucket in the new region.

Use Case

Currently I have to create a replication bucket myself then give its ARN to the backend module. This is extra work that could easily be encapsulated into this module.

schollii avatar Nov 24 '20 17:11 schollii

This is actually by design. If we added provisioning of the second bucket, we would change the interface to the module by always requiring a secondary provider to be passed to the module. It also complicates the naming convention of the bucket resource, as the secondary bucket should be disambiguated from the primary bucket. Our convention is to use the environment to connote the region (e.g. ue2 for us-east-2), but since we allow the user to provision that secondary bucket - they can name it whatever they want. Furthermore, by not defining the secondary destination within the module, it allows for maximum flexibility of the secondary bucket. The caller can provision that secondary bucket using this module using whatever other settings they want. It's also how we manage it in our reference architecture.

osterman avatar Nov 24 '20 17:11 osterman

So you mean the HCL2 does not currently support provider being enabled / disabled so it would always have to be given even if replication is not desired?

What about in that case providing a module that creates an s3 bucket suitable as a tfstate bucket replica for referencing in the backend module vars?

schollii avatar Nov 27 '20 11:11 schollii

Closing as "wontfix". @schollii for your reference:

What about in that case providing a module that creates an s3 bucket suitable as a tfstate bucket replica for referencing in the backend module vars?

You can use https://github.com/cloudposse/terraform-aws-s3-bucket

Nuru avatar Apr 23 '23 21:04 Nuru

I ended up creating my own https://registry.terraform.io/modules/schollii/multi-stack-backends

because I needed more automation than what the cloudposse module provided.

schollii avatar Apr 24 '23 02:04 schollii