Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform shows difference for gce-container-declaration after some time #143

Open
enricojonas opened this issue Oct 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@enricojonas
Copy link

enricojonas commented Oct 4, 2024

When using the output metadata_value which the module produces, after some time terraform shows a difference.

It seems that the compute engine API internally modifies the metadata gce-container-declaration after some time.

My observations show that the following is happening:

  • A banner is inserted on top
      # DISCLAIMER:
      # This container declaration format is not a public API and may change without
      # notice. Please use gcloud command-line tool or Google Cloud Console to run
      # Containers on Google Compute Engine.
  • all quotes are removed from the declaration yaml.

That means, if you apply after some time again, those changes are shown in the plan.

Expected behavior

There should not be any changes shown if no changes have been done.

Observed behavior

Changes are shown after some time.

Terraform will perform the following actions:

  # module.xxx.google_compute_instance.xxxx will be updated in-place
  ~ resource "google_compute_instance" "xxxx" {
        id                        = "projects/xxx/zones/europe-west1-b/instances/xxx"
      ~ metadata                  = {
          ~ "gce-container-declaration" = <<-EOT
              - # DISCLAIMER:
              - # This container declaration format is not a public API and may change without
              - # notice. Please use gcloud command-line tool or Google Cloud Console to run
              - # Containers on Google Compute Engine.
              - 
              - spec:
              -   containers:
              -   - image: europe-west4-docker.pkg.dev/xxx/xxx/xxx
              -     securityContext:
              -       fs_group: 999
              -       run_as_user: 999
              -   restartPolicy: OnFailure
              + "spec":
              +   "containers":
              +   - "image": "europe-west4-docker.pkg.dev/xxx/xxx/xxx"
              +     "securityContext":
              +       "fs_group": 999
              +       "run_as_user": 999
              +   "restartPolicy": "OnFailure"
            EOT
            # (4 unchanged elements hidden)
        }
        name                      = "xxx"
        tags                      = [
            "xxx",
            "xxx",
            "xxx",
        ]
        # (23 unchanged attributes hidden)

        # (8 unchanged blocks hidden)
    }

Terraform Configuration

module "gce-container" {
  source  = "terraform-google-modules/container-vm/google"
  version = "3.2.0" # Upgrade the version if necessary.

  container = {
    image = "europe-west4-docker.pkg.dev/xxx/xxx/xxx"

    securityContext = {
      run_as_user : 999
      fs_group : 999
    }
...

resource "google_compute_instance" "xxx" {
...
...

  metadata = {
    # Required metadata key.
    gce-container-declaration = module.gce-container.metadata_value
    google-logging-enabled    = "true"
    google-monitoring-enabled = "true"
    enable-oslogin            = "true"
    block-project-ssh-keys    = "true"
  }
...

Terraform Version

Terraform v1.9.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v6.5.0

Additional information

Currently, I have implemented the following workaround. Maybe the module could make use of a similar workaround as yamlencode function is limited to wrap all keys and values in quotes.

locals {
  # Needed because google is inserting this after sometime automatically.
  metadata_missing_banner = <<-EOT
# DISCLAIMER:
# This container declaration format is not a public API and may change without
# notice. Please use gcloud command-line tool or Google Cloud Console to run
# Containers on Google Compute Engine.
EOT
}

  metadata = {
    # Required metadata key.
    gce-container-declaration = join("\n", [local.metadata_missing_banner, replace(module.gce-container.metadata_value, "\"", "")])
@enricojonas enricojonas added the bug Something isn't working label Oct 4, 2024
Copy link

github-actions bot commented Dec 3, 2024

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label Dec 3, 2024
@enricojonas
Copy link
Author

It's still an issue.

@github-actions github-actions bot removed the Stale label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant