Skip to content

Support dynamic lifecycle configuration in Terraform modules #393

@fbtravi

Description

@fbtravi

Terraform currently does not allow variables inside the lifecycle block. For example, this is not allowed:

Copiar
Editar
variable "ignore_changes" {
  type    = list(string)
  default = ["template[0].containers"]
}

resource "google_cloud_run_v2_service" "example" {
  name     = "example-service"
  location = "us-central1"

  lifecycle {
    ignore_changes = var.ignore_changes
  }
}

This results in errors like:
A static list expression is required
Functions or variables may not be called here

Problem:

We cannot dynamically pass values to the lifecycle block via variables. This limits module reusability and makes it difficult to manage resources that are updated outside Terraform. In our case, we maintain separate repositories for application code and infrastructure, and the application pipeline deploys new Docker images directly, so Terraform should not override those updates.

Proposed idea:

Provide a Cloud Run V2 module with the lifecycle block predefined and safe, including the right ignore_changes.
This allows the application code to be deployed via CLI or CI/CD while Terraform continues to manage the infrastructure.

Goal:

Allow modules to safely handle updates outside Terraform without duplicating resources or hardcoding lifecycle values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions