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

Migrate cloudbuild repository #9631

Merged
merged 25 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions mmv1/products/cloudbuildv2/Repository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright 2023 Google Inc.
# 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.

--- !ruby/object:Api::Resource
name: Repository
base_url: projects/{{project}}/locations/{{location}}/connections/{{parent_connection}}/repositories
create_url: projects/{{project}}/locations/{{location}}/connections/{{parent_connection}}/repositories?repositoryId={{name}}
self_link: projects/{{project}}/locations/{{location}}/connections/{{parent_connection}}/repositories/{{name}}
immutable: true
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation': 'https://cloud.google.com/build/docs'
api: 'https://cloud.google.com/build/docs/api/reference/rest'
autogen_async: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
base_url: '{{op_id}}'
description: "A repository associated to a parent connection."
exclude_tgc: true
legacy_long_form_project: true
examples:
# These tests depend on secrets stored in a separate project, so we prefer not
# to show them in the docs.
- !ruby/object:Provider::Terraform::Examples
name: 'cloudbuildv2_repository_ghe'
primary_resource_id: 'primary'
skip_docs: true
vars:
connection_name: 'connection'
repository_name: 'repository'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudbuildv2_repository_github'
primary_resource_id: 'primary'
skip_docs: true
vars:
connection_name: 'connection'
repository_name: 'repository'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudbuildv2_repository_gle'
primary_resource_id: 'primary'
skip_docs: true
vars:
connection_name: 'connection'
repository_name: 'repository'
- !ruby/object:Provider::Terraform::Examples
name: 'cloudbuildv2_repository_ghe_doc'
skip_test: true
- !ruby/object:Provider::Terraform::Examples
name: 'cloudbuildv2_repository_github_doc'
skip_test: true
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/cloudbuildv2_repository.go.erb
parameters:
- !ruby/object:Api::Type::String
name: location
description: The location for the resource
url_param_only: true
immutable: true
default_from_api: true # EXTRACT_FROM_FIELD_IF_EMPTY
- !ruby/object:Api::Type::ResourceRef
name: parent_connection
resource: connection
imports: name
description: The connection for the resource
url_param_only: true
required: true
immutable: true
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
properties:
- !ruby/object:Api::Type::String
name: name
description: Name of the repository.
required: true
immutable: true
ignore_read: true
- !ruby/object:Api::Type::String
name: remoteUri
description: Required. Git Clone HTTPS URI.
required: true
immutable: true
- !ruby/object:Api::Type::String
name: createTime
description: Output only. Server assigned timestamp for when the connection was created.
output: true
- !ruby/object:Api::Type::String
name: updateTime
description: Output only. Server assigned timestamp for when the connection was updated.
output: true
- !ruby/object:Api::Type::KeyValueAnnotations
name: annotations
description: Allows clients to store small amounts of arbitrary data.
immutable: true
- !ruby/object:Api::Type::String
name: etag
description: This checksum is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.
output: true
2 changes: 0 additions & 2 deletions mmv1/provider/terraform_tgc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ def copy_common_files(output_folder, generate_code, _generate_docs)
'third_party/terraform/services/compute/image.go'],
['converters/google/resources/services/compute/disk_type.go',
'third_party/terraform/services/compute/disk_type.go'],
['converters/google/resources/services/logging/extract.go',
'third_party/terraform/services/logging/extract.go'],
['converters/google/resources/services/kms/kms_utils.go',
'third_party/terraform/services/kms/kms_utils.go'],
['converters/google/resources/services/sourcerepo/source_repo_utils.go',
Expand Down
37 changes: 37 additions & 0 deletions mmv1/templates/terraform/encoders/cloudbuildv2_repository.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%- # the license inside this block applies to this file
# Copyright 2023 Google Inc.
# 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.
-%>
config := meta.(*transport_tpg.Config)
// Extract any empty fields from the parent_connection field.
project, err := tpgresource.GetProject(d, config)
if err != nil {
return nil, fmt.Errorf("error getting project: %s", err)
}
parent_connection := d.Get("parent_connection").(string)
project, err = tpgresource.ExtractFieldByPattern("project", project, parent_connection, "projects/([a-z0-9A-Z-]*)/locations/.*")
if err != nil {
return nil, fmt.Errorf("error extracting project field: %s", err)
}
location := d.Get("location").(string)
location, err = tpgresource.ExtractFieldByPattern("location", location, parent_connection, "projects/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/connections/.*")
if err != nil {
return nil, fmt.Errorf("error extracting location field: %s", err)
}
// Set project to the extracted value.
d.Set("project", project)
// Set all the other fields to their short forms before forming url and setting ID.
name := d.Get("name").(string)
d.Set("location", location)
d.Set("name", name)
return obj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// Extract any empty fields from the bucket field.
parent := d.Get("parent").(string)
bucket := d.Get("bucket").(string)
parent, err := ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*")
parent, err := tpgresource.ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*")
if err != nil {
return nil, fmt.Errorf("error extracting parent field: %s", err)
}
location := d.Get("location").(string)
location, err = ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*")
location, err = tpgresource.ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*")
if err != nil {
return nil, fmt.Errorf("error extracting location field: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions mmv1/templates/terraform/encoders/logging_log_view.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// Extract any empty fields from the bucket field.
parent := d.Get("parent").(string)
bucket := d.Get("bucket").(string)
parent, err := ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*")
parent, err := tpgresource.ExtractFieldByPattern("parent", parent, bucket, "((projects|folders|organizations|billingAccounts)/[a-z0-9A-Z-]*)/locations/.*")
if err != nil {
return nil, fmt.Errorf("error extracting parent field: %s", err)
}
location := d.Get("location").(string)
location, err = ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*")
location, err = tpgresource.ExtractFieldByPattern("location", location, bucket, "[a-zA-Z]*/[a-z0-9A-Z-]*/locations/([a-z0-9-]*)/buckets/.*")
if err != nil {
return nil, fmt.Errorf("error extracting location field: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_cloudbuildv2_repository" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]['repository_name'] %>"
parent_connection = google_cloudbuildv2_connection.ghe_complete.name
remote_uri = "https://ghe.proctor-staging-test.com/proctorteam/regional_test.git"
location = "us-central1"
annotations = {
some-key = "some-value"
}
}

resource "google_cloudbuildv2_connection" "ghe_complete" {
location = "us-central1"
name = "<%= ctx[:vars]['connection_name'] %>"

github_enterprise_config {
host_uri = "https://ghe.proctor-staging-test.com"
app_id = 516
app_installation_id = 243
app_slug = "myapp"
private_key_secret_version = "projects/gcb-terraform-creds/secrets/ghe-private-key/versions/latest"
webhook_secret_secret_version = "projects/gcb-terraform-creds/secrets/ghe-webhook-secret/versions/latest"
}

annotations = {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "google_cloudbuildv2_repository" "primary" {
name = "<%= ctx[:vars]['repository_name'] %>"
parent_connection = google_cloudbuildv2_connection.github_update.name
remote_uri = "https://github.com/gcb-repos-robot/tf-demo.git"
location = "us-central1"
annotations = {}
}

resource "google_cloudbuildv2_connection" "github_update" {
location = "us-central1"
name = "<%= ctx[:vars]['connection_name'] %>"
disabled = false

github_config {
app_installation_id = 31300675

authorizer_credential {
oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/latest"
}
}

annotations = {
otherkey = "othervalue"

somekey = "somevalue"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ resource "google_secret_manager_secret_version" "github-token-secret-version" {
data "google_iam_policy" "p4sa-secretAccessor" {
binding {
role = "roles/secretmanager.secretAccessor"
// Here, {{projectNum}} is the Google Cloud project number for {{project}}.
members = ["serviceAccount:service-{{projectNum}}@gcp-sa-cloudbuild.iam.gserviceaccount.com"]
// Here, 123456789 is the Google Cloud project number for the project that contains the connection.
members = ["serviceAccount:service-123456789@gcp-sa-cloudbuild.iam.gserviceaccount.com"]
}
}

Expand All @@ -25,20 +25,20 @@ resource "google_secret_manager_secret_iam_policy" "policy" {
}

resource "google_cloudbuildv2_connection" "my-connection" {
location = "{{region}}"
location = "us-central1"
name = "my-connection"

github_config {
app_installation_id = {{installation-id}}
app_installation_id = 123123
authorizer_credential {
oauth_token_secret_version = google_secret_manager_secret_version.github-token-secret-version.id
}
}
}

resource "google_cloudbuildv2_repository" "my-repository" {
location = "{{region}}"
location = "us-central1"
name = "my-repo"
parent_connection = google_cloudbuildv2_connection.my-connection.name
remote_uri = "{{remote_uri}}"
remote_uri = "https://github.com/myuser/myrepo.git"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
resource "google_cloudbuildv2_repository" "primary" {
name = "<%= ctx[:vars]['repository_name'] %>"
parent_connection = google_cloudbuildv2_connection.gle.name
remote_uri = "https://gle-us-central1.gcb-test.com/proctor-test/smoketest.git"
location = "us-west1"

annotations = {
some-key = "some-value"
}
}

resource "google_cloudbuildv2_connection" "gle" {
location = "us-west1"
name = "<%= ctx[:vars]['connection_name'] %>"

gitlab_config {
authorizer_credential {
user_token_secret_version = "projects/407304063574/secrets/gle-api-token/versions/latest"
}

read_authorizer_credential {
user_token_secret_version = "projects/407304063574/secrets/gle-read-token/versions/latest"
}

webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest"
host_uri = "https://gle-us-central1.gcb-test.com"
}

annotations = {}
}
35 changes: 0 additions & 35 deletions mmv1/third_party/terraform/services/logging/extract.go

This file was deleted.

37 changes: 0 additions & 37 deletions mmv1/third_party/terraform/services/logging/extract_test.go

This file was deleted.

Loading
Loading