diff --git a/.changelog/8544.txt b/.changelog/8544.txt new file mode 100644 index 0000000000..cb42c6dcbd --- /dev/null +++ b/.changelog/8544.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +cloudbuild: added `git_file_source.bitbucket_server_config` and `source_to_build.bitbucket_server_config` fields to `google_cloudbuild_trigger` resource +``` diff --git a/google-beta/resource_cloudbuild_trigger_generated_test.go b/google-beta/resource_cloudbuild_trigger_generated_test.go index 3bacfa7f05..769db28f0e 100644 --- a/google-beta/resource_cloudbuild_trigger_generated_test.go +++ b/google-beta/resource_cloudbuild_trigger_generated_test.go @@ -445,6 +445,54 @@ resource "google_cloudbuild_trigger" "manual-trigger" { `, context) } +func TestAccCloudBuildTrigger_cloudbuildTriggerManualBitbucketServerExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudBuildTriggerDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudBuildTrigger_cloudbuildTriggerManualBitbucketServerExample(context), + }, + { + ResourceName: "google_cloudbuild_trigger.manual-bitbucket-trigger", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location"}, + }, + }, + }) +} + +func testAccCloudBuildTrigger_cloudbuildTriggerManualBitbucketServerExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuild_trigger" "manual-bitbucket-trigger" { + name = "terraform-manual-bbs-trigger" + + source_to_build { + uri = "https://bbs.com/scm/stag/test-repo.git" + ref = "refs/heads/main" + repo_type = "BITBUCKET_SERVER" + bitbucket_server_config = "projects/myProject/locations/global/bitbucketServerConfigs/configID" + } + + git_file_source { + path = "cloudbuild.yaml" + uri = "https://bbs.com/scm/stag/test-repo.git" + revision = "refs/heads/main" + repo_type = "BITBUCKET_SERVER" + bitbucket_server_config = "projects/myProject/locations/global/bitbucketServerConfigs/configID" + } +} +`, context) +} + func TestAccCloudBuildTrigger_cloudbuildTriggerRepoExample(t *testing.T) { t.Parallel() diff --git a/google-beta/resource_cloudbuild_trigger_test.go b/google-beta/resource_cloudbuild_trigger_test.go index 9a9c8e01d6..ebbe0edb93 100644 --- a/google-beta/resource_cloudbuild_trigger_test.go +++ b/google-beta/resource_cloudbuild_trigger_test.go @@ -305,6 +305,7 @@ resource "google_cloudbuild_trigger" "build_trigger" { uri = "https://bitbucket.org/myorg/myrepo" revision = "refs/heads/develop" repo_type = "BITBUCKET_SERVER" + bitbucket_server_config = "projects/123456789/locations/us-central1/bitbucketServerConfigs/myBitbucketConfig" } } `, name) diff --git a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go index b4a7a8957f..ae33ed23b5 100644 --- a/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go +++ b/google-beta/services/cloudbuild/resource_cloudbuild_trigger.go @@ -853,6 +853,12 @@ When using Pub/Sub, Webhook or Manual set the file name using git_file_source in ValidateFunc: verify.ValidateEnum([]string{"UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"}), Description: `The type of the repo, since it may not be explicit from the repo field (e.g from a URL). Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possible values: ["UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"]`, + }, + "bitbucket_server_config": { + Type: schema.TypeString, + Optional: true, + Description: `The full resource name of the bitbucket server config. +Format: projects/{project}/locations/{location}/bitbucketServerConfigs/{id}.`, }, "github_enterprise_config": { Type: schema.TypeString, @@ -1175,6 +1181,12 @@ One of 'trigger_template', 'github', 'pubsub_config' 'webhook_config' or 'source ValidateFunc: verify.ValidateEnum([]string{"UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"}), Description: `The type of the repo, since it may not be explicit from the repo field (e.g from a URL). Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possible values: ["UNKNOWN", "CLOUD_SOURCE_REPOSITORIES", "GITHUB", "BITBUCKET_SERVER"]`, + }, + "bitbucket_server_config": { + Type: schema.TypeString, + Optional: true, + Description: `The full resource name of the bitbucket server config. +Format: projects/{project}/locations/{location}/bitbucketServerConfigs/{id}.`, }, "github_enterprise_config": { Type: schema.TypeString, @@ -1949,6 +1961,8 @@ func flattenCloudBuildTriggerGitFileSource(v interface{}, d *schema.ResourceData flattenCloudBuildTriggerGitFileSourceRevision(original["revision"], d, config) transformed["github_enterprise_config"] = flattenCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(original["githubEnterpriseConfig"], d, config) + transformed["bitbucket_server_config"] = + flattenCloudBuildTriggerGitFileSourceBitbucketServerConfig(original["bitbucketServerConfig"], d, config) return []interface{}{transformed} } func flattenCloudBuildTriggerGitFileSourcePath(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { @@ -1975,6 +1989,10 @@ func flattenCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{}, return v } +func flattenCloudBuildTriggerGitFileSourceBitbucketServerConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudBuildTriggerRepositoryEventConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return nil @@ -2073,6 +2091,8 @@ func flattenCloudBuildTriggerSourceToBuild(v interface{}, d *schema.ResourceData flattenCloudBuildTriggerSourceToBuildRepoType(original["repoType"], d, config) transformed["github_enterprise_config"] = flattenCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(original["githubEnterpriseConfig"], d, config) + transformed["bitbucket_server_config"] = + flattenCloudBuildTriggerSourceToBuildBitbucketServerConfig(original["bitbucketServerConfig"], d, config) return []interface{}{transformed} } func flattenCloudBuildTriggerSourceToBuildUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { @@ -2095,6 +2115,10 @@ func flattenCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(v interface{}, return v } +func flattenCloudBuildTriggerSourceToBuildBitbucketServerConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenCloudBuildTriggerIgnoredFiles(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -3028,6 +3052,13 @@ func expandCloudBuildTriggerGitFileSource(v interface{}, d tpgresource.Terraform transformed["githubEnterpriseConfig"] = transformedGithubEnterpriseConfig } + transformedBitbucketServerConfig, err := expandCloudBuildTriggerGitFileSourceBitbucketServerConfig(original["bitbucket_server_config"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBitbucketServerConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["bitbucketServerConfig"] = transformedBitbucketServerConfig + } + return transformed, nil } @@ -3055,6 +3086,10 @@ func expandCloudBuildTriggerGitFileSourceGithubEnterpriseConfig(v interface{}, d return v, nil } +func expandCloudBuildTriggerGitFileSourceBitbucketServerConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandCloudBuildTriggerRepositoryEventConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -3226,6 +3261,13 @@ func expandCloudBuildTriggerSourceToBuild(v interface{}, d tpgresource.Terraform transformed["githubEnterpriseConfig"] = transformedGithubEnterpriseConfig } + transformedBitbucketServerConfig, err := expandCloudBuildTriggerSourceToBuildBitbucketServerConfig(original["bitbucket_server_config"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBitbucketServerConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["bitbucketServerConfig"] = transformedBitbucketServerConfig + } + return transformed, nil } @@ -3249,6 +3291,10 @@ func expandCloudBuildTriggerSourceToBuildGithubEnterpriseConfig(v interface{}, d return v, nil } +func expandCloudBuildTriggerSourceToBuildBitbucketServerConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandCloudBuildTriggerIgnoredFiles(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/cloudbuild_trigger.html.markdown b/website/docs/r/cloudbuild_trigger.html.markdown index 1de876e361..c85e55648a 100644 --- a/website/docs/r/cloudbuild_trigger.html.markdown +++ b/website/docs/r/cloudbuild_trigger.html.markdown @@ -368,6 +368,34 @@ git_file_source { } } ``` +
+## Example Usage - Cloudbuild Trigger Manual Bitbucket Server + + +```hcl +resource "google_cloudbuild_trigger" "manual-bitbucket-trigger" { + name = "terraform-manual-bbs-trigger" + + source_to_build { + uri = "https://bbs.com/scm/stag/test-repo.git" + ref = "refs/heads/main" + repo_type = "BITBUCKET_SERVER" + bitbucket_server_config = "projects/myProject/locations/global/bitbucketServerConfigs/configID" + } + + git_file_source { + path = "cloudbuild.yaml" + uri = "https://bbs.com/scm/stag/test-repo.git" + revision = "refs/heads/main" + repo_type = "BITBUCKET_SERVER" + bitbucket_server_config = "projects/myProject/locations/global/bitbucketServerConfigs/configID" + } +} +```