Home > database >  Ignoring already configured resources in Terraform - AWS
Ignoring already configured resources in Terraform - AWS

Time:06-21

There is a terraform code to configure an MWAA Environment in AWS. When it runs second time, no need to create IAM role or policy again. So it gives an error.

How to ignore the creation of existing resources in TF?

CodePudding user response:

I assume that you applied a Terraform plan which created resource "MWAA", then you somehow lost the state (locally stored and lost?, or the state wasn't shared with a different client?), then you re-apply the plan again, and Terraform informs you that it created "MWAA", again.

In that case, your main problem is that you lost the state, and you need to make sure that you do persist it, e.g., by storing it in a bucket.

However, if you really need to make Terraform aware about an already created resource, you need to put it in Terraform's state. One tool to do that is "terraform import", about which you can read more here: https://www.terraform.io/cli/import

CodePudding user response:

If you already have the statefile and if terraform is trying to re-install it again, then may be some tag change or modified timestamp value change...

In order to avoid it, you can specify the resource you want to apply using a terraform apply command..

terraform apply --target=resource 
  • Related