terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Duplicate backend configuration on remote.tf.json

Open angeloCabezas opened this issue 3 years ago • 8 comments
trafficstars

Good Morning,

I have the next question, every time that I execute "cdktf synth" it creates a remote.tf.json, cdk.tf.json and some extra files.

Then when I tried to execute Terraform plan I get the next error :

image

what it is right, because checking the remote.tf.json inside it, I have this

image

another terraform backend, I would like to know how to avoid this issue, because currently I'm using a automatic process which is using "cdktf synth" and after than "Terraform plan" and it fails.

Basically I dont want to create in the cdk.tf.json automatically

"terraform": {
    "backend": {
      "local": {
        "path": "C:\\D\\Cignium\\LM\\GitHubRepo\\infrastructure\\Platforms.LM.IAC\\src\\TerraformStack\\terraform.lm.tfstate"
      }
    },

Many thanks.

angeloCabezas avatar Mar 24 '22 05:03 angeloCabezas

Are you using Terraform Cloud? Do you have an azurerm backend configured somewhere?

The local backend is added automatically if no other backends are configured within the stack.

jsteinich avatar Mar 24 '22 22:03 jsteinich

Hi @jsteinich

Yes, I'm using terraform. Yes, it was configured in two places, so I take one out.

Ok I see this last version brings backend in the same file, gotcha.

Trying to set up terraform init, I got the following errors, looks like the way to set up is different ??

image

According to what I read that is because of "Backend Local". Could you pls walk me thought ?

I need to run this "cdktf synth" and get the cdk.tf.json with "Backend" ready to apply the command above.

Many thanks.

angeloCabezas avatar Mar 24 '22 23:03 angeloCabezas

Normally cdktf takes care of running terraform init. Your cdktf code can read in the configuration for a file, environment variable, or other sources.

If you do want to continue using terraform directly that should also be possible. It looks like you want to use Azure, so just define an instance of AzurermBackend within your code and put placeholders in place.

jsteinich avatar Mar 25 '22 11:03 jsteinich

Hi @jsteinich

Gotcha, many thanks for the help !

Regards

angeloCabezas avatar Mar 26 '22 00:03 angeloCabezas

@angeloCabezas Do I read it correctly that the issue is solved?

DanielMSchmidt avatar Mar 29 '22 09:03 DanielMSchmidt

On a related note: We're still referring to this.addOverride('terraform.backend' in some places and should upgrade that to using the RemoteBackend as using an override is not detected by the logic that inserts a LocalBackend as a fallback if none was found. E.g. our docs still recommend to use an override but they don't mention that one would need to clear the terraform.backend.local via an override, too (a user figured this out here).

ansgarm avatar Apr 12 '22 13:04 ansgarm

I've got the duplication of all resources using the local state. I've got this behaviour two time already. I have no idea whats going on.

a0s avatar Jul 03 '22 23:07 a0s

Hi @a0s, could you share some example code where this happens? I'm especially interested in any backend configuration and overrides. Also: are you using a monorepo and/or locally linked npm modules?

ansgarm avatar Jul 11 '22 09:07 ansgarm

Hi there! 👋 We haven't heard from you in 30 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.

github-actions[bot] avatar Dec 06 '22 02:12 github-actions[bot]

I'm closing this issue because we haven't heard back in 60 days. ⌛️ If you still need help, feel free to comment or reopen the issue!

github-actions[bot] avatar Jan 06 '23 02:01 github-actions[bot]

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Feb 06 '23 01:02 github-actions[bot]