skip to Main Content

How to define lifecycle check to avoid redeployment of resources if tags are changed

When i am using:

terraform {
  required_version = ">=1.0"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.0.0"
    }
  }
}

provider "aws" {
  region  = var.aws_region
  lifecycle {
    ignore_changes = [
      # Ignore changes to tags, e.g. because a management agent
      # updates these based on some ruleset managed elsewhere.
      tags,
    ]
  }
}

I am getting error:
The block type name "lifecycle" is reserved for use by Terraform in a future version.

2

Answers


  1. Chosen as BEST ANSWER

    Terraform doesn't redeploy resources if tags are added or removed.


  2. The ignore_changes should be set at the resource level, not the provider.

    Example:

    resource "aws_instance" "web" {
      ami           = "ami-0c94855ba95c574c8"
      instance_type = "t3.micro"
    
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    }
    

    Some notes:

    • The arguments corresponding to the given attribute names are considered when planning a create operation, but are ignored when planning an update.
    • Instead of a list, the special keyword all may be used to instruct Terraform to ignore all attributes, which means that Terraform can create and destroy the remote object but will never propose updates to it.
    • Only attributes defined by the resource type can be ignored. ignore_changes cannot be applied to itself or to any other meta-arguments.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search