Alternative way for variables in S3 backend

Variables are not supported in S3 backend I need alternative way to do this can any one suggests I go through online some are saying terragrunt some are say like python, workspaces.environments.Actually we are built some Dev environment for clients from the app they will enter the details like for ec2 they will enter count, ami, type from here all are fine but with the backend state file issue which does not support variables I need to change every time bucket name,path.Can some one please explain me the structure and sample code to resolve this thanks in advance. #23208

Hey @venu1428,

As you’ve stated it is not possible to use interpolated values in the Terraform block itself.

If you are looking for a solution to generate a pre-runtime of terraform then two of the options you mentioned should be able to do that.

  • terragrunt
  • custom file generator script (this could be Python, just a is aware of HCL syntax and templatizes that in a way)

It depends on your use case. If you only planning on creating these files with generated Terraform blocks in bulk once or twice, I would personally write a bash or Python script to achieve this.

Otherwise, I would configure it to be compatible with Terragrunt as it seems to do precisely what you are looking for. A tutorial covering dynamically creating an S3 remote backend using variables can be found on Gruntwork’s Medium blog.

Additionally, the official terragrunt README has a relevant snippet on to generate an remote backend block on S3.

@mpmsimo Thanks for the responce

I got error try to get the source from terragrunt.


terraform {

Deploy version v0.0.3 in stage

source = “”

I got error like
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


" I would personally write a bash or Python script to achieve this."can you give a example for this one to refer.