Skip to content

Commit a6072e0

Browse files
daniel-citapeabody
andauthored
fix: Do not create secret versions when using Cloud Build repositores second gen (#324)
Co-authored-by: Andrew Peabody <andrewpeabody@google.com>
1 parent b7c4084 commit a6072e0

File tree

65 files changed

+1338
-581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1338
-581
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ For the cloudbuild submodule, see the README [cloudbuild](./modules/cloudbuild).
6363
| org\_id | GCP Organization ID | `string` | n/a | yes |
6464
| org\_project\_creators | Additional list of members to have project creator role accross the organization. Prefix of group: user: or serviceAccount: is required. | `list(string)` | `[]` | no |
6565
| parent\_folder | GCP parent folder ID in the form folders/{id} | `string` | `""` | no |
66+
| project\_auto\_create\_network | Create the default network for the project created. | `bool` | `false` | no |
6667
| project\_deletion\_policy | The deletion policy for the project created. | `string` | `"PREVENT"` | no |
6768
| project\_id | Custom project ID to use for project created. If not supplied, the default id is {project\_prefix}-seed-{random suffix}. | `string` | `""` | no |
6869
| project\_labels | Labels to apply to the project. | `map(string)` | `{}` | no |

build/int.cloudbuild.yaml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ steps:
113113
- apply-tfbuilder
114114
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
115115
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilder --stage verify --verbose']
116-
- id: teardown-tfbuilder
117-
waitFor:
118-
- verify-tfbuilder
119-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
120-
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilder --stage teardown --verbose']
121116

122117
- id: apply-tfbuilder-github
123118
waitFor:
@@ -131,12 +126,6 @@ steps:
131126
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
132127
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilderGitHub --stage verify --verbose']
133128
secretEnv: ['IM_GITHUB_PAT']
134-
- id: teardown-tfbuilder-github
135-
waitFor:
136-
- verify-tfbuilder-github
137-
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
138-
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilderGitHub --stage teardown --verbose']
139-
secretEnv: ['IM_GITHUB_PAT']
140129

141130
- id: apply-tfbuilder-gitlab
142131
waitFor:
@@ -150,8 +139,26 @@ steps:
150139
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
151140
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilderGitLab --stage verify --verbose']
152141
secretEnv: ['IM_GITLAB_PAT']
142+
143+
- id: teardown-tfbuilder
144+
waitFor:
145+
- verify-tfbuilder
146+
- verify-tfbuilder-github
147+
- verify-tfbuilder-gitlab
148+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
149+
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilder --stage teardown --verbose']
150+
- id: teardown-tfbuilder-github
151+
waitFor:
152+
- verify-tfbuilder
153+
- verify-tfbuilder-github
154+
- verify-tfbuilder-gitlab
155+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
156+
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilderGitHub --stage teardown --verbose']
157+
secretEnv: ['IM_GITHUB_PAT']
153158
- id: teardown-tfbuilder-gitlab
154159
waitFor:
160+
- verify-tfbuilder
161+
- verify-tfbuilder-github
155162
- verify-tfbuilder-gitlab
156163
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
157164
args: ['/bin/bash', '-c', 'cft test run TestTFCloudBuildBuilderGitLab --stage teardown --verbose']

examples/cloudbuild_repo_connection_github/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ For GitHub connections you will need:
1010

1111
- Install the [Cloud Build App](https://github.com/apps/google-cloud-build) on Github.
1212
- Create a [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) on Github with [scopes](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/scopes-for-oauth-apps#available-scopes) `repo` and `read:user` (or if app is installed in a organization use `read:org`).
13+
- Create two [Google Secret Manager](https://cloud.google.com/secret-manager/docs/overview) secrets, one for the Cloud Build App and one for the Personal Access Token.
14+
- Populate the corresponding [secret versions](https://cloud.google.com/secret-manager/docs/add-secret-version) of each one of the secrets.
1315

1416
For more information on this topic refer to the Cloud Build repositories (2nd gen) documentation for
1517
[Connect to a GitHub repository](https://cloud.google.com/build/docs/automating-builds/github/connect-repo-github?generation=2nd-gen).
@@ -19,8 +21,8 @@ For more information on this topic refer to the Cloud Build repositories (2nd ge
1921

2022
| Name | Description | Type | Default | Required |
2123
|------|-------------|------|---------|:--------:|
22-
| github\_app\_id | The application ID for the Cloudbuild GitHub app. | `string` | n/a | yes |
23-
| github\_pat | The personal access token for authenticating with GitHub. | `string` | n/a | yes |
24+
| github\_app\_id\_secret\_id | The secret ID for the application ID for the Cloudbuild GitHub app. | `string` | n/a | yes |
25+
| github\_pat\_secret\_id | The secret ID for the personal access token for authenticating with GitHub. | `string` | n/a | yes |
2426
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |
2527
| repository\_name | The name of the test repository. | `string` | n/a | yes |
2628
| repository\_url | The HTTPS clone URL of the repository, ending with .git. | `string` | n/a | yes |

examples/cloudbuild_repo_connection_github/main.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
module "github_connection" {
17+
module "git_repo_connection" {
1818
source = "terraform-google-modules/bootstrap/google//modules/cloudbuild_repo_connection"
19-
version = "~> 9.0"
19+
version = "~> 8.0"
2020

2121
project_id = var.project_id
22-
credential_config = {
23-
credential_type = "GITHUBv2"
24-
github_pat = var.github_pat
25-
github_app_id = var.github_app_id
22+
connection_config = {
23+
connection_type = "GITHUBv2"
24+
github_secret_id = var.github_pat_secret_id
25+
github_app_id_secret_id = var.github_app_id_secret_id
2626
}
2727

2828
cloud_build_repositories = {

examples/cloudbuild_repo_connection_github/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
output "cloud_build_repositories_2nd_gen_connection" {
1818
description = "Cloudbuild connection created."
19-
value = module.github_connection.cloud_build_repositories_2nd_gen_connection
19+
value = module.git_repo_connection.cloud_build_repositories_2nd_gen_connection
2020
}
2121

2222
output "cloud_build_repositories_2nd_gen_repositories" {
2323
description = "Created repositories."
24-
value = module.github_connection.cloud_build_repositories_2nd_gen_repositories
24+
value = module.git_repo_connection.cloud_build_repositories_2nd_gen_repositories
2525
}
2626

examples/cloudbuild_repo_connection_github/variables.tf

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ variable "project_id" {
1919
type = string
2020
}
2121

22-
variable "github_pat" {
23-
description = "The personal access token for authenticating with GitHub."
22+
variable "github_pat_secret_id" {
23+
description = "The secret ID for the personal access token for authenticating with GitHub."
2424
type = string
2525
}
2626

27-
variable "github_app_id" {
28-
description = "The application ID for the Cloudbuild GitHub app."
27+
variable "github_app_id_secret_id" {
28+
description = "The secret ID for the application ID for the Cloudbuild GitHub app."
2929
type = string
3030
}
3131

@@ -38,4 +38,3 @@ variable "repository_name" {
3838
description = "The name of the test repository."
3939
type = string
4040
}
41-

examples/cloudbuild_repo_connection_gitlab/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ The example will create Cloud Build repositories (2nd gen) using a Gitlab connec
44

55
## Gitlab Requirements for Cloud Build Connection
66

7-
When using a Cloud Build repositories (2nd gen) GitLab repository, a Cloud Build connection to your repository provider will be needed.
7+
When using a Cloud Build repositories (2nd gen) GitLab repository, a Cloud Build connection to your repository provider will be created.
8+
9+
For GitLab connections you will need:
10+
11+
- Create a [Personal Access Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) on GitLab with [scope](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#personal-access-token-scopes) `api`.
12+
- Create a [Personal Access Token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) on GitLab with [scope](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#personal-access-token-scopes) `read_api`.
13+
- Create a [webhook](https://docs.gitlab.com/ee/user/project/integrations/webhooks.html)
14+
- Create three [Google Secret Manager](https://cloud.google.com/secret-manager/docs/overview) secrets, one for the `api` token, one for the `read_api` token, and one for the `webhook`.
15+
- Populate the corresponding [secret versions](https://cloud.google.com/secret-manager/docs/add-secret-version) of each one of the secrets.
816

917
For more information on this topic refer to the Cloud Build repositories (2nd gen) documentation:
1018
- [Connect to a GitLab host](https://cloud.google.com/build/docs/automating-builds/gitlab/connect-host-gitlab)
@@ -15,8 +23,9 @@ For more information on this topic refer to the Cloud Build repositories (2nd ge
1523

1624
| Name | Description | Type | Default | Required |
1725
|------|-------------|------|---------|:--------:|
18-
| gitlab\_authorizer\_credential | Credential for GitLab authorizer | `string` | n/a | yes |
19-
| gitlab\_read\_authorizer\_credential | Credential for GitLab read authorizer | `string` | n/a | yes |
26+
| gitlab\_authorizer\_secret\_id | The secret ID for the credential for GitLab authorizer | `string` | n/a | yes |
27+
| gitlab\_read\_authorizer\_secret\_id | The secret ID for the credential for GitLab read authorizer | `string` | n/a | yes |
28+
| gitlab\_webhook\_secret\_id | The secret ID for the WebHook for GitLab | `string` | n/a | yes |
2029
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |
2130
| repository\_name | The name of the test repository. | `string` | n/a | yes |
2231
| repository\_url | The HTTPS clone URL of the repository, ending with .git. | `string` | n/a | yes |

examples/cloudbuild_repo_connection_gitlab/main.tf

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
module "gitlab_connection" {
18-
source = "../../modules/cloudbuild_repo_connection"
17+
module "git_repo_connection" {
18+
source = "terraform-google-modules/bootstrap/google//modules/cloudbuild_repo_connection"
19+
version = "~> 8.0"
1920

2021
project_id = var.project_id
21-
credential_config = {
22-
credential_type = "GITLABv2"
23-
gitlab_authorizer_credential = var.gitlab_authorizer_credential
24-
gitlab_read_authorizer_credential = var.gitlab_read_authorizer_credential
22+
connection_config = {
23+
connection_type = "GITLABv2"
24+
gitlab_authorizer_credential_secret_id = var.gitlab_authorizer_secret_id
25+
gitlab_read_authorizer_credential_secret_id = var.gitlab_read_authorizer_secret_id
26+
gitlab_webhook_secret_id = var.gitlab_webhook_secret_id
2527
}
2628

2729
cloud_build_repositories = {

examples/cloudbuild_repo_connection_gitlab/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
output "cloud_build_repositories_2nd_gen_connection" {
1818
description = "Cloudbuild connection created."
19-
value = module.gitlab_connection.cloud_build_repositories_2nd_gen_connection
19+
value = module.git_repo_connection.cloud_build_repositories_2nd_gen_connection
2020
}
2121

2222
output "cloud_build_repositories_2nd_gen_repositories" {
2323
description = "Created repositories."
24-
value = module.gitlab_connection.cloud_build_repositories_2nd_gen_repositories
24+
value = module.git_repo_connection.cloud_build_repositories_2nd_gen_repositories
2525
}

examples/cloudbuild_repo_connection_gitlab/variables.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ variable "repository_name" {
2929
type = string
3030
}
3131

32-
variable "gitlab_authorizer_credential" {
33-
description = "Credential for GitLab authorizer"
32+
variable "gitlab_authorizer_secret_id" {
33+
description = "The secret ID for the credential for GitLab authorizer"
3434
type = string
3535
}
3636

37-
variable "gitlab_read_authorizer_credential" {
38-
description = "Credential for GitLab read authorizer"
37+
variable "gitlab_read_authorizer_secret_id" {
38+
description = "The secret ID for the credential for GitLab read authorizer"
3939
type = string
4040
}
4141

42+
variable "gitlab_webhook_secret_id" {
43+
description = "The secret ID for the WebHook for GitLab"
44+
type = string
45+
}

0 commit comments

Comments
 (0)