Terraform-provider-google: google_cloudbuild_trigger requires trigger_template even for github triggers

Created on 16 Nov 2019  ·  4Comments  ·  Source: hashicorp/terraform-provider-google


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 the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

❯ terraform -v
Terraform v0.12.15
+ provider.google v2.20.0
+ provider.google-beta v3.0.0-beta.1

Affected Resource(s)

google-beta provider 3.0.0-beta.1
  • google_cloudbuild_trigger

Terraform Configuration Files

I imported this cloudbuild trigger and wrote the following TF file:

resource "google_cloudbuild_trigger" "collect" {
  provider = google-beta.project-name

  description = "Push to any branch"
  filename = "cloudbuild.yaml"

  trigger_template {
    branch_name = ".*"
  }

  github {
    owner = "organization_name"
    name = "collect"
    push {
      branch = ".*"
    }
  }
}

Terraform Plan output:

❯ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

google_cloudbuild_trigger.collect: Refreshing state... [id=projects/project-name/triggers/b577ea05-46e9-48ba-9fde-24fa619c8eb1]

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # google_cloudbuild_trigger.collect will be updated in-place
  ~ resource "google_cloudbuild_trigger" "collect" {
        create_time    = "2019-11-15T19:51:57.261701992Z"
        description    = "Push to any branch"
        disabled       = false
        filename       = "cloudbuild.yaml"
        id             = "projects/project-name/triggers/b577ea05-46e9-48ba-9fde-24fa619c8eb1"
        ignored_files  = []
        included_files = []
        name           = "collect"
        project        = "project-name"
        substitutions  = {}
        trigger_id     = "b577ea05-46e9-48ba-9fde-24fa619c8eb1"

        github {
            name  = "collect"
            owner = "organization_name"

            push {
                branch = ".*"
            }
        }

        timeouts {}

      + trigger_template {
          + branch_name = ".*"
          + repo_name   = "default"
        }
    }

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

I removed the trigger_template from the configuration as the trigger is working as expected.

Config file:

resource "google_cloudbuild_trigger" "collect" {
  provider = google-beta.project-name

  description = "Push to any branch"
  filename = "cloudbuild.yaml"

  github {
    owner = "organization_name"
    name = "collect"
    push {
      branch = ".*"
    }
  }
}

Terraform plan output:

❯ terraform plan
Acquiring state lock. This may take a few moments...

Error: "trigger_template": required field is not set

  on cloudbuild_trigger.tf line 1, in resource "google_cloudbuild_trigger" "collect":
   1: resource "google_cloudbuild_trigger" "collect" {

Expected Behavior

Terraform should want to make no changes.

Actual Behavior

Terraform errors because trigger_template is a required field, even though the imported trigger does not include this field.

Steps to Reproduce

  • Create a cloudbuild trigger for a Github cloudbuild integration
  • Import it into tf
  • Write an appropriate .tf file as above
  • terraform plan
bug

Most helpful comment

Yeah, the confusion here is that it is required in GA, but one-or-the-other of trigger_template or github is allowed in beta. I'll get this fixed.

All 4 comments

@ndmckinley Seems like a regression as you know trigger_template and github are mutually exclusive as per https://cloud.google.com/cloud-build/docs/api/reference/rest/v1/projects.triggers and this was the behaviour in previous versions of the google-beta provider

Assigning to @ndmckinley who made this change

Yeah, the confusion here is that it is required in GA, but one-or-the-other of trigger_template or github is allowed in beta. I'll get this fixed.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings