HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Skip terraform resource if it exists

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
existsskipresourceterraform

Problem

I'm Getting an error creating a secret because it was created manually.

Error: error creating Secrets Manager Secret: ResourceExistsException: The operation failed because the secret  already exists.


Is there any way to tell Terraform to skip creating a resource if it already exists ?

Solution

after terraform 0.12 we have ways to control it using lifecycle we can simply skip resource by setting up lifecycle

resource "aws_instance" "web" {
    ami = "foo"
    lifecycle {
        ignore_changes = ["ami"]
    }
}


Here is the link of bug
https://github.com/hashicorp/terraform/pull/2525

Code Snippets

resource "aws_instance" "web" {
    ami = "foo"
    lifecycle {
        ignore_changes = ["ami"]
    }
}

Context

StackExchange DevOps Q#16888, answer score: 2

Revisions (0)

No revisions yet.