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

cloud_sql_instance volumes in google_cloud_run_v2_service inconsistent ordering #20360

Open
lyricnz opened this issue Nov 16, 2024 · 2 comments

Comments

@lyricnz
Copy link

lyricnz commented Nov 16, 2024

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

❯ terraform version
OpenTofu v1.8.5
on darwin_amd64
+ provider registry.opentofu.org/hashicorp/google v6.11.2

Affected Resource(s)

google_cloud_run_v2_service

Terraform Configuration

resource "google_cloud_run_v2_service" "default" {
  name = "cloudrun-service"

  location            = "us-central1"
  project             = "innablr-dev"

  template {
    execution_environment = "EXECUTION_ENVIRONMENT_GEN2"

    containers {
      image = "us-docker.pkg.dev/cloudrun/container/hello"
      volume_mounts {
        name       = "bucket"
        mount_path = "/var/www"
      }
      volume_mounts {
        name       = "cloudsql"
        mount_path = "/cloudsql"
      }
    }

    volumes {
      name = "cloudsql"
      cloud_sql_instance {
        instances = ["innablr-dev:australia-southeast2:innablr-dev"]
      }
    }

    volumes {
      name = "bucket"
      gcs {
        bucket    = google_storage_bucket.default.name
        read_only = false
      }
    }
  }
}

resource "google_storage_bucket" "default" {
  name     = "innablr-test-junk-cloudrun-service"
  location = "US"
  project  = "innablr-dev"
}

Debug Output

terraform2.log

Expected Behavior

terraform plan should show no changes

Actual Behavior

terraform plan wants to swap the order of the volumes. even if I apply this, the next plan/apply is the same.

❯ TF_LOG=debug TF_LOG_PATH=terraform2.log terraform apply
google_storage_bucket.default: Refreshing state... [id=innablr-test-junk-cloudrun-service]
google_cloud_run_v2_service.default: Refreshing state... [id=projects/innablr-dev/locations/us-central1/services/cloudrun-service]

OpenTofu used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

OpenTofu will perform the following actions:

  # google_cloud_run_v2_service.default will be updated in-place
  ~ resource "google_cloud_run_v2_service" "default" {
      ~ deletion_protection     = false -> true
        id                      = "projects/innablr-dev/locations/us-central1/services/cloudrun-service"
        name                    = "cloudrun-service"
        # (26 unchanged attributes hidden)

      ~ template {
            # (7 unchanged attributes hidden)

          ~ volumes {
              ~ name = "bucket" -> "cloudsql"

              + cloud_sql_instance {
                  + instances = [
                      + "innablr-dev:australia-southeast2:innablr-dev",
                    ]
                }

              - gcs {
                  - bucket    = "innablr-test-junk-cloudrun-service" -> null
                  - read_only = false -> null
                }
            }
          ~ volumes {
              ~ name = "cloudsql" -> "bucket"

              - cloud_sql_instance {
                  - instances = [
                      - "innablr-dev:australia-southeast2:innablr-dev",
                    ] -> null
                }

              + gcs {
                  + bucket    = "innablr-test-junk-cloudrun-service"
                  + read_only = false
                }
            }

            # (2 unchanged blocks hidden)
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Steps to reproduce

  1. terraform plan

Important Factoids

It looks like google-side API is returning the volumes in a particular order (cloudsql last?) which doesn't match what we're setting. If we SWAP the order of declaration of the volumes, then it plan/apply clean.

2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:     "volumes": [
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:       {
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         "name": "bucket",
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         "gcs": {
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:           "bucket": "innablr-test-junk-cloudrun-service"
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         }
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:       },
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:       {
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         "name": "cloudsql",
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         "cloudSqlInstance": {
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:           "instances": [
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google: "innablr-dev:australia-southeast2:innablr-dev"
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:           ]
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:         }
2024-11-16T15:58:17.128+1100 [DEBUG] provider.terraform-provider-google:       }

The same thing happens with the volume_mounts attribute.

References

#13368
GoogleCloudPlatform/magic-modules#8929

b/379910668

@wiktorn
Copy link

wiktorn commented Nov 16, 2024

Looks like the API is returning the entries in the lexicographical order by name and requires the same order in the resource. While it is possible to comply with this requirement when using bare resources, it is impossible to do that within modules that use dynamic to provide module mounts depending on the inputs without requiring users to specify correct volume names.

EDIT: actually it is solvable in the modules.

@ggtisc ggtisc self-assigned this Nov 19, 2024
@ggtisc
Copy link
Collaborator

ggtisc commented Nov 19, 2024

Confirmed permadiff issue

@ggtisc ggtisc removed their assignment Nov 19, 2024
@ggtisc ggtisc removed the forward/review In review; remove label to forward label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants