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

Errors when attempting to use GCS volumes in cloud-run-v2 #2684

Closed
lyricnz opened this issue Nov 14, 2024 · 6 comments · Fixed by #2686
Closed

Errors when attempting to use GCS volumes in cloud-run-v2 #2684

lyricnz opened this issue Nov 14, 2024 · 6 comments · Fixed by #2686
Assignees

Comments

@lyricnz
Copy link
Contributor

lyricnz commented Nov 14, 2024

Describe the bug
Cannot use the new support for GCS volumes in cloud-run-v2. Is it broken, or am I doing it wrong?

It was added:
#2638

Environment

output from `terraform -version`

❯ terraform -version
OpenTofu v1.8.4
on darwin_amd64
+ provider registry.opentofu.org/hashicorp/google v6.11.1
+ provider registry.opentofu.org/hashicorp/google-beta v6.11.1
output from `git rev-parse --short HEAD`

❯ git rev-parse --short HEAD
f1b074b5

To Reproduce
Steps to reproduce the behavior
Add a "volumes" stanza to a cloud-run-v2 module-resource in terraform:

  volumes = {
    xxx = {
      gcs = {
        bucket = "my-bucket-name"
        is_read_only = false
      }
    }
  }

Expected behavior
A clear and concise description of what you expected to happen.
Cloudrun to be created with this volume.

It works fine with the underlying provider:

# WORKS
resource "google_cloud_run_v2_service" "spam" {
  name = "dummy1"
  location     = "us-central1"
  launch_stage = "BETA"
  project = var.project_id

  template {
    execution_environment = "EXECUTION_ENVIRONMENT_GEN2"

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

    volumes {
      name = "bucket"
      gcs {
        bucket = "my-bucket-name"
        read_only = false
      }
    }
  }
}

So problem seems to be in service.tf https://github.com/GoogleCloudPlatform/cloud-foundation-fabric/blob/master/modules/cloud-run-v2/service.tf#L208 which may be generating incorrect dynamic content?? I don't know how to debug this.

    dynamic "volumes" {
      for_each = var.volumes
      content {
        name = volumes.key
        dynamic "gcs" {
          for_each = volumes.value.gcs == null ? [] : [""]
          content {
            bucket    = volumes.value.bucket
            read_only = volumes.value.is_read_only
          }
        }
      }
    }
  }

Result
Terraform output and/or error messages

Plan: 1 to add, 1 to change, 1 to destroy.
╷
│ Error: Unsupported attribute
│
│   on ../../../modules/cloud-run-v2/service.tf line 211, in resource "google_cloud_run_v2_service" "service":
│  211:             bucket    = volumes.value.bucket
│     ├────────────────
│     │ volumes.value is object with 5 attributes
│
│ This object does not have an attribute named "bucket".
╵
╷
│ Error: Unsupported attribute
│
│   on ../../../modules/cloud-run-v2/service.tf line 212, in resource "google_cloud_run_v2_service" "service":
│  212:             read_only = volumes.value.is_read_only
│     ├────────────────
│     │ volumes.value is object with 5 attributes
│
│ This object does not have an attribute named "is_read_only".
╵```


**Additional context**
Add any other context about the problem here
@wiktorn
Copy link
Collaborator

wiktorn commented Nov 14, 2024

This looks like a bug, let me take a look at it.

@wiktorn wiktorn self-assigned this Nov 14, 2024
@lyricnz
Copy link
Contributor Author

lyricnz commented Nov 14, 2024

Should it be using each.key and each.value rather than volumes.key and volumes.value? #noob

@wiktorn
Copy link
Collaborator

wiktorn commented Nov 14, 2024

Should it be using each.key and each.value rather than volumes.key and volumes.value? #noob

Close :-)

@lyricnz
Copy link
Contributor Author

lyricnz commented Nov 14, 2024

Cool! Will try that in the morning.

@lyricnz
Copy link
Contributor Author

lyricnz commented Nov 15, 2024

The fix (mostly) worked for me. Needed to add gen2_execution_environment = true also (which isn't in the example code)

@lyricnz
Copy link
Contributor Author

lyricnz commented Nov 16, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants