Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore duplicate resource error during terraform apply?

I am trying to reapply my changes using terraform apply but when I am doing it again , it gives me error with resource already exists and stops the deployment .

Example:

Error: AlreadyExistsException: An alias with the name arn:aws:kms:us-east-1:490449857273:alias/continuedep-cmk-us-east-1 already exists
        status code: 400, request id: 4447fd20-d33b-4c87-891e-cc5e09cc6108

  on ../../../modules/kms_cmk/main.tf line 11, in resource "aws_kms_alias" "keyalias":
  11: resource "aws_kms_alias" "keyalias" {



Error: Error creating DB Subnet Group: DBSubnetGroupAlreadyExists: The DB subnet group 'continuedep-sbg' already exists.
        status code: 400, request id: 97d662b6-79d4-4fde-aaf7-a2f3e5a0bd9e

  on ../../../modules/rds-postgres/main.tf line 2, in resource "aws_db_subnet_group" "generic_db_subnet_group":
   2: resource "aws_db_subnet_group" "generic_db_subnet_group" {

Likewise i get errors with many other existing resources.I want to avoid/ignore such errors and continue my deployment .

What other way i can use from which I can restart my terraform resource deployment from where it is interrupted in the middle.

My terraform version is : Terraform v0.12.9

like image 409
KanikaM Avatar asked Jan 15 '20 19:01

KanikaM


1 Answers

The errors are returned by the API the Terraform provider is calling.

Possible causes of this could be:

  • you ( or someone else ) have executed your Terraform code and you don't have a shared / updated state
  • someone have created them manually
  • a Terraform destroy failed in a way that deleted the resources for the API but failed to save the update state

solutions depends on what you need. You can:

  • delete those resources from your Terraform code to stop managing them with it
  • delete those resources from the API ( cloud provider ) and recreate them with Terraform
  • Perform a terraform import of those resources and remove the terraform code that is trying to recreate them (NOT RECOMMENDED)
  • use terraform apply --target=xxx to apply only resources you need to apply (NOT RECOMMENDED)
like image 156
RoviNX Avatar answered Oct 16 '22 08:10

RoviNX