Skip to content

Commit cb7b2f1

Browse files
committed
deploy with github
1 parent 9a41b1c commit cb7b2f1

23 files changed

+1127
-100
lines changed
File renamed without changes.

0-bootstrap/terraform.example.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ default_region_kms = "us"
6868
# to prevent saving the `gh_token` in plain text in this file,
6969
# export the GitHub fine grained access token in the command line
7070
# as an environment variable before running terraform.
71-
# Run the following commnad in your shell:
71+
# Run the following command in your shell:
7272
# export TF_VAR_gh_token="YOUR-FINE-GRAINED-ACCESS-TOKEN"
7373

7474

File renamed without changes.
File renamed without changes.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ REGISTRY_URL := gcr.io/cloud-foundation-cicd
2626
.PHONY: docker_test_lint
2727
docker_test_lint:
2828
docker run --rm -it \
29-
-e ENABLE_PARALLEL=1 \
29+
-e ENABLE_PARALLEL=0 \
3030
-e DISABLE_TFLINT=1 \
3131
-e EXCLUDE_LINT_DIRS \
3232
-v $(CURDIR):/workspace \

build/github-tf-plan-all.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: "tf-plan-all"
16+
on:
17+
push:
18+
branches:
19+
- "plan"
20+
21+
env:
22+
PROJECT_ID: ${{ secrets.PROJECT_ID }}
23+
TF_BACKEND: ${{ secrets.TF_BACKEND }}
24+
TF_VAR_gh_token: ${{ secrets.TF_VAR_gh_token }}
25+
TF_IN_AUTOMATION: "true"
26+
27+
jobs:
28+
run:
29+
runs-on: "ubuntu-latest"
30+
permissions:
31+
contents: "read"
32+
id-token: "write"
33+
issues: "write"
34+
pull-requests: "write"
35+
36+
steps:
37+
- uses: "actions/checkout@v4"
38+
39+
- id: "auth"
40+
uses: "google-github-actions/auth@v2"
41+
with:
42+
token_format: "access_token"
43+
workload_identity_provider: ${{ secrets.WIF_PROVIDER_NAME }}
44+
service_account: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
45+
46+
- uses: "google-github-actions/setup-gcloud@v2"
47+
with:
48+
install_components: "beta,terraform-tools"
49+
50+
- uses: "hashicorp/setup-terraform@v3"
51+
with:
52+
terraform_version: "1.5.7"
53+
54+
- id: setup
55+
shell: bash
56+
run: |
57+
echo "Adding bucket information to backends"
58+
for i in `find . -name 'backend.tf'`
59+
do
60+
sed -i'' -e "s/UPDATE_ME/${TF_BACKEND}/" $i
61+
sed -i'' -e "s/UPDATE_PROJECTS_BACKEND/${TF_BACKEND}/" $i
62+
done
63+
64+
- id: plan-validate-all
65+
run: |
66+
${GITHUB_WORKSPACE}/tf-wrapper.sh plan_validate_all "${GITHUB_REF_NAME}" "${GITHUB_WORKSPACE}/policy-library" "${PROJECT_ID}" "FILESYSTEM" "GITHUB"

build/run_gcp_auth.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ SA="$3"
2929
# System folder to save the temporary files
3030
SAVE_PATH="$4"
3131

32-
# TODO
32+
# Save the OIDC token to a file.
33+
# gcloud requires the OIDC token to be passed as a file.
3334
echo "${OIDC_TOKEN}" > "${SAVE_PATH}"/.ci_job_token_file
3435

35-
# TODO
36+
# Exchange the OIDC token for a Google Cloud credential.
3637
gcloud iam workload-identity-pools \
3738
create-cred-config "${WIF_PROVIDER}" \
3839
--service-account="${SA}" \
3940
--output-file="${SAVE_PATH}"/.gcp_generated_credentials.json \
4041
--credential-source-file="${SAVE_PATH}"/.ci_job_token_file \
4142

42-
# TODO
43+
# Authenticate using the generated credential.
4344
gcloud auth login --cred-file="${SAVE_PATH}"/.gcp_generated_credentials.json --update-adc

0 commit comments

Comments
 (0)