-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add instructions for deployment using GitHub Actions (#955)
- Loading branch information
1 parent
a7ce17e
commit 56450bd
Showing
23 changed files
with
1,449 additions
and
78 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
provider "github" { | ||
owner = var.gh_repos.owner | ||
token = var.gh_token | ||
} | ||
|
||
locals { | ||
cicd_project_id = module.gh_cicd.project_id | ||
|
||
gh_config = { | ||
"bootstrap" = var.gh_repos.bootstrap, | ||
"org" = var.gh_repos.organization, | ||
"env" = var.gh_repos.environments, | ||
"net" = var.gh_repos.networks, | ||
"proj" = var.gh_repos.projects, | ||
} | ||
|
||
sa_mapping = { | ||
for k, v in local.gh_config : k => { | ||
sa_name = google_service_account.terraform-env-sa[k].name | ||
attribute = "attribute.repository/${var.gh_repos.owner}/${v}" | ||
} | ||
} | ||
|
||
commom_secrets = { | ||
"PROJECT_ID" : module.gh_cicd.project_id, | ||
"WIF_PROVIDER_NAME" : module.gh_oidc.provider_name, | ||
"TF_BACKEND" : module.seed_bootstrap.gcs_bucket_tfstate, | ||
"TF_VAR_gh_token": var.gh_token, | ||
} | ||
|
||
secrets_list = flatten([ | ||
for k, v in local.gh_config : [ | ||
for secret, plaintext in local.commom_secrets : { | ||
config = k | ||
secret_name = secret | ||
plaintext_value = plaintext | ||
repository = v | ||
} | ||
] | ||
]) | ||
|
||
sa_secrets = [for k, v in local.gh_config : { | ||
config = k | ||
secret_name = "SERVICE_ACCOUNT_EMAIL" | ||
plaintext_value = google_service_account.terraform-env-sa[k].email | ||
repository = v | ||
} | ||
] | ||
|
||
gh_secrets = { for v in concat(local.sa_secrets, local.secrets_list) : "${v.config}.${v.secret_name}" => v } | ||
|
||
} | ||
|
||
module "gh_cicd" { | ||
source = "terraform-google-modules/project-factory/google" | ||
version = "~> 12.0" | ||
|
||
name = "${var.project_prefix}-b-cicd-wif-gh" | ||
random_project_id = true | ||
org_id = var.org_id | ||
folder_id = google_folder.bootstrap.id | ||
billing_account = var.billing_account | ||
activate_apis = [ | ||
"compute.googleapis.com", | ||
"admin.googleapis.com", | ||
"iam.googleapis.com", | ||
"billingbudgets.googleapis.com", | ||
"cloudbilling.googleapis.com", | ||
"serviceusage.googleapis.com", | ||
"cloudresourcemanager.googleapis.com", | ||
"iamcredentials.googleapis.com", | ||
] | ||
} | ||
|
||
module "gh_oidc" { | ||
source = "terraform-google-modules/github-actions-runners/google//modules/gh-oidc" | ||
version = "~> 3.1" | ||
|
||
project_id = module.gh_cicd.project_id | ||
pool_id = "foundation-pool" | ||
provider_id = "foundation-gh-provider" | ||
sa_mapping = local.sa_mapping | ||
} | ||
|
||
resource "github_actions_secret" "secrets" { | ||
for_each = local.gh_secrets | ||
|
||
repository = each.value.repository | ||
secret_name = each.value.secret_name | ||
plaintext_value = each.value.plaintext_value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,67 +28,87 @@ group_billing_admins = "REPLACE_ME" | |
|
||
default_region = "us-central1" | ||
|
||
// Optional - for an organization with existing projects or for development/validation. | ||
// Uncomment this variable to place all the example foundation resources under | ||
// the provided folder instead of the root organization. | ||
// The variable value is the numeric folder ID | ||
// The folder must already exist. | ||
//parent_folder = "01234567890" | ||
# Optional - for an organization with existing projects or for development/validation. | ||
# Uncomment this variable to place all the example foundation resources under | ||
# the provided folder instead of the root organization. | ||
# The variable value is the numeric folder ID | ||
# The folder must already exist. | ||
# parent_folder = "01234567890" | ||
|
||
// Optional - for enabling the automatic groups creation, uncoment the groups | ||
// variable and update the values with the desired group names | ||
//groups = { | ||
// create_groups = true, | ||
// billing_project = "billing-project", | ||
// required_groups = { | ||
// group_org_admins = "[email protected]" | ||
// group_billing_admins = "[email protected]" | ||
// billing_data_users = "[email protected]" | ||
// audit_data_users = "[email protected]" | ||
// monitoring_workspace_users = "[email protected]" | ||
// }, | ||
// optional_groups = { | ||
// gcp_platform_viewer = "[email protected]" | ||
// gcp_security_reviewer = "[email protected]" | ||
// gcp_network_viewer = "[email protected]" | ||
// gcp_scc_admin = "[email protected]" | ||
// gcp_global_secrets_admin = "[email protected]" | ||
// gcp_audit_viewer = "[email protected]" | ||
// } | ||
//} | ||
// | ||
# Optional - for enabling the automatic groups creation, uncoment the groups | ||
# variable and update the values with the desired group names | ||
# groups = { | ||
# create_groups = true, | ||
# billing_project = "billing-project", | ||
# required_groups = { | ||
# group_org_admins = "[email protected]" | ||
# group_billing_admins = "[email protected]" | ||
# billing_data_users = "[email protected]" | ||
# audit_data_users = "[email protected]" | ||
# monitoring_workspace_users = "[email protected]" | ||
# }, | ||
# optional_groups = { | ||
# gcp_platform_viewer = "[email protected]" | ||
# gcp_security_reviewer = "[email protected]" | ||
# gcp_network_viewer = "[email protected]" | ||
# gcp_scc_admin = "[email protected]" | ||
# gcp_global_secrets_admin = "[email protected]" | ||
# gcp_audit_viewer = "[email protected]" | ||
# } | ||
# } | ||
# | ||
|
||
|
||
/* ---------------------------------------- | ||
Specific to github_bootstrap | ||
---------------------------------------- */ | ||
# Un-comment github_bootstrap and its outputs if you want to use GitHub Actions instead of Cloud Build | ||
# gh_repos = { | ||
# owner = "YOUR-GITHUB-USER-OR-ORGANIZATION", | ||
# bootstrap = "YOUR-BOOTSTRAP-REPOSITORY", | ||
# organization = "YOUR-ORGANIZATION-REPOSITORY", | ||
# environments = "YOUR-ENVIRONMENTS-REPOSITORY", | ||
# networks = "YOUR-NETWORKS-REPOSITORY", | ||
# projects = "YOUR-PROJECTS-REPOSITORY", | ||
# } | ||
# | ||
# to prevent saving the `gh_token` in plain text in this file, | ||
# export the GitHub fine grained access token in the command line | ||
# as an environment variable before running terraform. | ||
# Run the following commnad in your shell: | ||
# export TF_VAR_gh_token="YOUR-FINE-GRAINED-ACCESS-TOKEN" | ||
|
||
|
||
/* ---------------------------------------- | ||
Specific to jenkins_bootstrap module | ||
---------------------------------------- */ | ||
// Un-comment the jenkins_bootstrap module and its outputs if you want to use Jenkins instead of Cloud Build | ||
//jenkins_agent_gce_subnetwork_cidr_range = "172.16.1.0/24" | ||
// | ||
//jenkins_agent_gce_private_ip_address = "172.16.1.6" | ||
// | ||
//jenkins_agent_gce_ssh_pub_key = "ssh-rsa [KEY_VALUE] [USERNAME]" | ||
// | ||
//jenkins_agent_sa_email = "jenkins-agent-gce" # service_account_prefix will be added | ||
// | ||
//jenkins_controller_subnetwork_cidr_range = ["10.1.0.6/32"] | ||
// | ||
//nat_bgp_asn = "64514" | ||
// | ||
//vpn_shared_secret = "shared_secret" | ||
// | ||
//on_prem_vpn_public_ip_address = "" | ||
// | ||
//on_prem_vpn_public_ip_address2 = "" | ||
// | ||
//router_asn = "64515" | ||
// | ||
//bgp_peer_asn = "64513" | ||
// | ||
//tunnel0_bgp_peer_address = "169.254.1.1" | ||
// | ||
//tunnel0_bgp_session_range = "169.254.1.2/30" | ||
// | ||
//tunnel1_bgp_peer_address = "169.254.2.1" | ||
// | ||
//tunnel1_bgp_session_range = "169.254.2.2/30" | ||
# Un-comment the jenkins_bootstrap module and its outputs if you want to use Jenkins instead of Cloud Build | ||
# jenkins_agent_gce_subnetwork_cidr_range = "172.16.1.0/24" | ||
# | ||
# jenkins_agent_gce_private_ip_address = "172.16.1.6" | ||
# | ||
# jenkins_agent_gce_ssh_pub_key = "ssh-rsa [KEY_VALUE] [USERNAME]" | ||
# | ||
# jenkins_agent_sa_email = "jenkins-agent-gce" # service_account_prefix will be added | ||
# | ||
# jenkins_controller_subnetwork_cidr_range = ["10.1.0.6/32"] | ||
# | ||
# nat_bgp_asn = "64514" | ||
# | ||
# vpn_shared_secret = "shared_secret" | ||
# | ||
# on_prem_vpn_public_ip_address = "" | ||
# | ||
# on_prem_vpn_public_ip_address2 = "" | ||
# | ||
# router_asn = "64515" | ||
# | ||
# bgp_peer_asn = "64513" | ||
# | ||
# tunnel0_bgp_peer_address = "169.254.1.1" | ||
# | ||
# tunnel0_bgp_session_range = "169.254.1.2/30" | ||
# | ||
# tunnel1_bgp_peer_address = "169.254.2.1" | ||
# | ||
# tunnel1_bgp_session_range = "169.254.2.2/30" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.