amazon-web-servicesterraformterraform-provider-awsinfrastructure-as-code

Define lifecycle check (globally) to avoid redeployment of ALL resources if tags are changed


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.


Solution

  • 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: