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

Adding "name" to Cloud Build trigger resource #2492

Merged
merged 4 commits into from
Oct 29, 2019
Merged

Adding "name" to Cloud Build trigger resource #2492

merged 4 commits into from
Oct 29, 2019

Conversation

WillBeebe
Copy link

@WillBeebe WillBeebe commented Oct 18, 2019

When trying to create multiple Cloud Build triggers in parallel, sometimes triggers will get the same name. I added the field name so that a user can ensure uniqueness instead of rely on the API.

Here is an example of what I was doing.

locals {
  default_substitutions = {
    OX_ARTIFACTS_GCS_BUCKET = google_storage_bucket.deployment_artifacts.name
  }

  repos = {
    "deploy-tools" = {
      substitutions = merge(local.default_substitutions, {
      })
    },
    "eagle-eye-ui-api" = {
      substitutions = merge(local.default_substitutions, {
        CI_ENV = var.environment
      })
    }
  }
}


resource "google_cloudbuild_trigger" "master-trigger" {
  for_each = local.repos
  provider = google-beta

  # name     = "${each.key}-master-trigger"

  github {
    push {
      branch = "master"
    }
    owner = "openx"
    name  = each.key
  }

  substitutions = each.value.substitutions

  filename = "cloudbuild.yaml"
}

resource "google_cloudbuild_trigger" "pr-trigger" {
  for_each = local.repos
  provider = google-beta

  # name     = "${each.key}-pr-trigger"

  github {
    pull_request {
      branch = ".*"
    }
    owner = "openx"
    name  = each.key
  }

  substitutions = each.value.substitutions

  filename = "cloudbuild-pr.yaml"
}

When trying to run the compiler I ran into issues about file limits. I added a note to the README.md about this, let me know if I should separate that into a different PR.

`cloudbuild`: added ability to specify `name` for `cloud_build_trigger` to avoid name collisions when creating multiple triggers at once.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, 8a3aa28.

Pull request statuses

New Pull Requests

I built this PR into one or more new PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#1277
depends: GoogleCloudPlatform/terraform-google-conversion#233
depends: hashicorp/terraform-provider-google#4709
depends: ansible-collections/google.cloud#31
depends: modular-magician/inspec-gcp#236

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, 6b83487.

Pull request statuses

terraform-provider-google-beta already has an open PR.
terraform-google-conversion already has an open PR.
terraform-provider-google already has an open PR.
Ansible already has an open PR.
InSpec already has an open PR.

New Pull Requests

I didn't open any new pull requests because of this PR.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, 519dcbf.

Pull request statuses

terraform-provider-google-beta already has an open PR.
terraform-google-conversion already has an open PR.
terraform-provider-google already has an open PR.
Ansible already has an open PR.
InSpec already has an open PR.

New Pull Requests

I didn't open any new pull requests because of this PR.

@chrisst chrisst changed the title Adding "name" to Cloud Build resource Adding "name" to Cloud Build trigger resource Oct 28, 2019
@chrisst chrisst self-requested a review October 28, 2019 20:18
@@ -50,6 +50,10 @@ objects:
description: |
The unique identifier for the trigger.
output: true
- !ruby/object:Api::Type::String
name: 'name'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Reviewing in Terraform context
Adding a property to api.yaml will default to making it optional. However since this property is created by the API if it's not specified you will need to also have it marked as Computed in Terraform. If it's not Computed and a user upgrades to this version, subsequent terraform apply runs will attempt to override the name with an empty string as it will detect a difference between what had been specified in the config and what was set in the state from the API.

To do this you can set the property to default_from_api: true in the terraform.yaml. See triggerTemplate.projectId as an example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Chris! This makes a ton of sense. I'm adding this because creating multiple triggers at once sometimes results in them getting the same computed name. Thanks for reviewing and explaining how to add this default.

I've made the change (I think in the right way). 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks, a much needed addition.

@chrisst chrisst self-assigned this Oct 28, 2019
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
I see that this PR has already had some downstream PRs generated. Any open downstreams are already updated to your most recent commit, e41e212.

Pull request statuses

terraform-provider-google-beta already has an open PR.
terraform-google-conversion already has an open PR.
terraform-provider-google already has an open PR.
Ansible already has an open PR.
InSpec already has an open PR.

New Pull Requests

I didn't open any new pull requests because of this PR.

Copy link
Contributor

@chrisst chrisst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. For future reference there's no need to merge master back into the branch. Our build tools will rebase against master before merging the change in.

@@ -50,6 +50,10 @@ objects:
description: |
The unique identifier for the trigger.
output: true
- !ruby/object:Api::Type::String
name: 'name'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks, a much needed addition.

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

Successfully merging this pull request may close these issues.

5 participants