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

Automate Terraform for oss-vdb-test #1017

Merged
merged 22 commits into from
Feb 15, 2023

Conversation

michaelkedar
Copy link
Member

@michaelkedar michaelkedar commented Feb 10, 2023

Adds a number of things needed to start automatically running terraform changes on the staging environment.
(I know Andrew wants to discuss potentially using KCC, but I'm using this to start setting up our staging pipeline)

  • Adds Terraform Docker image, usable by Cloud Build to run Terraform for our project.
  • Adds a cloud build trigger on oss-vdb to run terraform plan on oss-vdb-test when terraform files are changed
    • Output is only viewable in Cloud Build at the moment
    • Also added a Github workflow to comment on PRs when something changes.
  • Adds a cloud build trigger on oss-vdb to run terraform apply on oss-vdb-test on pushes to the master branch.
    • The cloud build yaml will eventually be used for building Docker images & running Cloud Deploy

The Cloud Builds use the existing deployment service account from oss-vdb. IAM permissions have been granted to it on oss-vdb-test to allow it to modify the project as needed.

@michaelkedar
Copy link
Member Author

Well, the Github commenting didn't work ☹️

deployment/terraform/cloudbuild-tf-plan.yaml Outdated Show resolved Hide resolved
docker/terraform/cloudbuild.yaml Outdated Show resolved Hide resolved
@michaelkedar
Copy link
Member Author

Turns out GitHub Actions coming from public forked repositories can't have more than read permissions, so I can't use an action to make a comment.

I'm removing the action, and we'll just have to remember to check the plans.

Copy link
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

thanks! some initial comments.

deployment/build-and-stage.yaml Outdated Show resolved Hide resolved
deployment/terraform/cloudbuild-tf-plan.yaml Outdated Show resolved Hide resolved
docker/terraform/Dockerfile Outdated Show resolved Hide resolved
docker/terraform/README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

LGTM with some minor comments remaining.

@andrewpollock can you please review and sign off on this too?

deployment/terraform/cloudbuild-tf-plan.yaml Outdated Show resolved Hide resolved
deployment/build-and-stage.yaml Outdated Show resolved Hide resolved
deployment/terraform/cloudbuild-tf-plan.yaml Outdated Show resolved Hide resolved
}

get-active-account
if [[ (! -z "$active_account") && (! -z "$GCLOUD_SERVICE_KEY") ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think you might have more parenthesis in here than strictly necessary...

be activated, which will override the account already activated in this container.

This usually happens if you've defined the GCLOUD_SERVICE_KEY environment variable in a cloudbuild.yaml file & this is
executing in a Google cloud builder environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "Google Cloud Build" instead?

get-active-account
}

function service-account-usage() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given this looks more like an error message, emit it on stderr per https://google.github.io/styleguide/shellguide.html#stdout-vs-stderr

function activate-service-key() {
rootdir=/root/.config/gcloud-config
mkdir -p $rootdir
tmpdir=$(mktemp -d "$rootdir/servicekey.XXXXXXXX")
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you're going with curly braces around variables, which I'm totally cool with, just be consistent: https://google.github.io/styleguide/shellguide.html#variable-expansion

}

function activate-service-key() {
rootdir=/root/.config/gcloud-config
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,53 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@michaelkedar michaelkedar Feb 15, 2023

Choose a reason for hiding this comment

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

I didn't actually write or edit this file - it came from https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/terraform

I mentioned it in the README but I might add a comment in the file (and in Dockerfile and cloud build file) to note this as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I'd glossed over that in the README. Treat all of these as nits then... I filed GoogleCloudPlatform/cloud-builders-community#611 against the source.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm just going to leave it as-is, so I don't inadvertently break anything.

deployment/terraform/modules/osv/scripts/esp_full_version Outdated Show resolved Hide resolved
deployment/terraform/cloudbuild-tf-plan.yaml Outdated Show resolved Hide resolved
@michaelkedar michaelkedar merged commit 3f7f138 into google:master Feb 15, 2023
@michaelkedar michaelkedar deleted the terraform-cloudbuild branch August 2, 2023 23:26
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 this pull request may close these issues.

3 participants