diff --git a/.changelog/9537.txt b/.changelog/9537.txt new file mode 100644 index 00000000000..6515d29bd66 --- /dev/null +++ b/.changelog/9537.txt @@ -0,0 +1,3 @@ +```release-note:note +cloudbuildv2: changed underlying actuation engine for `google_cloudbuildv2_connection`, there should be no user-facing impact +``` \ No newline at end of file diff --git a/google/provider/provider_dcl_resources.go b/google/provider/provider_dcl_resources.go index 9ee087a03b8..a64fd0a3825 100644 --- a/google/provider/provider_dcl_resources.go +++ b/google/provider/provider_dcl_resources.go @@ -24,7 +24,6 @@ import ( "github.com/hashicorp/terraform-provider-google/google/services/assuredworkloads" "github.com/hashicorp/terraform-provider-google/google/services/bigqueryreservation" "github.com/hashicorp/terraform-provider-google/google/services/cloudbuild" - "github.com/hashicorp/terraform-provider-google/google/services/cloudbuildv2" "github.com/hashicorp/terraform-provider-google/google/services/clouddeploy" "github.com/hashicorp/terraform-provider-google/google/services/compute" "github.com/hashicorp/terraform-provider-google/google/services/containeraws" @@ -45,7 +44,6 @@ var dclResources = map[string]*schema.Resource{ "google_assured_workloads_workload": assuredworkloads.ResourceAssuredWorkloadsWorkload(), "google_bigquery_reservation_assignment": bigqueryreservation.ResourceBigqueryReservationAssignment(), "google_cloudbuild_worker_pool": cloudbuild.ResourceCloudbuildWorkerPool(), - "google_cloudbuildv2_connection": cloudbuildv2.ResourceCloudbuildv2Connection(), "google_clouddeploy_delivery_pipeline": clouddeploy.ResourceClouddeployDeliveryPipeline(), "google_clouddeploy_target": clouddeploy.ResourceClouddeployTarget(), "google_compute_firewall_policy": compute.ResourceComputeFirewallPolicy(), diff --git a/google/provider/provider_mmv1_resources.go b/google/provider/provider_mmv1_resources.go index b48eb4a9bc7..9c3be682f65 100644 --- a/google/provider/provider_mmv1_resources.go +++ b/google/provider/provider_mmv1_resources.go @@ -385,9 +385,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 377 +// Generated resources: 378 // Generated IAM resources: 225 -// Total generated resources: 602 +// Total generated resources: 603 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -494,6 +494,7 @@ var generatedResources = map[string]*schema.Resource{ "google_cloud_asset_project_feed": cloudasset.ResourceCloudAssetProjectFeed(), "google_cloudbuild_bitbucket_server_config": cloudbuild.ResourceCloudBuildBitbucketServerConfig(), "google_cloudbuild_trigger": cloudbuild.ResourceCloudBuildTrigger(), + "google_cloudbuildv2_connection": cloudbuildv2.ResourceCloudbuildv2Connection(), "google_cloudbuildv2_connection_iam_binding": tpgiamresource.ResourceIamBinding(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc), "google_cloudbuildv2_connection_iam_member": tpgiamresource.ResourceIamMember(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc), "google_cloudbuildv2_connection_iam_policy": tpgiamresource.ResourceIamPolicy(cloudbuildv2.Cloudbuildv2ConnectionIamSchema, cloudbuildv2.Cloudbuildv2ConnectionIamUpdaterProducer, cloudbuildv2.Cloudbuildv2ConnectionIdParseFunc), diff --git a/google/services/cloudbuildv2/resource_cloudbuildv2_connection.go b/google/services/cloudbuildv2/resource_cloudbuildv2_connection.go index f9cbd057c80..ae4b52a2851 100644 --- a/google/services/cloudbuildv2/resource_cloudbuildv2_connection.go +++ b/google/services/cloudbuildv2/resource_cloudbuildv2_connection.go @@ -3,34 +3,30 @@ // ---------------------------------------------------------------------------- // -// *** AUTO GENERATED CODE *** Type: DCL *** +// *** AUTO GENERATED CODE *** Type: MMv1 *** // // ---------------------------------------------------------------------------- // -// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) -// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). -// Changes will need to be made to the DCL or Magic Modules instead of here. +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. // -// We are not currently able to accept contributions to this file. If changes -// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. // // ---------------------------------------------------------------------------- package cloudbuildv2 import ( - "context" "fmt" "log" + "reflect" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" - cloudbuildv2 "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuildv2" - - "github.com/hashicorp/terraform-provider-google/google/tpgdclresource" "github.com/hashicorp/terraform-provider-google/google/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" ) @@ -51,9 +47,10 @@ func ResourceCloudbuildv2Connection() *schema.Resource { Update: schema.DefaultTimeout(20 * time.Minute), Delete: schema.DefaultTimeout(20 * time.Minute), }, + CustomizeDiff: customdiff.All( - tpgresource.DefaultProviderProject, tpgresource.SetAnnotationsDiff, + tpgresource.DefaultProviderProject, ), Schema: map[string]*schema.Schema{ @@ -61,394 +58,374 @@ func ResourceCloudbuildv2Connection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "The location for the resource", + Description: `The location for the resource`, }, - "name": { Type: schema.TypeString, Required: true, ForceNew: true, - Description: "Immutable. The resource name of the connection, in the format `projects/{project}/locations/{location}/connections/{connection_id}`.", + Description: `Immutable. The resource name of the connection.`, }, + "annotations": { + Type: schema.TypeMap, + Optional: true, + Description: `Allows clients to store small amounts of arbitrary data. +**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration. +Please refer to the field 'effective_annotations' for all of the annotations present on the resource.`, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "disabled": { Type: schema.TypeBool, Optional: true, - Description: "If disabled is set to true, functionality is disabled for this connection. Repository based API methods and webhooks processing for repositories in this connection will be disabled.", - }, - - "effective_annotations": { - Type: schema.TypeMap, - Computed: true, - Description: "All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.", + Description: `If disabled is set to true, functionality is disabled for this connection. Repository based API methods and webhooks processing for repositories in this connection will be disabled.`, }, - "github_config": { - Type: schema.TypeList, - Optional: true, - Description: "Configuration for connections to github.com.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGithubConfigSchema(), + Type: schema.TypeList, + Optional: true, + Description: `Configuration for connections to github.com.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "app_installation_id": { + Type: schema.TypeInt, + Optional: true, + Description: `GitHub App installation id.`, + }, + "authorizer_credential": { + Type: schema.TypeList, + Optional: true, + Description: `OAuth credential of the account that authorized the Cloud Build GitHub App. It is recommended to use a robot account instead of a human user account. The OAuth token must be tied to the Cloud Build GitHub App.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "oauth_token_secret_version": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `A SecretManager resource containing the OAuth token that authorizes the Cloud Build connection. Format: 'projects/*/secrets/*/versions/*'.`, + }, + "username": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. The username associated to this token.`, + }, + }, + }, + }, + }, + }, ConflictsWith: []string{"github_enterprise_config", "gitlab_config"}, }, - "github_enterprise_config": { - Type: schema.TypeList, - Optional: true, - Description: "Configuration for connections to an instance of GitHub Enterprise.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGithubEnterpriseConfigSchema(), + Type: schema.TypeList, + Optional: true, + Description: `Configuration for connections to an instance of GitHub Enterprise.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "host_uri": { + Type: schema.TypeString, + Required: true, + Description: `Required. The URI of the GitHub Enterprise host this connection is for.`, + }, + "app_id": { + Type: schema.TypeInt, + Optional: true, + Description: `Id of the GitHub App created from the manifest.`, + }, + "app_installation_id": { + Type: schema.TypeInt, + Optional: true, + Description: `ID of the installation of the GitHub App.`, + }, + "app_slug": { + Type: schema.TypeString, + Optional: true, + Description: `The URL-friendly name of the GitHub App.`, + }, + "private_key_secret_version": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `SecretManager resource containing the private key of the GitHub App, formatted as 'projects/*/secrets/*/versions/*'.`, + }, + "service_directory_config": { + Type: schema.TypeList, + Optional: true, + Description: `Configuration for using Service Directory to privately connect to a GitHub Enterprise server. This should only be set if the GitHub Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitHub Enterprise server will be made over the public internet.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}.`, + }, + }, + }, + }, + "ssl_ca": { + Type: schema.TypeString, + Optional: true, + Description: `SSL certificate to use for requests to GitHub Enterprise.`, + }, + "webhook_secret_secret_version": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `SecretManager resource containing the webhook secret of the GitHub App, formatted as 'projects/*/secrets/*/versions/*'.`, + }, + }, + }, ConflictsWith: []string{"github_config", "gitlab_config"}, }, - "gitlab_config": { - Type: schema.TypeList, - Optional: true, - Description: "Configuration for connections to gitlab.com or an instance of GitLab Enterprise.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGitlabConfigSchema(), - ConflictsWith: []string{"github_config", "github_enterprise_config"}, - }, - - "project": { - Type: schema.TypeString, - Computed: true, - Optional: true, - ForceNew: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "The project for the resource", - }, - - "annotations": { - Type: schema.TypeMap, + Type: schema.TypeList, Optional: true, - Description: "Allows clients to store small amounts of arbitrary data.\n\n**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.\nPlease refer to the field `effective_annotations` for all of the annotations present on the resource.", - Elem: &schema.Schema{Type: schema.TypeString}, + Description: `Configuration for connections to gitlab.com or an instance of GitLab Enterprise.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "authorizer_credential": { + Type: schema.TypeList, + Required: true, + Description: `Required. A GitLab personal access token with the 'api' scope access.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_token_secret_version": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: 'projects/*/secrets/*/versions/*'.`, + }, + "username": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. The username associated to this token.`, + }, + }, + }, + }, + "read_authorizer_credential": { + Type: schema.TypeList, + Required: true, + Description: `Required. A GitLab personal access token with the minimum 'read_api' scope access.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "user_token_secret_version": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: 'projects/*/secrets/*/versions/*'.`, + }, + "username": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. The username associated to this token.`, + }, + }, + }, + }, + "webhook_secret_secret_version": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `Required. Immutable. SecretManager resource containing the webhook secret of a GitLab Enterprise project, formatted as 'projects/*/secrets/*/versions/*'.`, + }, + "host_uri": { + Type: schema.TypeString, + Computed: true, + Optional: true, + Description: `The URI of the GitLab Enterprise host this connection is for. If not specified, the default value is https://gitlab.com.`, + }, + "service_directory_config": { + Type: schema.TypeList, + Optional: true, + Description: `Configuration for using Service Directory to privately connect to a GitLab Enterprise server. This should only be set if the GitLab Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitLab Enterprise server will be made over the public internet.`, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "service": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + Description: `Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}.`, + }, + }, + }, + }, + "ssl_ca": { + Type: schema.TypeString, + Optional: true, + Description: `SSL certificate to use for requests to GitLab Enterprise.`, + }, + "server_version": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Version of the GitLab Enterprise server running on the 'host_uri'.`, + }, + }, + }, + ConflictsWith: []string{"github_config", "github_enterprise_config"}, }, - "create_time": { Type: schema.TypeString, Computed: true, - Description: "Output only. Server assigned timestamp for when the connection was created.", + Description: `Output only. Server assigned timestamp for when the connection was created.`, + }, + "effective_annotations": { + Type: schema.TypeMap, + Computed: true, + Description: `All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.`, + Elem: &schema.Schema{Type: schema.TypeString}, }, - "etag": { Type: schema.TypeString, Computed: true, - 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.", + 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.`, }, - "installation_state": { Type: schema.TypeList, Computed: true, - Description: "Output only. Installation state of the Connection.", - Elem: Cloudbuildv2ConnectionInstallationStateSchema(), + Description: `Output only. Installation state of the Connection.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action_uri": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Link to follow for next action. Empty string if the installation is already complete.`, + }, + "message": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Message of what the user should do next to continue the installation. Empty string if the installation is already complete.`, + }, + "stage": { + Type: schema.TypeString, + Computed: true, + Description: `Output only. Current step of the installation process.`, + }, + }, + }, }, - "reconciling": { Type: schema.TypeBool, Computed: true, - Description: "Output only. Set to true when the connection is being set up or updated in the background.", + Description: `Output only. Set to true when the connection is being set up or updated in the background.`, }, - "update_time": { Type: schema.TypeString, Computed: true, - Description: "Output only. Server assigned timestamp for when the connection was updated.", - }, - }, - } -} - -func Cloudbuildv2ConnectionGithubConfigSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "app_installation_id": { - Type: schema.TypeInt, - Optional: true, - Description: "GitHub App installation id.", - }, - - "authorizer_credential": { - Type: schema.TypeList, - Optional: true, - Description: "OAuth credential of the account that authorized the Cloud Build GitHub App. It is recommended to use a robot account instead of a human user account. The OAuth token must be tied to the Cloud Build GitHub App.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGithubConfigAuthorizerCredentialSchema(), + Description: `Output only. Server assigned timestamp for when the connection was updated.`, }, - }, - } -} - -func Cloudbuildv2ConnectionGithubConfigAuthorizerCredentialSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "oauth_token_secret_version": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "A SecretManager resource containing the OAuth token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`.", - }, - - "username": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The username associated to this token.", + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, }, }, + UseJSONNumber: true, } } -func Cloudbuildv2ConnectionGithubEnterpriseConfigSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "host_uri": { - Type: schema.TypeString, - Required: true, - Description: "Required. The URI of the GitHub Enterprise host this connection is for.", - }, - - "app_id": { - Type: schema.TypeInt, - Optional: true, - Description: "Id of the GitHub App created from the manifest.", - }, - - "app_installation_id": { - Type: schema.TypeInt, - Optional: true, - Description: "ID of the installation of the GitHub App.", - }, - - "app_slug": { - Type: schema.TypeString, - Optional: true, - Description: "The URL-friendly name of the GitHub App.", - }, - - "private_key_secret_version": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "SecretManager resource containing the private key of the GitHub App, formatted as `projects/*/secrets/*/versions/*`.", - }, - - "service_directory_config": { - Type: schema.TypeList, - Optional: true, - Description: "Configuration for using Service Directory to privately connect to a GitHub Enterprise server. This should only be set if the GitHub Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitHub Enterprise server will be made over the public internet.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigSchema(), - }, - - "ssl_ca": { - Type: schema.TypeString, - Optional: true, - Description: "SSL certificate to use for requests to GitHub Enterprise.", - }, - - "webhook_secret_secret_version": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "SecretManager resource containing the webhook secret of the GitHub App, formatted as `projects/*/secrets/*/versions/*`.", - }, - }, +func resourceCloudbuildv2ConnectionCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err } -} -func Cloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "service": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}.", - }, - }, + obj := make(map[string]interface{}) + githubConfigProp, err := expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("github_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(githubConfigProp)) && (ok || !reflect.DeepEqual(v, githubConfigProp)) { + obj["githubConfig"] = githubConfigProp } -} - -func Cloudbuildv2ConnectionGitlabConfigSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "authorizer_credential": { - Type: schema.TypeList, - Required: true, - Description: "Required. A GitLab personal access token with the `api` scope access.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGitlabConfigAuthorizerCredentialSchema(), - }, - - "read_authorizer_credential": { - Type: schema.TypeList, - Required: true, - Description: "Required. A GitLab personal access token with the minimum `read_api` scope access.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialSchema(), - }, - - "webhook_secret_secret_version": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "Required. Immutable. SecretManager resource containing the webhook secret of a GitLab Enterprise project, formatted as `projects/*/secrets/*/versions/*`.", - }, - - "host_uri": { - Type: schema.TypeString, - Computed: true, - Optional: true, - Description: "The URI of the GitLab Enterprise host this connection is for. If not specified, the default value is https://gitlab.com.", - }, - - "service_directory_config": { - Type: schema.TypeList, - Optional: true, - Description: "Configuration for using Service Directory to privately connect to a GitLab Enterprise server. This should only be set if the GitLab Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitLab Enterprise server will be made over the public internet.", - MaxItems: 1, - Elem: Cloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigSchema(), - }, - - "ssl_ca": { - Type: schema.TypeString, - Optional: true, - Description: "SSL certificate to use for requests to GitLab Enterprise.", - }, - - "server_version": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. Version of the GitLab Enterprise server running on the `host_uri`.", - }, - }, + githubEnterpriseConfigProp, err := expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("github_enterprise_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(githubEnterpriseConfigProp)) && (ok || !reflect.DeepEqual(v, githubEnterpriseConfigProp)) { + obj["githubEnterpriseConfig"] = githubEnterpriseConfigProp } -} - -func Cloudbuildv2ConnectionGitlabConfigAuthorizerCredentialSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "user_token_secret_version": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`.", - }, - - "username": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The username associated to this token.", - }, - }, + gitlabConfigProp, err := expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("gitlab_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(gitlabConfigProp)) && (ok || !reflect.DeepEqual(v, gitlabConfigProp)) { + obj["gitlabConfig"] = gitlabConfigProp } -} - -func Cloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "user_token_secret_version": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`.", - }, - - "username": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. The username associated to this token.", - }, - }, + disabledProp, err := expandCloudbuildv2ConnectionDisabled(d.Get("disabled"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) { + obj["disabled"] = disabledProp } -} - -func Cloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "service": { - Type: schema.TypeString, - Required: true, - DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, - Description: "Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}.", - }, - }, + etagProp, err := expandCloudbuildv2ConnectionEtag(d.Get("etag"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("etag"); !tpgresource.IsEmptyValue(reflect.ValueOf(etagProp)) && (ok || !reflect.DeepEqual(v, etagProp)) { + obj["etag"] = etagProp } -} - -func Cloudbuildv2ConnectionInstallationStateSchema() *schema.Resource { - return &schema.Resource{ - Schema: map[string]*schema.Schema{ - "action_uri": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. Link to follow for next action. Empty string if the installation is already complete.", - }, - - "message": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. Message of what the user should do next to continue the installation. Empty string if the installation is already complete.", - }, - - "stage": { - Type: schema.TypeString, - Computed: true, - Description: "Output only. Current step of the installation process. Possible values: STAGE_UNSPECIFIED, PENDING_CREATE_APP, PENDING_USER_OAUTH, PENDING_INSTALL_APP, COMPLETE", - }, - }, + annotationsProp, err := expandCloudbuildv2ConnectionEffectiveAnnotations(d.Get("effective_annotations"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) { + obj["annotations"] = annotationsProp } -} -func resourceCloudbuildv2ConnectionCreate(d *schema.ResourceData, meta interface{}) error { - config := meta.(*transport_tpg.Config) - project, err := tpgresource.GetProject(d, config) + url, err := tpgresource.ReplaceVarsForId(d, config, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections?connectionId={{name}}") if err != nil { return err } - obj := &cloudbuildv2.Connection{ - Location: dcl.String(d.Get("location").(string)), - Name: dcl.String(d.Get("name").(string)), - Disabled: dcl.Bool(d.Get("disabled").(bool)), - Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")), - GithubConfig: expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config")), - GithubEnterpriseConfig: expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config")), - GitlabConfig: expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config")), - Project: dcl.String(project), - } + log.Printf("[DEBUG] Creating new Connection: %#v", obj) + billingProject := "" - id, err := obj.ID() - if err != nil { - return fmt.Errorf("error constructing id: %s", err) - } - d.SetId(id) - directive := tpgdclresource.CreateDirective - userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + project, err := tpgresource.GetProject(d, config) if err != nil { - return err + return fmt.Errorf("Error fetching project for Connection: %s", err) } - billingProject := project + billingProject = strings.TrimPrefix(project, "projects/") + // err == nil indicates that the billing_project value was found if bp, err := tpgresource.GetBillingProject(d, config); err == nil { billingProject = bp } - client := transport_tpg.NewDCLCloudbuildv2Client(config, userAgent, billingProject, d.Timeout(schema.TimeoutCreate)) - if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil { - d.SetId("") - return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) - } else { - client.Config.BasePath = bp + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return fmt.Errorf("Error creating Connection: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVarsForId(d, config, "projects/{{project}}/locations/{{location}}/connections/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) } - res, err := client.ApplyConnection(context.Background(), obj, directive...) + d.SetId(id) + + err = Cloudbuildv2OperationWaitTime( + config, res, tpgresource.GetResourceNameFromSelfLink(project), "Creating Connection", userAgent, + d.Timeout(schema.TimeoutCreate)) - if _, ok := err.(dcl.DiffAfterApplyError); ok { - log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err) - } else if err != nil { + if err != nil { // The resource didn't actually create d.SetId("") - return fmt.Errorf("Error creating Connection: %s", err) + return fmt.Errorf("Error waiting to create Connection: %s", err) } log.Printf("[DEBUG] Finished creating Connection %q: %#v", d.Id(), res) @@ -458,189 +435,233 @@ func resourceCloudbuildv2ConnectionCreate(d *schema.ResourceData, meta interface func resourceCloudbuildv2ConnectionRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) - project, err := tpgresource.GetProject(d, config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { return err } - obj := &cloudbuildv2.Connection{ - Location: dcl.String(d.Get("location").(string)), - Name: dcl.String(d.Get("name").(string)), - Disabled: dcl.Bool(d.Get("disabled").(bool)), - Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")), - GithubConfig: expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config")), - GithubEnterpriseConfig: expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config")), - GitlabConfig: expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config")), - Project: dcl.String(project), + url, err := tpgresource.ReplaceVarsForId(d, config, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections/{{name}}") + if err != nil { + return err } - userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + billingProject := "" + + project, err := tpgresource.GetProject(d, config) if err != nil { - return err + return fmt.Errorf("Error fetching project for Connection: %s", err) } - billingProject := project + billingProject = strings.TrimPrefix(project, "projects/") + // err == nil indicates that the billing_project value was found if bp, err := tpgresource.GetBillingProject(d, config); err == nil { billingProject = bp } - client := transport_tpg.NewDCLCloudbuildv2Client(config, userAgent, billingProject, d.Timeout(schema.TimeoutRead)) - if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil { - d.SetId("") - return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) - } else { - client.Config.BasePath = bp - } - res, err := client.GetConnection(context.Background(), obj) + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + }) if err != nil { - resourceName := fmt.Sprintf("Cloudbuildv2Connection %q", d.Id()) - return tpgdclresource.HandleNotFoundDCLError(err, d, resourceName) + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Cloudbuildv2Connection %q", d.Id())) } - if err = d.Set("location", res.Location); err != nil { - return fmt.Errorf("error setting location in state: %s", err) - } - if err = d.Set("name", res.Name); err != nil { - return fmt.Errorf("error setting name in state: %s", err) - } - if err = d.Set("disabled", res.Disabled); err != nil { - return fmt.Errorf("error setting disabled in state: %s", err) + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("effective_annotations", res.Annotations); err != nil { - return fmt.Errorf("error setting effective_annotations in state: %s", err) + + if err := d.Set("create_time", flattenCloudbuildv2ConnectionCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("github_config", flattenCloudbuildv2ConnectionGithubConfig(res.GithubConfig)); err != nil { - return fmt.Errorf("error setting github_config in state: %s", err) + if err := d.Set("update_time", flattenCloudbuildv2ConnectionUpdateTime(res["updateTime"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("github_enterprise_config", flattenCloudbuildv2ConnectionGithubEnterpriseConfig(res.GithubEnterpriseConfig)); err != nil { - return fmt.Errorf("error setting github_enterprise_config in state: %s", err) + if err := d.Set("github_config", flattenCloudbuildv2ConnectionGithubConfig(res["githubConfig"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("gitlab_config", flattenCloudbuildv2ConnectionGitlabConfig(res.GitlabConfig)); err != nil { - return fmt.Errorf("error setting gitlab_config in state: %s", err) + if err := d.Set("github_enterprise_config", flattenCloudbuildv2ConnectionGithubEnterpriseConfig(res["githubEnterpriseConfig"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("project", res.Project); err != nil { - return fmt.Errorf("error setting project in state: %s", err) + if err := d.Set("gitlab_config", flattenCloudbuildv2ConnectionGitlabConfig(res["gitlabConfig"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("annotations", flattenCloudbuildv2ConnectionAnnotations(res.Annotations, d)); err != nil { - return fmt.Errorf("error setting annotations in state: %s", err) + if err := d.Set("installation_state", flattenCloudbuildv2ConnectionInstallationState(res["installationState"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("create_time", res.CreateTime); err != nil { - return fmt.Errorf("error setting create_time in state: %s", err) + if err := d.Set("disabled", flattenCloudbuildv2ConnectionDisabled(res["disabled"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("etag", res.Etag); err != nil { - return fmt.Errorf("error setting etag in state: %s", err) + if err := d.Set("reconciling", flattenCloudbuildv2ConnectionReconciling(res["reconciling"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("installation_state", flattenCloudbuildv2ConnectionInstallationState(res.InstallationState)); err != nil { - return fmt.Errorf("error setting installation_state in state: %s", err) + if err := d.Set("annotations", flattenCloudbuildv2ConnectionAnnotations(res["annotations"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("reconciling", res.Reconciling); err != nil { - return fmt.Errorf("error setting reconciling in state: %s", err) + if err := d.Set("etag", flattenCloudbuildv2ConnectionEtag(res["etag"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } - if err = d.Set("update_time", res.UpdateTime); err != nil { - return fmt.Errorf("error setting update_time in state: %s", err) + if err := d.Set("effective_annotations", flattenCloudbuildv2ConnectionEffectiveAnnotations(res["annotations"], d, config)); err != nil { + return fmt.Errorf("Error reading Connection: %s", err) } return nil } + func resourceCloudbuildv2ConnectionUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) - project, err := tpgresource.GetProject(d, config) - if err != nil { - return err - } - - obj := &cloudbuildv2.Connection{ - Location: dcl.String(d.Get("location").(string)), - Name: dcl.String(d.Get("name").(string)), - Disabled: dcl.Bool(d.Get("disabled").(bool)), - Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")), - GithubConfig: expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config")), - GithubEnterpriseConfig: expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config")), - GitlabConfig: expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config")), - Project: dcl.String(project), - } - directive := tpgdclresource.UpdateDirective userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { return err } billingProject := "" - // err == nil indicates that the billing_project value was found - if bp, err := tpgresource.GetBillingProject(d, config); err == nil { - billingProject = bp - } - client := transport_tpg.NewDCLCloudbuildv2Client(config, userAgent, billingProject, d.Timeout(schema.TimeoutUpdate)) - if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil { - d.SetId("") - return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) - } else { - client.Config.BasePath = bp - } - res, err := client.ApplyConnection(context.Background(), obj, directive...) - if _, ok := err.(dcl.DiffAfterApplyError); ok { - log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err) - } else if err != nil { - // The resource didn't actually create - d.SetId("") - return fmt.Errorf("Error updating Connection: %s", err) + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Connection: %s", err) } + billingProject = strings.TrimPrefix(project, "projects/") - log.Printf("[DEBUG] Finished creating Connection %q: %#v", d.Id(), res) + obj := make(map[string]interface{}) + githubConfigProp, err := expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("github_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, githubConfigProp)) { + obj["githubConfig"] = githubConfigProp + } + githubEnterpriseConfigProp, err := expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("github_enterprise_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, githubEnterpriseConfigProp)) { + obj["githubEnterpriseConfig"] = githubEnterpriseConfigProp + } + gitlabConfigProp, err := expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("gitlab_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, gitlabConfigProp)) { + obj["gitlabConfig"] = gitlabConfigProp + } + disabledProp, err := expandCloudbuildv2ConnectionDisabled(d.Get("disabled"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, disabledProp)) { + obj["disabled"] = disabledProp + } + etagProp, err := expandCloudbuildv2ConnectionEtag(d.Get("etag"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("etag"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, etagProp)) { + obj["etag"] = etagProp + } + annotationsProp, err := expandCloudbuildv2ConnectionEffectiveAnnotations(d.Get("effective_annotations"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, annotationsProp)) { + obj["annotations"] = annotationsProp + } + + url, err := tpgresource.ReplaceVarsForId(d, config, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Connection %q: %#v", d.Id(), obj) + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + }) + + if err != nil { + return fmt.Errorf("Error updating Connection %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Connection %q: %#v", d.Id(), res) + } + + err = Cloudbuildv2OperationWaitTime( + config, res, tpgresource.GetResourceNameFromSelfLink(project), "Updating Connection", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } return resourceCloudbuildv2ConnectionRead(d, meta) } func resourceCloudbuildv2ConnectionDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) - project, err := tpgresource.GetProject(d, config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) if err != nil { return err } - obj := &cloudbuildv2.Connection{ - Location: dcl.String(d.Get("location").(string)), - Name: dcl.String(d.Get("name").(string)), - Disabled: dcl.Bool(d.Get("disabled").(bool)), - Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")), - GithubConfig: expandCloudbuildv2ConnectionGithubConfig(d.Get("github_config")), - GithubEnterpriseConfig: expandCloudbuildv2ConnectionGithubEnterpriseConfig(d.Get("github_enterprise_config")), - GitlabConfig: expandCloudbuildv2ConnectionGitlabConfig(d.Get("gitlab_config")), - Project: dcl.String(project), + billingProject := "" + + project, err := tpgresource.GetProject(d, config) + if err != nil { + return fmt.Errorf("Error fetching project for Connection: %s", err) } + billingProject = strings.TrimPrefix(project, "projects/") - log.Printf("[DEBUG] Deleting Connection %q", d.Id()) - userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + url, err := tpgresource.ReplaceVarsForId(d, config, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections/{{name}}") if err != nil { return err } - billingProject := project + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Connection %q", d.Id()) + // err == nil indicates that the billing_project value was found if bp, err := tpgresource.GetBillingProject(d, config); err == nil { billingProject = bp } - client := transport_tpg.NewDCLCloudbuildv2Client(config, userAgent, billingProject, d.Timeout(schema.TimeoutDelete)) - if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil { - d.SetId("") - return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err) - } else { - client.Config.BasePath = bp + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutDelete), + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, "Connection") } - if err := client.DeleteConnection(context.Background(), obj); err != nil { - return fmt.Errorf("Error deleting Connection: %s", err) + + err = Cloudbuildv2OperationWaitTime( + config, res, tpgresource.GetResourceNameFromSelfLink(project), "Deleting Connection", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err } - log.Printf("[DEBUG] Finished deleting Connection %q", d.Id()) + log.Printf("[DEBUG] Finished deleting Connection %q: %#v", d.Id(), res) return nil } func resourceCloudbuildv2ConnectionImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { config := meta.(*transport_tpg.Config) - if err := tpgresource.ParseImportId([]string{ - "projects/(?P[^/]+)/locations/(?P[^/]+)/connections/(?P[^/]+)", - "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", - "(?P[^/]+)/(?P[^/]+)", + "^projects/(?P[^/]+)/locations/(?P[^/]+)/connections/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)$", + "^(?P[^/]+)/(?P[^/]+)$", + "^(?P[^/]+)$", }, d, config); err != nil { return nil, err } @@ -655,269 +676,697 @@ func resourceCloudbuildv2ConnectionImport(d *schema.ResourceData, meta interface return []*schema.ResourceData{d}, nil } -func expandCloudbuildv2ConnectionGithubConfig(o interface{}) *cloudbuildv2.ConnectionGithubConfig { - if o == nil { - return cloudbuildv2.EmptyConnectionGithubConfig - } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGithubConfig +func flattenCloudbuildv2ConnectionCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGithubConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGithubConfig{ - AppInstallationId: dcl.Int64(int64(obj["app_installation_id"].(int))), - AuthorizerCredential: expandCloudbuildv2ConnectionGithubConfigAuthorizerCredential(obj["authorizer_credential"]), + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } + transformed := make(map[string]interface{}) + transformed["authorizer_credential"] = + flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredential(original["authorizerCredential"], d, config) + transformed["app_installation_id"] = + flattenCloudbuildv2ConnectionGithubConfigAppInstallationId(original["appInstallationId"], d, config) + return []interface{}{transformed} } - -func flattenCloudbuildv2ConnectionGithubConfig(obj *cloudbuildv2.ConnectionGithubConfig) interface{} { - if obj == nil || obj.Empty() { +func flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredential(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { return nil } - transformed := map[string]interface{}{ - "app_installation_id": obj.AppInstallationId, - "authorizer_credential": flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredential(obj.AuthorizerCredential), + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } - + transformed := make(map[string]interface{}) + transformed["oauth_token_secret_version"] = + flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredentialOauthTokenSecretVersion(original["oauthTokenSecretVersion"], d, config) + transformed["username"] = + flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredentialUsername(original["username"], d, config) return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredentialOauthTokenSecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} +func flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredentialUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func expandCloudbuildv2ConnectionGithubConfigAuthorizerCredential(o interface{}) *cloudbuildv2.ConnectionGithubConfigAuthorizerCredential { - if o == nil { - return cloudbuildv2.EmptyConnectionGithubConfigAuthorizerCredential - } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGithubConfigAuthorizerCredential +func flattenCloudbuildv2ConnectionGithubConfigAppInstallationId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { + return intVal + } } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGithubConfigAuthorizerCredential{ - OAuthTokenSecretVersion: dcl.String(obj["oauth_token_secret_version"].(string)), + + // number values are represented as float64 + if floatVal, ok := v.(float64); ok { + intVal := int(floatVal) + return intVal } + + return v // let terraform core handle it otherwise } -func flattenCloudbuildv2ConnectionGithubConfigAuthorizerCredential(obj *cloudbuildv2.ConnectionGithubConfigAuthorizerCredential) interface{} { - if obj == nil || obj.Empty() { +func flattenCloudbuildv2ConnectionGithubEnterpriseConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { return nil } - transformed := map[string]interface{}{ - "oauth_token_secret_version": obj.OAuthTokenSecretVersion, - "username": obj.Username, + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } - + transformed := make(map[string]interface{}) + transformed["host_uri"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigHostUri(original["hostUri"], d, config) + transformed["app_id"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppId(original["appId"], d, config) + transformed["app_slug"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppSlug(original["appSlug"], d, config) + transformed["private_key_secret_version"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigPrivateKeySecretVersion(original["privateKeySecretVersion"], d, config) + transformed["webhook_secret_secret_version"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigWebhookSecretSecretVersion(original["webhookSecretSecretVersion"], d, config) + transformed["app_installation_id"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppInstallationId(original["appInstallationId"], d, config) + transformed["service_directory_config"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(original["serviceDirectoryConfig"], d, config) + transformed["ssl_ca"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigSslCa(original["sslCa"], d, config) return []interface{}{transformed} - +} +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigHostUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func expandCloudbuildv2ConnectionGithubEnterpriseConfig(o interface{}) *cloudbuildv2.ConnectionGithubEnterpriseConfig { - if o == nil { - return cloudbuildv2.EmptyConnectionGithubEnterpriseConfig +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { + return intVal + } } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGithubEnterpriseConfig + + // number values are represented as float64 + if floatVal, ok := v.(float64); ok { + intVal := int(floatVal) + return intVal } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGithubEnterpriseConfig{ - HostUri: dcl.String(obj["host_uri"].(string)), - AppId: dcl.Int64(int64(obj["app_id"].(int))), - AppInstallationId: dcl.Int64(int64(obj["app_installation_id"].(int))), - AppSlug: dcl.String(obj["app_slug"].(string)), - PrivateKeySecretVersion: dcl.String(obj["private_key_secret_version"].(string)), - ServiceDirectoryConfig: expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(obj["service_directory_config"]), - SslCa: dcl.String(obj["ssl_ca"].(string)), - WebhookSecretSecretVersion: dcl.String(obj["webhook_secret_secret_version"].(string)), + + return v // let terraform core handle it otherwise +} + +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppSlug(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigPrivateKeySecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigWebhookSecretSecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigAppInstallationId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + // Handles the string fixed64 format + if strVal, ok := v.(string); ok { + if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { + return intVal + } + } + + // number values are represented as float64 + if floatVal, ok := v.(float64); ok { + intVal := int(floatVal) + return intVal } + + return v // let terraform core handle it otherwise } -func flattenCloudbuildv2ConnectionGithubEnterpriseConfig(obj *cloudbuildv2.ConnectionGithubEnterpriseConfig) interface{} { - if obj == nil || obj.Empty() { +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { return nil } - transformed := map[string]interface{}{ - "host_uri": obj.HostUri, - "app_id": obj.AppId, - "app_installation_id": obj.AppInstallationId, - "app_slug": obj.AppSlug, - "private_key_secret_version": obj.PrivateKeySecretVersion, - "service_directory_config": flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(obj.ServiceDirectoryConfig), - "ssl_ca": obj.SslCa, - "webhook_secret_secret_version": obj.WebhookSecretSecretVersion, + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } - + transformed := make(map[string]interface{}) + transformed["service"] = + flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigService(original["service"], d, config) return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigService(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} +func flattenCloudbuildv2ConnectionGithubEnterpriseConfigSslCa(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(o interface{}) *cloudbuildv2.ConnectionGithubEnterpriseConfigServiceDirectoryConfig { - if o == nil { - return cloudbuildv2.EmptyConnectionGithubEnterpriseConfigServiceDirectoryConfig - } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGithubEnterpriseConfigServiceDirectoryConfig +func flattenCloudbuildv2ConnectionGitlabConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGithubEnterpriseConfigServiceDirectoryConfig{ - Service: dcl.String(obj["service"].(string)), + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } + transformed := make(map[string]interface{}) + transformed["host_uri"] = + flattenCloudbuildv2ConnectionGitlabConfigHostUri(original["hostUri"], d, config) + transformed["webhook_secret_secret_version"] = + flattenCloudbuildv2ConnectionGitlabConfigWebhookSecretSecretVersion(original["webhookSecretSecretVersion"], d, config) + transformed["read_authorizer_credential"] = + flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(original["readAuthorizerCredential"], d, config) + transformed["authorizer_credential"] = + flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(original["authorizerCredential"], d, config) + transformed["service_directory_config"] = + flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(original["serviceDirectoryConfig"], d, config) + transformed["ssl_ca"] = + flattenCloudbuildv2ConnectionGitlabConfigSslCa(original["sslCa"], d, config) + transformed["server_version"] = + flattenCloudbuildv2ConnectionGitlabConfigServerVersion(original["serverVersion"], d, config) + return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGitlabConfigHostUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func flattenCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(obj *cloudbuildv2.ConnectionGithubEnterpriseConfigServiceDirectoryConfig) interface{} { - if obj == nil || obj.Empty() { +func flattenCloudbuildv2ConnectionGitlabConfigWebhookSecretSecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { return nil } - transformed := map[string]interface{}{ - "service": obj.Service, + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } - + transformed := make(map[string]interface{}) + transformed["user_token_secret_version"] = + flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUserTokenSecretVersion(original["userTokenSecretVersion"], d, config) + transformed["username"] = + flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUsername(original["username"], d, config) return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUserTokenSecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} +func flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func expandCloudbuildv2ConnectionGitlabConfig(o interface{}) *cloudbuildv2.ConnectionGitlabConfig { - if o == nil { - return cloudbuildv2.EmptyConnectionGitlabConfig - } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGitlabConfig +func flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGitlabConfig{ - AuthorizerCredential: expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(obj["authorizer_credential"]), - ReadAuthorizerCredential: expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(obj["read_authorizer_credential"]), - WebhookSecretSecretVersion: dcl.String(obj["webhook_secret_secret_version"].(string)), - HostUri: dcl.StringOrNil(obj["host_uri"].(string)), - ServiceDirectoryConfig: expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(obj["service_directory_config"]), - SslCa: dcl.String(obj["ssl_ca"].(string)), + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } + transformed := make(map[string]interface{}) + transformed["user_token_secret_version"] = + flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUserTokenSecretVersion(original["userTokenSecretVersion"], d, config) + transformed["username"] = + flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUsername(original["username"], d, config) + return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUserTokenSecretVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func flattenCloudbuildv2ConnectionGitlabConfig(obj *cloudbuildv2.ConnectionGitlabConfig) interface{} { - if obj == nil || obj.Empty() { +func flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUsername(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { return nil } - transformed := map[string]interface{}{ - "authorizer_credential": flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(obj.AuthorizerCredential), - "read_authorizer_credential": flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(obj.ReadAuthorizerCredential), - "webhook_secret_secret_version": obj.WebhookSecretSecretVersion, - "host_uri": obj.HostUri, - "service_directory_config": flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(obj.ServiceDirectoryConfig), - "ssl_ca": obj.SslCa, - "server_version": obj.ServerVersion, + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil } + transformed := make(map[string]interface{}) + transformed["service"] = + flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigService(original["service"], d, config) + return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigService(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionGitlabConfigSslCa(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} +func flattenCloudbuildv2ConnectionGitlabConfigServerVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionInstallationState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["stage"] = + flattenCloudbuildv2ConnectionInstallationStateStage(original["stage"], d, config) + transformed["message"] = + flattenCloudbuildv2ConnectionInstallationStateMessage(original["message"], d, config) + transformed["action_uri"] = + flattenCloudbuildv2ConnectionInstallationStateActionUri(original["actionUri"], d, config) return []interface{}{transformed} +} +func flattenCloudbuildv2ConnectionInstallationStateStage(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionInstallationStateMessage(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionInstallationStateActionUri(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionDisabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} +func flattenCloudbuildv2ConnectionReconciling(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v } -func expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(o interface{}) *cloudbuildv2.ConnectionGitlabConfigAuthorizerCredential { - if o == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigAuthorizerCredential +func flattenCloudbuildv2ConnectionAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigAuthorizerCredential + + transformed := make(map[string]interface{}) + if l, ok := d.GetOkExists("annotations"); ok { + for k := range l.(map[string]interface{}) { + transformed[k] = v.(map[string]interface{})[k] + } } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGitlabConfigAuthorizerCredential{ - UserTokenSecretVersion: dcl.String(obj["user_token_secret_version"].(string)), + + return transformed +} + +func flattenCloudbuildv2ConnectionEtag(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudbuildv2ConnectionEffectiveAnnotations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func expandCloudbuildv2ConnectionGithubConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedAuthorizerCredential, err := expandCloudbuildv2ConnectionGithubConfigAuthorizerCredential(original["authorizer_credential"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAuthorizerCredential); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["authorizerCredential"] = transformedAuthorizerCredential + } + + transformedAppInstallationId, err := expandCloudbuildv2ConnectionGithubConfigAppInstallationId(original["app_installation_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAppInstallationId); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["appInstallationId"] = transformedAppInstallationId + } + + return transformed, nil } -func flattenCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(obj *cloudbuildv2.ConnectionGitlabConfigAuthorizerCredential) interface{} { - if obj == nil || obj.Empty() { - return nil +func expandCloudbuildv2ConnectionGithubConfigAuthorizerCredential(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil } - transformed := map[string]interface{}{ - "user_token_secret_version": obj.UserTokenSecretVersion, - "username": obj.Username, + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedOauthTokenSecretVersion, err := expandCloudbuildv2ConnectionGithubConfigAuthorizerCredentialOauthTokenSecretVersion(original["oauth_token_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedOauthTokenSecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["oauthTokenSecretVersion"] = transformedOauthTokenSecretVersion } - return []interface{}{transformed} + transformedUsername, err := expandCloudbuildv2ConnectionGithubConfigAuthorizerCredentialUsername(original["username"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["username"] = transformedUsername + } + + return transformed, nil +} + +func expandCloudbuildv2ConnectionGithubConfigAuthorizerCredentialOauthTokenSecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} +func expandCloudbuildv2ConnectionGithubConfigAuthorizerCredentialUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil } -func expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(o interface{}) *cloudbuildv2.ConnectionGitlabConfigReadAuthorizerCredential { - if o == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigReadAuthorizerCredential +func expandCloudbuildv2ConnectionGithubConfigAppInstallationId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHostUri, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigHostUri(original["host_uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHostUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["hostUri"] = transformedHostUri } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigReadAuthorizerCredential + + transformedAppId, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigAppId(original["app_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAppId); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["appId"] = transformedAppId } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGitlabConfigReadAuthorizerCredential{ - UserTokenSecretVersion: dcl.String(obj["user_token_secret_version"].(string)), + + transformedAppSlug, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigAppSlug(original["app_slug"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAppSlug); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["appSlug"] = transformedAppSlug } + + transformedPrivateKeySecretVersion, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigPrivateKeySecretVersion(original["private_key_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPrivateKeySecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["privateKeySecretVersion"] = transformedPrivateKeySecretVersion + } + + transformedWebhookSecretSecretVersion, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigWebhookSecretSecretVersion(original["webhook_secret_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedWebhookSecretSecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["webhookSecretSecretVersion"] = transformedWebhookSecretSecretVersion + } + + transformedAppInstallationId, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigAppInstallationId(original["app_installation_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAppInstallationId); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["appInstallationId"] = transformedAppInstallationId + } + + transformedServiceDirectoryConfig, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(original["service_directory_config"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServiceDirectoryConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["serviceDirectoryConfig"] = transformedServiceDirectoryConfig + } + + transformedSslCa, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigSslCa(original["ssl_ca"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSslCa); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["sslCa"] = transformedSslCa + } + + return transformed, nil } -func flattenCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(obj *cloudbuildv2.ConnectionGitlabConfigReadAuthorizerCredential) interface{} { - if obj == nil || obj.Empty() { - return nil +func expandCloudbuildv2ConnectionGithubEnterpriseConfigHostUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigAppId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigAppSlug(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigPrivateKeySecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigWebhookSecretSecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigAppInstallationId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil } - transformed := map[string]interface{}{ - "user_token_secret_version": obj.UserTokenSecretVersion, - "username": obj.Username, + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedService, err := expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigService(original["service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedService); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["service"] = transformedService } - return []interface{}{transformed} + return transformed, nil +} + +func expandCloudbuildv2ConnectionGithubEnterpriseConfigServiceDirectoryConfigService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} +func expandCloudbuildv2ConnectionGithubEnterpriseConfigSslCa(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil } -func expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(o interface{}) *cloudbuildv2.ConnectionGitlabConfigServiceDirectoryConfig { - if o == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigServiceDirectoryConfig +func expandCloudbuildv2ConnectionGitlabConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil } - objArr := o.([]interface{}) - if len(objArr) == 0 || objArr[0] == nil { - return cloudbuildv2.EmptyConnectionGitlabConfigServiceDirectoryConfig + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedHostUri, err := expandCloudbuildv2ConnectionGitlabConfigHostUri(original["host_uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedHostUri); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["hostUri"] = transformedHostUri } - obj := objArr[0].(map[string]interface{}) - return &cloudbuildv2.ConnectionGitlabConfigServiceDirectoryConfig{ - Service: dcl.String(obj["service"].(string)), + + transformedWebhookSecretSecretVersion, err := expandCloudbuildv2ConnectionGitlabConfigWebhookSecretSecretVersion(original["webhook_secret_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedWebhookSecretSecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["webhookSecretSecretVersion"] = transformedWebhookSecretSecretVersion } -} -func flattenCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(obj *cloudbuildv2.ConnectionGitlabConfigServiceDirectoryConfig) interface{} { - if obj == nil || obj.Empty() { - return nil + transformedReadAuthorizerCredential, err := expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(original["read_authorizer_credential"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedReadAuthorizerCredential); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["readAuthorizerCredential"] = transformedReadAuthorizerCredential } - transformed := map[string]interface{}{ - "service": obj.Service, + + transformedAuthorizerCredential, err := expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(original["authorizer_credential"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAuthorizerCredential); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["authorizerCredential"] = transformedAuthorizerCredential } - return []interface{}{transformed} + transformedServiceDirectoryConfig, err := expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(original["service_directory_config"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServiceDirectoryConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["serviceDirectoryConfig"] = transformedServiceDirectoryConfig + } + transformedSslCa, err := expandCloudbuildv2ConnectionGitlabConfigSslCa(original["ssl_ca"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSslCa); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["sslCa"] = transformedSslCa + } + + transformedServerVersion, err := expandCloudbuildv2ConnectionGitlabConfigServerVersion(original["server_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServerVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["serverVersion"] = transformedServerVersion + } + + return transformed, nil } -func flattenCloudbuildv2ConnectionInstallationState(obj *cloudbuildv2.ConnectionInstallationState) interface{} { - if obj == nil || obj.Empty() { - return nil +func expandCloudbuildv2ConnectionGitlabConfigHostUri(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigWebhookSecretSecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredential(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil } - transformed := map[string]interface{}{ - "action_uri": obj.ActionUri, - "message": obj.Message, - "stage": obj.Stage, + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedUserTokenSecretVersion, err := expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUserTokenSecretVersion(original["user_token_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUserTokenSecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["userTokenSecretVersion"] = transformedUserTokenSecretVersion } - return []interface{}{transformed} + transformedUsername, err := expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUsername(original["username"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["username"] = transformedUsername + } + return transformed, nil } -func flattenCloudbuildv2ConnectionAnnotations(v map[string]string, d *schema.ResourceData) interface{} { - if v == nil { - return nil +func expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUserTokenSecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigReadAuthorizerCredentialUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredential(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedUserTokenSecretVersion, err := expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUserTokenSecretVersion(original["user_token_secret_version"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUserTokenSecretVersion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["userTokenSecretVersion"] = transformedUserTokenSecretVersion + } + + transformedUsername, err := expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUsername(original["username"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUsername); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["username"] = transformedUsername } + return transformed, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUserTokenSecretVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigAuthorizerCredentialUsername(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + if len(l) == 0 || l[0] == nil { + return nil, nil + } + raw := l[0] + original := raw.(map[string]interface{}) transformed := make(map[string]interface{}) - if l, ok := d.Get("annotations").(map[string]interface{}); ok { - for k, _ := range l { - transformed[k] = v[k] - } + + transformedService, err := expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigService(original["service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedService); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["service"] = transformedService } - return transformed + return transformed, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigServiceDirectoryConfigService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigSslCa(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionGitlabConfigServerVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionEtag(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandCloudbuildv2ConnectionEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil } diff --git a/google/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_test.go b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_test.go index 6bc867b9757..98b80b47852 100644 --- a/google/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_test.go +++ b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_generated_test.go @@ -3,103 +3,37 @@ // ---------------------------------------------------------------------------- // -// *** AUTO GENERATED CODE *** Type: DCL *** +// *** AUTO GENERATED CODE *** Type: MMv1 *** // // ---------------------------------------------------------------------------- // -// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) -// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). -// Changes will need to be made to the DCL or Magic Modules instead of here. +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. // -// We are not currently able to accept contributions to this file. If changes -// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. // // ---------------------------------------------------------------------------- package cloudbuildv2_test import ( - "context" "fmt" - dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl" - cloudbuildv2 "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuildv2" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "strings" "testing" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-google/google/acctest" - "github.com/hashicorp/terraform-provider-google/google/envvar" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" ) -func TestAccCloudbuildv2Connection_GheCompleteConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "region": envvar.GetTestRegionFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GheCompleteConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GheConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "region": envvar.GetTestRegionFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GheConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GheConnectionUpdate0(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GhePrivConnection(t *testing.T) { +func TestAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(t *testing.T) { t.Parallel() context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "region": envvar.GetTestRegionFromEnv(), "random_suffix": acctest.RandString(t, 10), } @@ -109,376 +43,23 @@ func TestAccCloudbuildv2Connection_GhePrivConnection(t *testing.T) { CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccCloudbuildv2Connection_GhePrivConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GhePrivUpdateConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "region": envvar.GetTestRegionFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GhePrivUpdateConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GhePrivUpdateConnectionUpdate0(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GithubConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "region": envvar.GetTestRegionFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GithubConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GithubConnectionUpdate0(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GitlabConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GitlabConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GleConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GleConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GleConnectionUpdate0(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GleOldConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GleOldConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GleOldConnectionUpdate0(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GlePrivConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GlePrivConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - }, - }) -} -func TestAccCloudbuildv2Connection_GlePrivUpdateConnection(t *testing.T) { - t.Parallel() - - context := map[string]interface{}{ - "project_name": envvar.GetTestProjectFromEnv(), - "random_suffix": acctest.RandString(t, 10), - } - - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccCloudbuildv2Connection_GlePrivUpdateConnection(context), - }, - { - ResourceName: "google_cloudbuildv2_connection.primary", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, - }, - { - Config: testAccCloudbuildv2Connection_GlePrivUpdateConnectionUpdate0(context), + Config: testAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(context), }, { - ResourceName: "google_cloudbuildv2_connection.primary", + ResourceName: "google_cloudbuildv2_connection.my-connection", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"annotations"}, + ImportStateVerifyIgnore: []string{"name", "location", "annotations"}, }, }, }) } -func testAccCloudbuildv2Connection_GheCompleteConnection(context map[string]interface{}) string { +func testAccCloudbuildv2Connection_cloudbuildv2ConnectionExample(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - 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" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GheConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - github_enterprise_config { - host_uri = "https://ghe.proctor-staging-test.com" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GheConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - 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" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GhePrivConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - github_enterprise_config { - host_uri = "https://ghe.proctor-private-ca.com" - - service_directory_config { - service = "projects/gcb-terraform-creds/locations/%{region}/namespaces/myns/services/serv" - } - - ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIEXTCCA0WgAwIBAgIUANaBCc9j/xdKJHU0sgmv6yE2WCIwDQYJKoZIhvcNAQEL\nBQAwLDEUMBIGA1UEChMLUHJvY3RvciBFbmcxFDASBgNVBAMTC1Byb2N0b3ItZW5n\nMB4XDTIxMDcxNTIwMDcwMloXDTIyMDcxNTIwMDcwMVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBAMVel7I88DkhwW445BNPBZvJNTV1AreHdz4um4U1\nop2+4L7JeNrUs5SRc0fzeOyOmA9ZzTDu9hBC7zj/sVNUy6cIQGCj32sr5SCAEIat\nnFZlzmVqJPT4J5NAaE37KO5347myTJEBrvpq8az4CtvX0yUzPK0gbUmaSaztVi4o\ndbJLKyv575xCLC/Hu6fIHBDH19eG1Ath9VpuAOkttRRoxu2VqijJZrGqaS+0o+OX\nrLi5HMtZbZjgQB4mc1g3ZDKX/gynxr+CDNaqNOqxuog33Tl5OcOk9DrR3MInaE7F\nyQFuH9mzF64AqOoTf7Tr/eAIz5XVt8K51nk+fSybEfKVwtMCAwEAAaOCAaEwggGd\nMA4GA1UdDwEB/wQEAwIFoDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQU/9dYyqMz\nv9rOMwPZcoIRMDAQCjAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDCB\njQYIKwYBBQUHAQEEgYAwfjB8BggrBgEFBQcwAoZwaHR0cDovL3ByaXZhdGVjYS1j\nb250ZW50LTYxYWEyYzA5LTAwMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9y\nYWdlLmdvb2dsZWFwaXMuY29tLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NhLmNydDAo\nBgNVHREBAf8EHjAcghpnaGUucHJvY3Rvci1wcml2YXRlLWNhLmNvbTCBggYDVR0f\nBHsweTB3oHWgc4ZxaHR0cDovL3ByaXZhdGVjYS1jb250ZW50LTYxYWEyYzA5LTAw\nMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9yYWdlLmdvb2dsZWFwaXMuY29t\nLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NybC5jcmwwDQYJKoZIhvcNAQELBQADggEB\nABo6BQLEZZ+YNiDuv2sRvcxSopQQb7fZjqIA9XOA35pNSKay2SncODnNvfsdRnOp\ncoy25sQSIzWyJ9zWl8DZ6evoOu5csZ2PoFqx5LsIq37w+ZcwD6DM8Zm7JqASxmxx\nGqTF0nHC4Aw8q8aJBeRD3PsSkfN5Q3DP3nTDnLyd0l+yPIkHUbZMoiFHX3BkhCng\nG96mYy/y3t16ghfV9lZkXpD/JK5aiN0bTHCDRc69owgfYiAcAqzBJ9gfZ90MBgzv\ngTTQel5dHg49SYXfnUpTy0HdQLEcoggOF8Q8V+xKdKa6eVbrvjJrkEJmvIQI5iCR\nhNvKR25mx8JUopqEXmONmqU=\n-----END CERTIFICATE-----\n\n-----BEGIN CERTIFICATE-----\nMIIDSDCCAjCgAwIBAgITMwWN+62nLcgyLa7p+jD1K90g6TANBgkqhkiG9w0BAQsF\nADAsMRQwEgYDVQQKEwtQcm9jdG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcw\nHhcNMjEwNzEyMTM1OTQ0WhcNMzEwNzEwMTM1OTQzWjAsMRQwEgYDVQQKEwtQcm9j\ndG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcwggEiMA0GCSqGSIb3DQEBAQUA\nA4IBDwAwggEKAoIBAQCYqJP5Qt90jIbld2dtuUV/zIkBFsTe4fapJfhBji03xBpN\nO1Yxj/jPSZ67Kdeoy0lEwvc2hL5FQGhIjLMR0mzOyN4fk/DZiA/4tAVi7hJyqpUC\n71JSwp7MwXL1b26CSE1MhcoCqA/E4iZxfJfF/ef4lhmC24UEmu8FEbldoy+6OysB\nRu7dGDwicW5F9h7eSkpGAsCRdJHh65iUx/IH0C4Ux2UZRDZdj6wVbuVu9tb938xF\nyRuVClONoLSn/lwdzeV7hQmBSm8qmfgbNPbYRaNLz3hOpsT+27aDQp2/pxue8hFJ\nd7We3+Lr5O4IL45PBwhVEAiFZqde6d4qViNEB2qTAgMBAAGjYzBhMA4GA1UdDwEB\n/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTkQGTiCkLCmv/Awxdz\n5TAVRmyFfDAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDANBgkqhkiG\n9w0BAQsFAAOCAQEAfy5BJsWdx0oWWi7SFg9MbryWjBVPJl93UqACgG0Cgh813O/x\nlDZQhGO/ZFVhHz/WgooE/HgVNoVJTubKLLzz+zCkOB0wa3GMqJDyFjhFmUtd/3VM\nZh0ZQ+JWYsAiZW4VITj5xEn/d/B3xCFWGC1vhvhptEJ8Fo2cE1yM2pzk08NqFWoY\n4FaH0sbxWgyCKwTmtcYDbnx4FYuddryGCIxbYizqUK1dr4DGKeHonhm/d234Ew3x\n3vIBPoHMOfBec/coP1xAf5o+F+MRMO/sQ3tTGgyOH18lwsHo9SmXCrmOwVQPKrEw\nm+A+5TjXLmenyaBhqXa0vkAZYJhWdROhWC0VTA==\n-----END CERTIFICATE-----\n" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GhePrivUpdateConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - github_enterprise_config { - host_uri = "https://ghe.proctor-staging-test.com" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GhePrivUpdateConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - - github_enterprise_config { - host_uri = "https://ghe.proctor-private-ca.com" - - service_directory_config { - service = "projects/gcb-terraform-creds/locations/%{region}/namespaces/myns/services/serv" - } - - ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIEXTCCA0WgAwIBAgIUANaBCc9j/xdKJHU0sgmv6yE2WCIwDQYJKoZIhvcNAQEL\nBQAwLDEUMBIGA1UEChMLUHJvY3RvciBFbmcxFDASBgNVBAMTC1Byb2N0b3ItZW5n\nMB4XDTIxMDcxNTIwMDcwMloXDTIyMDcxNTIwMDcwMVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBAMVel7I88DkhwW445BNPBZvJNTV1AreHdz4um4U1\nop2+4L7JeNrUs5SRc0fzeOyOmA9ZzTDu9hBC7zj/sVNUy6cIQGCj32sr5SCAEIat\nnFZlzmVqJPT4J5NAaE37KO5347myTJEBrvpq8az4CtvX0yUzPK0gbUmaSaztVi4o\ndbJLKyv575xCLC/Hu6fIHBDH19eG1Ath9VpuAOkttRRoxu2VqijJZrGqaS+0o+OX\nrLi5HMtZbZjgQB4mc1g3ZDKX/gynxr+CDNaqNOqxuog33Tl5OcOk9DrR3MInaE7F\nyQFuH9mzF64AqOoTf7Tr/eAIz5XVt8K51nk+fSybEfKVwtMCAwEAAaOCAaEwggGd\nMA4GA1UdDwEB/wQEAwIFoDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQU/9dYyqMz\nv9rOMwPZcoIRMDAQCjAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDCB\njQYIKwYBBQUHAQEEgYAwfjB8BggrBgEFBQcwAoZwaHR0cDovL3ByaXZhdGVjYS1j\nb250ZW50LTYxYWEyYzA5LTAwMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9y\nYWdlLmdvb2dsZWFwaXMuY29tLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NhLmNydDAo\nBgNVHREBAf8EHjAcghpnaGUucHJvY3Rvci1wcml2YXRlLWNhLmNvbTCBggYDVR0f\nBHsweTB3oHWgc4ZxaHR0cDovL3ByaXZhdGVjYS1jb250ZW50LTYxYWEyYzA5LTAw\nMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9yYWdlLmdvb2dsZWFwaXMuY29t\nLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NybC5jcmwwDQYJKoZIhvcNAQELBQADggEB\nABo6BQLEZZ+YNiDuv2sRvcxSopQQb7fZjqIA9XOA35pNSKay2SncODnNvfsdRnOp\ncoy25sQSIzWyJ9zWl8DZ6evoOu5csZ2PoFqx5LsIq37w+ZcwD6DM8Zm7JqASxmxx\nGqTF0nHC4Aw8q8aJBeRD3PsSkfN5Q3DP3nTDnLyd0l+yPIkHUbZMoiFHX3BkhCng\nG96mYy/y3t16ghfV9lZkXpD/JK5aiN0bTHCDRc69owgfYiAcAqzBJ9gfZ90MBgzv\ngTTQel5dHg49SYXfnUpTy0HdQLEcoggOF8Q8V+xKdKa6eVbrvjJrkEJmvIQI5iCR\nhNvKR25mx8JUopqEXmONmqU=\n-----END CERTIFICATE-----\n\n-----BEGIN CERTIFICATE-----\nMIIDSDCCAjCgAwIBAgITMwWN+62nLcgyLa7p+jD1K90g6TANBgkqhkiG9w0BAQsF\nADAsMRQwEgYDVQQKEwtQcm9jdG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcw\nHhcNMjEwNzEyMTM1OTQ0WhcNMzEwNzEwMTM1OTQzWjAsMRQwEgYDVQQKEwtQcm9j\ndG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcwggEiMA0GCSqGSIb3DQEBAQUA\nA4IBDwAwggEKAoIBAQCYqJP5Qt90jIbld2dtuUV/zIkBFsTe4fapJfhBji03xBpN\nO1Yxj/jPSZ67Kdeoy0lEwvc2hL5FQGhIjLMR0mzOyN4fk/DZiA/4tAVi7hJyqpUC\n71JSwp7MwXL1b26CSE1MhcoCqA/E4iZxfJfF/ef4lhmC24UEmu8FEbldoy+6OysB\nRu7dGDwicW5F9h7eSkpGAsCRdJHh65iUx/IH0C4Ux2UZRDZdj6wVbuVu9tb938xF\nyRuVClONoLSn/lwdzeV7hQmBSm8qmfgbNPbYRaNLz3hOpsT+27aDQp2/pxue8hFJ\nd7We3+Lr5O4IL45PBwhVEAiFZqde6d4qViNEB2qTAgMBAAGjYzBhMA4GA1UdDwEB\n/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTkQGTiCkLCmv/Awxdz\n5TAVRmyFfDAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDANBgkqhkiG\n9w0BAQsFAAOCAQEAfy5BJsWdx0oWWi7SFg9MbryWjBVPJl93UqACgG0Cgh813O/x\nlDZQhGO/ZFVhHz/WgooE/HgVNoVJTubKLLzz+zCkOB0wa3GMqJDyFjhFmUtd/3VM\nZh0ZQ+JWYsAiZW4VITj5xEn/d/B3xCFWGC1vhvhptEJ8Fo2cE1yM2pzk08NqFWoY\n4FaH0sbxWgyCKwTmtcYDbnx4FYuddryGCIxbYizqUK1dr4DGKeHonhm/d234Ew3x\n3vIBPoHMOfBec/coP1xAf5o+F+MRMO/sQ3tTGgyOH18lwsHo9SmXCrmOwVQPKrEw\nm+A+5TjXLmenyaBhqXa0vkAZYJhWdROhWC0VTA==\n-----END CERTIFICATE-----\n" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GithubConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - disabled = true +resource "google_cloudbuildv2_connection" "my-connection" { + location = "us-central1" + name = "tf-test-tf-test-connection%{random_suffix}" github_config { app_installation_id = 0 @@ -487,277 +68,14 @@ resource "google_cloudbuildv2_connection" "primary" { oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/1" } } - - project = "%{project_name}" - - annotations = { - somekey = "somevalue" - } -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GithubConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "%{region}" - name = "tf-test-connection%{random_suffix}" - disabled = false - - github_config { - app_installation_id = 31300675 - - authorizer_credential { - oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/latest" - } - } - - project = "%{project_name}" - - annotations = { - otherkey = "othervalue" - - somekey = "somevalue" - } -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GitlabConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - gitlab_config { - authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gitlab-api-pat/versions/latest" - } - - read_authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gitlab-read-pat/versions/latest" - } - - webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GleConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - 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" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GleConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - gitlab_config { - authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-old-api-token/versions/2" - } - - read_authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-old-read-token/versions/3" - } - - webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" - host_uri = "https://gle-old.gcb-test.com" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GleOldConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - gitlab_config { - authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-old-api-token/versions/2" - } - - read_authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-old-read-token/versions/3" - } - - webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" - host_uri = "https://gle-old.gcb-test.com" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GleOldConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - 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" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GlePrivConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - gitlab_config { - authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-private-api/versions/1" - } - - read_authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-private-read-token/versions/1" - } - - webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" - host_uri = "https://gle-us.gle-us-private.com" - - service_directory_config { - service = "projects/407304063574/locations/us-west1/namespaces/private-conn/services/gitlab-private" - } - - ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIDcTCCAlmgAwIBAgIUbxJ3jxaRf5IPcUiQWRPRqpLL4s4wDQYJKoZIhvcNAQEL\nBQAwTjELMAkGA1UEBhMCVVMxGzAZBgNVBAoMEkdvb2dsZSBDbG91ZCBCdWlsZDEi\nMCAGA1UEAwwZZ2xlLXVzLmdsZS11cy1wcml2YXRlLmNvbTAeFw0yMzEwMjAxNjQ3\nNDJaFw0yNDEwMTkxNjQ3NDJaME4xCzAJBgNVBAYTAlVTMRswGQYDVQQKDBJHb29n\nbGUgQ2xvdWQgQnVpbGQxIjAgBgNVBAMMGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRE84wKcuzc+beQ323\nIsNVVOF1+WZ975LvXpIt8Mw1bcYeYUcvgBXSXAByHGMtef8OBb9BUvLOVZdT3Xow\nCUbhCiK3zQy29pCn0rsneIvzGUXQgQRXK/Zap1N/hif4E7CIgjuvCN0Mn6BfDV/H\nXFm6EV3YUJrRPBr1rZik7doaYYwaJshCSTBtZxXZdvsG/OBuAXbJ9GB0B62EiTBz\n5g6yRdATut+PbgfzaWlPsgL3TTH+HPNCMO+ULnFupfZwRCtV+dJng76QYGs8fmFo\ntiWeElcsU8W7aqmjOkKRWcFsHpxPNXp8GG+jsZrVAnMOR3QeRLvowysSQD99IrGH\nAhwlAgMBAAGjRzBFMCQGA1UdEQQdMBuCGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wHQYDVR0OBBYEFKCIp5BruT4fpeDFQ2bKgdUvpfbWMA0GCSqGSIb3DQEBCwUA\nA4IBAQAQ4pUQmmd7eNIu9MQGna9lHYRFL0/G3mrK6Dcfm2As9qdcRw3dph8/iute\nxKDdBsnt6jDHrsjN0Na7Eq0040oBJrxG/NtqGX0zHNdpAT61bQ6j9reAT+KOrHys\nDJXH2lPuFW183AU7mmvcbXTEwkKex1i+DNoEdGYUbBfnWWeuhGzFog+/f9mtjoHL\nplcmx0VWHBQ5KO9Aq4OR/86DSg5QRPk76W9k3cM2ShXMm3TmTBZ+taJFfjZo5jP+\n7PLt2z9grSvFSXh2jnMyAs2yP4c+WezOXZLijqROr378AGBaksQK0CP+CYjZRpn1\nvndr1njLbvSjIypwKgZROb4P6XVa\n-----END CERTIFICATE-----\n" - } - - project = "%{project_name}" - annotations = {} } - - -`, context) -} - -func testAccCloudbuildv2Connection_GlePrivUpdateConnection(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - 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" - } - - project = "%{project_name}" - annotations = {} -} - - -`, context) -} - -func testAccCloudbuildv2Connection_GlePrivUpdateConnectionUpdate0(context map[string]interface{}) string { - return acctest.Nprintf(` -resource "google_cloudbuildv2_connection" "primary" { - location = "us-west1" - name = "tf-test-connection%{random_suffix}" - - gitlab_config { - authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-private-api/versions/1" - } - - read_authorizer_credential { - user_token_secret_version = "projects/407304063574/secrets/gle-private-read-token/versions/1" - } - - webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" - host_uri = "https://gle-us.gle-us-private.com" - - service_directory_config { - service = "projects/407304063574/locations/us-west1/namespaces/private-conn/services/gitlab-private" - } - - ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIDcTCCAlmgAwIBAgIUbxJ3jxaRf5IPcUiQWRPRqpLL4s4wDQYJKoZIhvcNAQEL\nBQAwTjELMAkGA1UEBhMCVVMxGzAZBgNVBAoMEkdvb2dsZSBDbG91ZCBCdWlsZDEi\nMCAGA1UEAwwZZ2xlLXVzLmdsZS11cy1wcml2YXRlLmNvbTAeFw0yMzEwMjAxNjQ3\nNDJaFw0yNDEwMTkxNjQ3NDJaME4xCzAJBgNVBAYTAlVTMRswGQYDVQQKDBJHb29n\nbGUgQ2xvdWQgQnVpbGQxIjAgBgNVBAMMGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRE84wKcuzc+beQ323\nIsNVVOF1+WZ975LvXpIt8Mw1bcYeYUcvgBXSXAByHGMtef8OBb9BUvLOVZdT3Xow\nCUbhCiK3zQy29pCn0rsneIvzGUXQgQRXK/Zap1N/hif4E7CIgjuvCN0Mn6BfDV/H\nXFm6EV3YUJrRPBr1rZik7doaYYwaJshCSTBtZxXZdvsG/OBuAXbJ9GB0B62EiTBz\n5g6yRdATut+PbgfzaWlPsgL3TTH+HPNCMO+ULnFupfZwRCtV+dJng76QYGs8fmFo\ntiWeElcsU8W7aqmjOkKRWcFsHpxPNXp8GG+jsZrVAnMOR3QeRLvowysSQD99IrGH\nAhwlAgMBAAGjRzBFMCQGA1UdEQQdMBuCGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wHQYDVR0OBBYEFKCIp5BruT4fpeDFQ2bKgdUvpfbWMA0GCSqGSIb3DQEBCwUA\nA4IBAQAQ4pUQmmd7eNIu9MQGna9lHYRFL0/G3mrK6Dcfm2As9qdcRw3dph8/iute\nxKDdBsnt6jDHrsjN0Na7Eq0040oBJrxG/NtqGX0zHNdpAT61bQ6j9reAT+KOrHys\nDJXH2lPuFW183AU7mmvcbXTEwkKex1i+DNoEdGYUbBfnWWeuhGzFog+/f9mtjoHL\nplcmx0VWHBQ5KO9Aq4OR/86DSg5QRPk76W9k3cM2ShXMm3TmTBZ+taJFfjZo5jP+\n7PLt2z9grSvFSXh2jnMyAs2yP4c+WezOXZLijqROr378AGBaksQK0CP+CYjZRpn1\nvndr1njLbvSjIypwKgZROb4P6XVa\n-----END CERTIFICATE-----\n" - } - - project = "%{project_name}" - annotations = {} -} - - `, context) } func testAccCheckCloudbuildv2ConnectionDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { - if rs.Type != "rs.google_cloudbuildv2_connection" { + if rs.Type != "google_cloudbuildv2_connection" { continue } if strings.HasPrefix(name, "data.") { @@ -766,28 +84,29 @@ func testAccCheckCloudbuildv2ConnectionDestroyProducer(t *testing.T) func(s *ter config := acctest.GoogleProviderConfig(t) + url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{Cloudbuildv2BasePath}}projects/{{project}}/locations/{{location}}/connections/{{name}}") + if err != nil { + return err + } + billingProject := "" + if config.BillingProject != "" { billingProject = config.BillingProject } - obj := &cloudbuildv2.Connection{ - Location: dcl.String(rs.Primary.Attributes["location"]), - Name: dcl.String(rs.Primary.Attributes["name"]), - Disabled: dcl.Bool(rs.Primary.Attributes["disabled"] == "true"), - Project: dcl.StringOrNil(rs.Primary.Attributes["project"]), - CreateTime: dcl.StringOrNil(rs.Primary.Attributes["create_time"]), - Etag: dcl.StringOrNil(rs.Primary.Attributes["etag"]), - Reconciling: dcl.Bool(rs.Primary.Attributes["reconciling"] == "true"), - UpdateTime: dcl.StringOrNil(rs.Primary.Attributes["update_time"]), - } - - client := transport_tpg.NewDCLCloudbuildv2Client(config, config.UserAgent, billingProject, 0) - _, err := client.GetConnection(context.Background(), obj) + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: config.UserAgent, + }) if err == nil { - return fmt.Errorf("google_cloudbuildv2_connection still exists %v", obj) + return fmt.Errorf("Cloudbuildv2Connection still exists at %s", url) } } + return nil } } diff --git a/google/services/cloudbuildv2/resource_cloudbuildv2_connection_sweeper.go b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_sweeper.go index 6694cbaf9f1..56a9ee099bb 100644 --- a/google/services/cloudbuildv2/resource_cloudbuildv2_connection_sweeper.go +++ b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_sweeper.go @@ -3,16 +3,15 @@ // ---------------------------------------------------------------------------- // -// *** AUTO GENERATED CODE *** Type: DCL *** +// *** AUTO GENERATED CODE *** Type: MMv1 *** // // ---------------------------------------------------------------------------- // -// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules) -// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library). -// Changes will need to be made to the DCL or Magic Modules instead of here. +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. // -// We are not currently able to accept contributions to this file. If changes -// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. // // ---------------------------------------------------------------------------- @@ -21,11 +20,12 @@ package cloudbuildv2 import ( "context" "log" + "strings" "testing" - cloudbuildv2 "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuildv2" "github.com/hashicorp/terraform-provider-google/google/envvar" "github.com/hashicorp/terraform-provider-google/google/sweeper" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" ) @@ -33,8 +33,10 @@ func init() { sweeper.AddTestSweepers("Cloudbuildv2Connection", testSweepCloudbuildv2Connection) } +// At the time of writing, the CI only passes us-central1 as the region func testSweepCloudbuildv2Connection(region string) error { - log.Print("[INFO][SWEEPER_LOG] Starting sweeper for Cloudbuildv2Connection") + resourceName := "Cloudbuildv2Connection" + log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) config, err := sweeper.SharedConfigForRegion(region) if err != nil { @@ -51,23 +53,87 @@ func testSweepCloudbuildv2Connection(region string) error { t := &testing.T{} billingId := envvar.GetTestBillingAccountFromEnv(t) - // Setup variables to be used for Delete arguments. - d := map[string]string{ - "project": config.Project, - "region": region, - "location": region, - "zone": "-", - "billing_account": billingId, + // Setup variables to replace in list template + d := &tpgresource.ResourceDataMock{ + FieldsInSchema: map[string]interface{}{ + "project": config.Project, + "region": region, + "location": region, + "zone": "-", + "billing_account": billingId, + }, } - client := transport_tpg.NewDCLCloudbuildv2Client(config, config.UserAgent, "", 0) - err = client.DeleteAllConnection(context.Background(), d["project"], d["location"], isDeletableCloudbuildv2Connection) + listTemplate := strings.Split("https://cloudbuild.googleapis.com/v2/projects/{{project}}/locations/{{location}}/connections", "?")[0] + listUrl, err := tpgresource.ReplaceVars(d, config, listTemplate) if err != nil { - return err + log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) + return nil } - return nil -} -func isDeletableCloudbuildv2Connection(r *cloudbuildv2.Connection) bool { - return sweeper.IsSweepableTestResource(*r.Name) + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: config.Project, + RawURL: listUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) + return nil + } + + resourceList, ok := res["connections"] + if !ok { + log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") + return nil + } + + rl := resourceList.([]interface{}) + + log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) + // Keep count of items that aren't sweepable for logging. + nonPrefixCount := 0 + for _, ri := range rl { + obj := ri.(map[string]interface{}) + if obj["name"] == nil { + log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) + return nil + } + + name := tpgresource.GetResourceNameFromSelfLink(obj["name"].(string)) + // Skip resources that shouldn't be sweeped + if !sweeper.IsSweepableTestResource(name) { + nonPrefixCount++ + continue + } + + deleteTemplate := "https://cloudbuild.googleapis.com/v2/projects/{{project}}/locations/{{location}}/connections/{{name}}" + deleteUrl, err := tpgresource.ReplaceVars(d, config, deleteTemplate) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) + return nil + } + deleteUrl = deleteUrl + name + + // Don't wait on operations as we may have a lot to delete + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "DELETE", + Project: config.Project, + RawURL: deleteUrl, + UserAgent: config.UserAgent, + }) + if err != nil { + log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) + } else { + log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) + } + } + + if nonPrefixCount > 0 { + log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) + } + + return nil } diff --git a/google/services/cloudbuildv2/resource_cloudbuildv2_connection_test.go b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_test.go new file mode 100644 index 00000000000..9aa33e43a65 --- /dev/null +++ b/google/services/cloudbuildv2/resource_cloudbuildv2_connection_test.go @@ -0,0 +1,681 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package cloudbuildv2_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" +) + +func TestAccCloudbuildv2Connection_GheCompleteConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GheCompleteConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations", "name"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GheConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GheConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GheConnectionUpdate0(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GhePrivConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GhePrivConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GhePrivUpdateConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GhePrivUpdateConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GhePrivUpdateConnectionUpdate0(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GithubConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GithubConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GithubConnectionUpdate0(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GitlabConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GitlabConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GleConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GleConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GleConnectionUpdate0(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GleOldConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GleOldConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GleOldConnectionUpdate0(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GlePrivConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GlePrivConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func TestAccCloudbuildv2Connection_GlePrivUpdateConnection(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_name": envvar.GetTestProjectFromEnv(), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckCloudbuildv2ConnectionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccCloudbuildv2Connection_GleConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + { + Config: testAccCloudbuildv2Connection_GlePrivConnection(context), + }, + { + ResourceName: "google_cloudbuildv2_connection.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"annotations"}, + }, + }, + }) +} + +func testAccCloudbuildv2Connection_GheCompleteConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "projects/%{project_name}/locations/%{region}/connections/tf-test-connection%{random_suffix}" + + 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" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GheConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + + github_enterprise_config { + host_uri = "https://ghe.proctor-staging-test.com" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GheConnectionUpdate0(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + + 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" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GhePrivConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + + github_enterprise_config { + host_uri = "https://ghe.proctor-private-ca.com" + + service_directory_config { + service = "projects/gcb-terraform-creds/locations/%{region}/namespaces/myns/services/serv" + } + + ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIEXTCCA0WgAwIBAgIUANaBCc9j/xdKJHU0sgmv6yE2WCIwDQYJKoZIhvcNAQEL\nBQAwLDEUMBIGA1UEChMLUHJvY3RvciBFbmcxFDASBgNVBAMTC1Byb2N0b3ItZW5n\nMB4XDTIxMDcxNTIwMDcwMloXDTIyMDcxNTIwMDcwMVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBAMVel7I88DkhwW445BNPBZvJNTV1AreHdz4um4U1\nop2+4L7JeNrUs5SRc0fzeOyOmA9ZzTDu9hBC7zj/sVNUy6cIQGCj32sr5SCAEIat\nnFZlzmVqJPT4J5NAaE37KO5347myTJEBrvpq8az4CtvX0yUzPK0gbUmaSaztVi4o\ndbJLKyv575xCLC/Hu6fIHBDH19eG1Ath9VpuAOkttRRoxu2VqijJZrGqaS+0o+OX\nrLi5HMtZbZjgQB4mc1g3ZDKX/gynxr+CDNaqNOqxuog33Tl5OcOk9DrR3MInaE7F\nyQFuH9mzF64AqOoTf7Tr/eAIz5XVt8K51nk+fSybEfKVwtMCAwEAAaOCAaEwggGd\nMA4GA1UdDwEB/wQEAwIFoDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQU/9dYyqMz\nv9rOMwPZcoIRMDAQCjAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDCB\njQYIKwYBBQUHAQEEgYAwfjB8BggrBgEFBQcwAoZwaHR0cDovL3ByaXZhdGVjYS1j\nb250ZW50LTYxYWEyYzA5LTAwMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9y\nYWdlLmdvb2dsZWFwaXMuY29tLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NhLmNydDAo\nBgNVHREBAf8EHjAcghpnaGUucHJvY3Rvci1wcml2YXRlLWNhLmNvbTCBggYDVR0f\nBHsweTB3oHWgc4ZxaHR0cDovL3ByaXZhdGVjYS1jb250ZW50LTYxYWEyYzA5LTAw\nMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9yYWdlLmdvb2dsZWFwaXMuY29t\nLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NybC5jcmwwDQYJKoZIhvcNAQELBQADggEB\nABo6BQLEZZ+YNiDuv2sRvcxSopQQb7fZjqIA9XOA35pNSKay2SncODnNvfsdRnOp\ncoy25sQSIzWyJ9zWl8DZ6evoOu5csZ2PoFqx5LsIq37w+ZcwD6DM8Zm7JqASxmxx\nGqTF0nHC4Aw8q8aJBeRD3PsSkfN5Q3DP3nTDnLyd0l+yPIkHUbZMoiFHX3BkhCng\nG96mYy/y3t16ghfV9lZkXpD/JK5aiN0bTHCDRc69owgfYiAcAqzBJ9gfZ90MBgzv\ngTTQel5dHg49SYXfnUpTy0HdQLEcoggOF8Q8V+xKdKa6eVbrvjJrkEJmvIQI5iCR\nhNvKR25mx8JUopqEXmONmqU=\n-----END CERTIFICATE-----\n\n-----BEGIN CERTIFICATE-----\nMIIDSDCCAjCgAwIBAgITMwWN+62nLcgyLa7p+jD1K90g6TANBgkqhkiG9w0BAQsF\nADAsMRQwEgYDVQQKEwtQcm9jdG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcw\nHhcNMjEwNzEyMTM1OTQ0WhcNMzEwNzEwMTM1OTQzWjAsMRQwEgYDVQQKEwtQcm9j\ndG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcwggEiMA0GCSqGSIb3DQEBAQUA\nA4IBDwAwggEKAoIBAQCYqJP5Qt90jIbld2dtuUV/zIkBFsTe4fapJfhBji03xBpN\nO1Yxj/jPSZ67Kdeoy0lEwvc2hL5FQGhIjLMR0mzOyN4fk/DZiA/4tAVi7hJyqpUC\n71JSwp7MwXL1b26CSE1MhcoCqA/E4iZxfJfF/ef4lhmC24UEmu8FEbldoy+6OysB\nRu7dGDwicW5F9h7eSkpGAsCRdJHh65iUx/IH0C4Ux2UZRDZdj6wVbuVu9tb938xF\nyRuVClONoLSn/lwdzeV7hQmBSm8qmfgbNPbYRaNLz3hOpsT+27aDQp2/pxue8hFJ\nd7We3+Lr5O4IL45PBwhVEAiFZqde6d4qViNEB2qTAgMBAAGjYzBhMA4GA1UdDwEB\n/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTkQGTiCkLCmv/Awxdz\n5TAVRmyFfDAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDANBgkqhkiG\n9w0BAQsFAAOCAQEAfy5BJsWdx0oWWi7SFg9MbryWjBVPJl93UqACgG0Cgh813O/x\nlDZQhGO/ZFVhHz/WgooE/HgVNoVJTubKLLzz+zCkOB0wa3GMqJDyFjhFmUtd/3VM\nZh0ZQ+JWYsAiZW4VITj5xEn/d/B3xCFWGC1vhvhptEJ8Fo2cE1yM2pzk08NqFWoY\n4FaH0sbxWgyCKwTmtcYDbnx4FYuddryGCIxbYizqUK1dr4DGKeHonhm/d234Ew3x\n3vIBPoHMOfBec/coP1xAf5o+F+MRMO/sQ3tTGgyOH18lwsHo9SmXCrmOwVQPKrEw\nm+A+5TjXLmenyaBhqXa0vkAZYJhWdROhWC0VTA==\n-----END CERTIFICATE-----\n" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GhePrivUpdateConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + + github_enterprise_config { + host_uri = "https://ghe.proctor-staging-test.com" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GhePrivUpdateConnectionUpdate0(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + + github_enterprise_config { + host_uri = "https://ghe.proctor-private-ca.com" + + service_directory_config { + service = "projects/gcb-terraform-creds/locations/%{region}/namespaces/myns/services/serv" + } + + ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIEXTCCA0WgAwIBAgIUANaBCc9j/xdKJHU0sgmv6yE2WCIwDQYJKoZIhvcNAQEL\nBQAwLDEUMBIGA1UEChMLUHJvY3RvciBFbmcxFDASBgNVBAMTC1Byb2N0b3ItZW5n\nMB4XDTIxMDcxNTIwMDcwMloXDTIyMDcxNTIwMDcwMVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBAMVel7I88DkhwW445BNPBZvJNTV1AreHdz4um4U1\nop2+4L7JeNrUs5SRc0fzeOyOmA9ZzTDu9hBC7zj/sVNUy6cIQGCj32sr5SCAEIat\nnFZlzmVqJPT4J5NAaE37KO5347myTJEBrvpq8az4CtvX0yUzPK0gbUmaSaztVi4o\ndbJLKyv575xCLC/Hu6fIHBDH19eG1Ath9VpuAOkttRRoxu2VqijJZrGqaS+0o+OX\nrLi5HMtZbZjgQB4mc1g3ZDKX/gynxr+CDNaqNOqxuog33Tl5OcOk9DrR3MInaE7F\nyQFuH9mzF64AqOoTf7Tr/eAIz5XVt8K51nk+fSybEfKVwtMCAwEAAaOCAaEwggGd\nMA4GA1UdDwEB/wQEAwIFoDAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBQU/9dYyqMz\nv9rOMwPZcoIRMDAQCjAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDCB\njQYIKwYBBQUHAQEEgYAwfjB8BggrBgEFBQcwAoZwaHR0cDovL3ByaXZhdGVjYS1j\nb250ZW50LTYxYWEyYzA5LTAwMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9y\nYWdlLmdvb2dsZWFwaXMuY29tLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NhLmNydDAo\nBgNVHREBAf8EHjAcghpnaGUucHJvY3Rvci1wcml2YXRlLWNhLmNvbTCBggYDVR0f\nBHsweTB3oHWgc4ZxaHR0cDovL3ByaXZhdGVjYS1jb250ZW50LTYxYWEyYzA5LTAw\nMDAtMjJjMi05ZjYyLWQ0ZjU0N2Y4MDIwMC5zdG9yYWdlLmdvb2dsZWFwaXMuY29t\nLzQxNGU4ZTJjZjU2ZWEyYzQxNmM0L2NybC5jcmwwDQYJKoZIhvcNAQELBQADggEB\nABo6BQLEZZ+YNiDuv2sRvcxSopQQb7fZjqIA9XOA35pNSKay2SncODnNvfsdRnOp\ncoy25sQSIzWyJ9zWl8DZ6evoOu5csZ2PoFqx5LsIq37w+ZcwD6DM8Zm7JqASxmxx\nGqTF0nHC4Aw8q8aJBeRD3PsSkfN5Q3DP3nTDnLyd0l+yPIkHUbZMoiFHX3BkhCng\nG96mYy/y3t16ghfV9lZkXpD/JK5aiN0bTHCDRc69owgfYiAcAqzBJ9gfZ90MBgzv\ngTTQel5dHg49SYXfnUpTy0HdQLEcoggOF8Q8V+xKdKa6eVbrvjJrkEJmvIQI5iCR\nhNvKR25mx8JUopqEXmONmqU=\n-----END CERTIFICATE-----\n\n-----BEGIN CERTIFICATE-----\nMIIDSDCCAjCgAwIBAgITMwWN+62nLcgyLa7p+jD1K90g6TANBgkqhkiG9w0BAQsF\nADAsMRQwEgYDVQQKEwtQcm9jdG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcw\nHhcNMjEwNzEyMTM1OTQ0WhcNMzEwNzEwMTM1OTQzWjAsMRQwEgYDVQQKEwtQcm9j\ndG9yIEVuZzEUMBIGA1UEAxMLUHJvY3Rvci1lbmcwggEiMA0GCSqGSIb3DQEBAQUA\nA4IBDwAwggEKAoIBAQCYqJP5Qt90jIbld2dtuUV/zIkBFsTe4fapJfhBji03xBpN\nO1Yxj/jPSZ67Kdeoy0lEwvc2hL5FQGhIjLMR0mzOyN4fk/DZiA/4tAVi7hJyqpUC\n71JSwp7MwXL1b26CSE1MhcoCqA/E4iZxfJfF/ef4lhmC24UEmu8FEbldoy+6OysB\nRu7dGDwicW5F9h7eSkpGAsCRdJHh65iUx/IH0C4Ux2UZRDZdj6wVbuVu9tb938xF\nyRuVClONoLSn/lwdzeV7hQmBSm8qmfgbNPbYRaNLz3hOpsT+27aDQp2/pxue8hFJ\nd7We3+Lr5O4IL45PBwhVEAiFZqde6d4qViNEB2qTAgMBAAGjYzBhMA4GA1UdDwEB\n/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTkQGTiCkLCmv/Awxdz\n5TAVRmyFfDAfBgNVHSMEGDAWgBTkQGTiCkLCmv/Awxdz5TAVRmyFfDANBgkqhkiG\n9w0BAQsFAAOCAQEAfy5BJsWdx0oWWi7SFg9MbryWjBVPJl93UqACgG0Cgh813O/x\nlDZQhGO/ZFVhHz/WgooE/HgVNoVJTubKLLzz+zCkOB0wa3GMqJDyFjhFmUtd/3VM\nZh0ZQ+JWYsAiZW4VITj5xEn/d/B3xCFWGC1vhvhptEJ8Fo2cE1yM2pzk08NqFWoY\n4FaH0sbxWgyCKwTmtcYDbnx4FYuddryGCIxbYizqUK1dr4DGKeHonhm/d234Ew3x\n3vIBPoHMOfBec/coP1xAf5o+F+MRMO/sQ3tTGgyOH18lwsHo9SmXCrmOwVQPKrEw\nm+A+5TjXLmenyaBhqXa0vkAZYJhWdROhWC0VTA==\n-----END CERTIFICATE-----\n" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GithubConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + disabled = true + + github_config { + app_installation_id = 0 + + authorizer_credential { + oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/1" + } + } + + project = "%{project_name}" + + annotations = { + somekey = "somevalue" + } +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GithubConnectionUpdate0(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "%{region}" + name = "tf-test-connection%{random_suffix}" + disabled = false + + github_config { + app_installation_id = 31300675 + + authorizer_credential { + oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/latest" + } + } + + project = "%{project_name}" + + annotations = { + otherkey = "othervalue" + + somekey = "somevalue" + } +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GitlabConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + gitlab_config { + authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gitlab-api-pat/versions/latest" + } + + read_authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gitlab-read-pat/versions/latest" + } + + webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GleConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + 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" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GleConnectionUpdate0(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + gitlab_config { + authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-old-api-token/versions/2" + } + + read_authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-old-read-token/versions/3" + } + + webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" + host_uri = "https://gle-old.gcb-test.com" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GleOldConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + gitlab_config { + authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-old-api-token/versions/2" + } + + read_authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-old-read-token/versions/3" + } + + webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" + host_uri = "https://gle-old.gcb-test.com" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GleOldConnectionUpdate0(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + 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" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} + +func testAccCloudbuildv2Connection_GlePrivConnection(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_cloudbuildv2_connection" "primary" { + location = "us-west1" + name = "tf-test-connection%{random_suffix}" + + gitlab_config { + authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-private-api/versions/1" + } + + read_authorizer_credential { + user_token_secret_version = "projects/407304063574/secrets/gle-private-read-token/versions/1" + } + + webhook_secret_secret_version = "projects/407304063574/secrets/gle-webhook-secret/versions/latest" + host_uri = "https://gle-us.gle-us-private.com" + + service_directory_config { + service = "projects/407304063574/locations/us-west1/namespaces/private-conn/services/gitlab-private" + } + + ssl_ca = "-----BEGIN CERTIFICATE-----\nMIIDcTCCAlmgAwIBAgIUbxJ3jxaRf5IPcUiQWRPRqpLL4s4wDQYJKoZIhvcNAQEL\nBQAwTjELMAkGA1UEBhMCVVMxGzAZBgNVBAoMEkdvb2dsZSBDbG91ZCBCdWlsZDEi\nMCAGA1UEAwwZZ2xlLXVzLmdsZS11cy1wcml2YXRlLmNvbTAeFw0yMzEwMjAxNjQ3\nNDJaFw0yNDEwMTkxNjQ3NDJaME4xCzAJBgNVBAYTAlVTMRswGQYDVQQKDBJHb29n\nbGUgQ2xvdWQgQnVpbGQxIjAgBgNVBAMMGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRE84wKcuzc+beQ323\nIsNVVOF1+WZ975LvXpIt8Mw1bcYeYUcvgBXSXAByHGMtef8OBb9BUvLOVZdT3Xow\nCUbhCiK3zQy29pCn0rsneIvzGUXQgQRXK/Zap1N/hif4E7CIgjuvCN0Mn6BfDV/H\nXFm6EV3YUJrRPBr1rZik7doaYYwaJshCSTBtZxXZdvsG/OBuAXbJ9GB0B62EiTBz\n5g6yRdATut+PbgfzaWlPsgL3TTH+HPNCMO+ULnFupfZwRCtV+dJng76QYGs8fmFo\ntiWeElcsU8W7aqmjOkKRWcFsHpxPNXp8GG+jsZrVAnMOR3QeRLvowysSQD99IrGH\nAhwlAgMBAAGjRzBFMCQGA1UdEQQdMBuCGWdsZS11cy5nbGUtdXMtcHJpdmF0ZS5j\nb20wHQYDVR0OBBYEFKCIp5BruT4fpeDFQ2bKgdUvpfbWMA0GCSqGSIb3DQEBCwUA\nA4IBAQAQ4pUQmmd7eNIu9MQGna9lHYRFL0/G3mrK6Dcfm2As9qdcRw3dph8/iute\nxKDdBsnt6jDHrsjN0Na7Eq0040oBJrxG/NtqGX0zHNdpAT61bQ6j9reAT+KOrHys\nDJXH2lPuFW183AU7mmvcbXTEwkKex1i+DNoEdGYUbBfnWWeuhGzFog+/f9mtjoHL\nplcmx0VWHBQ5KO9Aq4OR/86DSg5QRPk76W9k3cM2ShXMm3TmTBZ+taJFfjZo5jP+\n7PLt2z9grSvFSXh2jnMyAs2yP4c+WezOXZLijqROr378AGBaksQK0CP+CYjZRpn1\nvndr1njLbvSjIypwKgZROb4P6XVa\n-----END CERTIFICATE-----\n" + } + + project = "%{project_name}" + annotations = {} +} + + +`, context) +} diff --git a/google/transport/provider_dcl_client_creation.go b/google/transport/provider_dcl_client_creation.go index f05eda46554..58c8db9a1eb 100644 --- a/google/transport/provider_dcl_client_creation.go +++ b/google/transport/provider_dcl_client_creation.go @@ -28,7 +28,6 @@ import ( assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads" bigqueryreservation "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/bigqueryreservation" cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild" - cloudbuildv2 "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuildv2" clouddeploy "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/clouddeploy" cloudresourcemanager "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudresourcemanager" compute "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/compute" @@ -137,29 +136,6 @@ func NewDCLCloudbuildClient(config *Config, userAgent, billingProject string, ti return cloudbuild.NewClient(dclConfig) } -func NewDCLCloudbuildv2Client(config *Config, userAgent, billingProject string, timeout time.Duration) *cloudbuildv2.Client { - configOptions := []dcl.ConfigOption{ - dcl.WithHTTPClient(config.Client), - dcl.WithUserAgent(userAgent), - dcl.WithLogger(dclLogger{}), - dcl.WithBasePath(config.Cloudbuildv2BasePath), - } - - if timeout != 0 { - configOptions = append(configOptions, dcl.WithTimeout(timeout)) - } - - if config.UserProjectOverride { - configOptions = append(configOptions, dcl.WithUserProjectOverride()) - if billingProject != "" { - configOptions = append(configOptions, dcl.WithBillingProject(billingProject)) - } - } - - dclConfig := dcl.NewConfig(configOptions...) - return cloudbuildv2.NewClient(dclConfig) -} - func NewDCLClouddeployClient(config *Config, userAgent, billingProject string, timeout time.Duration) *clouddeploy.Client { configOptions := []dcl.ConfigOption{ dcl.WithHTTPClient(config.Client), diff --git a/website/docs/d/cloudbuildv2_connection_iam_policy.html.markdown b/website/docs/d/cloudbuildv2_connection_iam_policy.html.markdown index 2e9e8908a6c..9bcbe41268d 100644 --- a/website/docs/d/cloudbuildv2_connection_iam_policy.html.markdown +++ b/website/docs/d/cloudbuildv2_connection_iam_policy.html.markdown @@ -38,6 +38,7 @@ data "google_cloudbuildv2_connection_iam_policy" "policy" { The following arguments are supported: * `name` - (Required) Used to find the parent resource to bind the IAM policy to +* `location` - (Required) The location for the resource Used to find the parent resource to bind the IAM policy to * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used. diff --git a/website/docs/r/cloudbuildv2_connection.html.markdown b/website/docs/r/cloudbuildv2_connection.html.markdown index 426fa3538d3..5ea566a4121 100644 --- a/website/docs/r/cloudbuildv2_connection.html.markdown +++ b/website/docs/r/cloudbuildv2_connection.html.markdown @@ -1,28 +1,58 @@ --- # ---------------------------------------------------------------------------- # -# *** AUTO GENERATED CODE *** Type: DCL *** +# *** AUTO GENERATED CODE *** Type: MMv1 *** # # ---------------------------------------------------------------------------- # -# This file is managed by Magic Modules (https:#github.com/GoogleCloudPlatform/magic-modules) -# and is based on the DCL (https:#github.com/GoogleCloudPlatform/declarative-resource-client-library). -# Changes will need to be made to the DCL or Magic Modules instead of here. +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. # -# We are not currently able to accept contributions to this file. If changes -# are required, please file an issue at https:#github.com/hashicorp/terraform-provider-google/issues/new/choose +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. # # ---------------------------------------------------------------------------- subcategory: "Cloud Build v2" description: |- - The Cloudbuildv2 Connection resource + A connection to a SCM like GitHub, GitHub Enterprise, Bitbucket Data Center or GitLab. --- -# google_cloudbuildv2_connection +# google\_cloudbuildv2\_connection + +A connection to a SCM like GitHub, GitHub Enterprise, Bitbucket Data Center or GitLab. + + +To get more information about Connection, see: + +* [API documentation](https://cloud.google.com/build/docs/api/reference/rest) +* How-to Guides + * [Official Documentation](https://cloud.google.com/build/docs) + + +## Example Usage - Cloudbuildv2 Connection + + +```hcl +resource "google_cloudbuildv2_connection" "my-connection" { + location = "us-central1" + name = "tf-test-connection" + + github_config { + app_installation_id = 0 + + authorizer_credential { + oauth_token_secret_version = "projects/gcb-terraform-creds/secrets/github-pat/versions/1" + } + } +} +``` +## Example Usage - Cloudbuildv2 Connection Ghe -The Cloudbuildv2 Connection resource -## Example Usage - ghe ```hcl resource "google_secret_manager_secret" "private-key-secret" { secret_id = "ghe-pk-secret" @@ -86,10 +116,10 @@ resource "google_cloudbuildv2_connection" "my-connection" { google_secret_manager_secret_iam_policy.policy-whs ] } - ``` -## Example Usage - GitHub Connection -Creates a Connection to github.com +## Example Usage - Cloudbuildv2 Connection Github + + ```hcl resource "google_secret_manager_secret" "github-token-secret" { secret_id = "github-token-secret" @@ -107,7 +137,7 @@ resource "google_secret_manager_secret_version" "github-token-secret-version" { data "google_iam_policy" "p4sa-secretAccessor" { binding { role = "roles/secretmanager.secretAccessor" - // Here, 123456789 is the Google Cloud project number for my-project-name. + // 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"] } } @@ -118,7 +148,7 @@ resource "google_secret_manager_secret_iam_policy" "policy" { } resource "google_cloudbuildv2_connection" "my-connection" { - location = "us-west1" + location = "us-central1" name = "my-connection" github_config { @@ -128,166 +158,178 @@ resource "google_cloudbuildv2_connection" "my-connection" { } } } - ``` ## Argument Reference The following arguments are supported: + +* `name` - + (Required) + Immutable. The resource name of the connection. + * `location` - (Required) The location for the resource - -* `name` - - (Required) - Immutable. The resource name of the connection, in the format `projects/{project}/locations/{location}/connections/{connection_id}`. - -The `authorizer_credential` block supports: - -* `user_token_secret_version` - - (Required) - Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`. - -* `username` - - Output only. The username associated to this token. - -The `read_authorizer_credential` block supports: - -* `user_token_secret_version` - - (Required) - Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`. - -* `username` - - Output only. The username associated to this token. - - - - -* `annotations` - - (Optional) - Allows clients to store small amounts of arbitrary data. -**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration. -Please refer to the field `effective_annotations` for all of the annotations present on the resource. - -* `disabled` - - (Optional) - If disabled is set to true, functionality is disabled for this connection. Repository based API methods and webhooks processing for repositories in this connection will be disabled. - * `github_config` - (Optional) Configuration for connections to github.com. - + Structure is [documented below](#nested_github_config). + * `github_enterprise_config` - (Optional) Configuration for connections to an instance of GitHub Enterprise. - + Structure is [documented below](#nested_github_enterprise_config). + * `gitlab_config` - (Optional) Configuration for connections to gitlab.com or an instance of GitLab Enterprise. - -* `project` - - (Optional) - The project for the resource - + Structure is [documented below](#nested_gitlab_config). +* `disabled` - + (Optional) + If disabled is set to true, functionality is disabled for this connection. Repository based API methods and webhooks processing for repositories in this connection will be disabled. -The `github_config` block supports: - -* `app_installation_id` - +* `annotations` - (Optional) - GitHub App installation id. - + Allows clients to store small amounts of arbitrary data. + **Note**: This field is non-authoritative, and will only manage the annotations present in your configuration. + Please refer to the field `effective_annotations` for all of the annotations present on the resource. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `github_config` block supports: + * `authorizer_credential` - (Optional) OAuth credential of the account that authorized the Cloud Build GitHub App. It is recommended to use a robot account instead of a human user account. The OAuth token must be tied to the Cloud Build GitHub App. - -The `authorizer_credential` block supports: - + Structure is [documented below](#nested_authorizer_credential). + +* `app_installation_id` - + (Optional) + GitHub App installation id. + + +The `authorizer_credential` block supports: + * `oauth_token_secret_version` - (Optional) A SecretManager resource containing the OAuth token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`. - + * `username` - + (Output) Output only. The username associated to this token. - -The `github_enterprise_config` block supports: - + +The `github_enterprise_config` block supports: + +* `host_uri` - + (Required) + Required. The URI of the GitHub Enterprise host this connection is for. + * `app_id` - (Optional) Id of the GitHub App created from the manifest. - -* `app_installation_id` - - (Optional) - ID of the installation of the GitHub App. - + * `app_slug` - (Optional) The URL-friendly name of the GitHub App. - -* `host_uri` - - (Required) - Required. The URI of the GitHub Enterprise host this connection is for. - + * `private_key_secret_version` - (Optional) SecretManager resource containing the private key of the GitHub App, formatted as `projects/*/secrets/*/versions/*`. - + +* `webhook_secret_secret_version` - + (Optional) + SecretManager resource containing the webhook secret of the GitHub App, formatted as `projects/*/secrets/*/versions/*`. + +* `app_installation_id` - + (Optional) + ID of the installation of the GitHub App. + * `service_directory_config` - (Optional) Configuration for using Service Directory to privately connect to a GitHub Enterprise server. This should only be set if the GitHub Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitHub Enterprise server will be made over the public internet. - + Structure is [documented below](#nested_service_directory_config). + * `ssl_ca` - (Optional) SSL certificate to use for requests to GitHub Enterprise. - -* `webhook_secret_secret_version` - - (Optional) - SecretManager resource containing the webhook secret of the GitHub App, formatted as `projects/*/secrets/*/versions/*`. - -The `service_directory_config` block supports: - + + +The `service_directory_config` block supports: + * `service` - (Required) Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}. - -The `gitlab_config` block supports: - -* `authorizer_credential` - - (Required) - Required. A GitLab personal access token with the `api` scope access. - + +The `gitlab_config` block supports: + * `host_uri` - (Optional) The URI of the GitLab Enterprise host this connection is for. If not specified, the default value is https://gitlab.com. - + +* `webhook_secret_secret_version` - + (Required) + Required. Immutable. SecretManager resource containing the webhook secret of a GitLab Enterprise project, formatted as `projects/*/secrets/*/versions/*`. + * `read_authorizer_credential` - (Required) Required. A GitLab personal access token with the minimum `read_api` scope access. - -* `server_version` - - Output only. Version of the GitLab Enterprise server running on the `host_uri`. - + Structure is [documented below](#nested_read_authorizer_credential). + +* `authorizer_credential` - + (Required) + Required. A GitLab personal access token with the `api` scope access. + Structure is [documented below](#nested_authorizer_credential). + * `service_directory_config` - (Optional) Configuration for using Service Directory to privately connect to a GitLab Enterprise server. This should only be set if the GitLab Enterprise server is hosted on-premises and not reachable by public internet. If this field is left empty, calls to the GitLab Enterprise server will be made over the public internet. - + Structure is [documented below](#nested_service_directory_config). + * `ssl_ca` - (Optional) SSL certificate to use for requests to GitLab Enterprise. - -* `webhook_secret_secret_version` - + +* `server_version` - + (Output) + Output only. Version of the GitLab Enterprise server running on the `host_uri`. + + +The `read_authorizer_credential` block supports: + +* `user_token_secret_version` - (Required) - Required. Immutable. SecretManager resource containing the webhook secret of a GitLab Enterprise project, formatted as `projects/*/secrets/*/versions/*`. - -The `service_directory_config` block supports: - + Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`. + +* `username` - + (Output) + Output only. The username associated to this token. + +The `authorizer_credential` block supports: + +* `user_token_secret_version` - + (Required) + Required. A SecretManager resource containing the user token that authorizes the Cloud Build connection. Format: `projects/*/secrets/*/versions/*`. + +* `username` - + (Output) + Output only. The username associated to this token. + +The `service_directory_config` block supports: + * `service` - (Required) Required. The Service Directory service name. Format: projects/{project}/locations/{location}/namespaces/{namespace}/services/{service}. - + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: @@ -296,22 +338,38 @@ In addition to the arguments listed above, the following computed attributes are * `create_time` - Output only. Server assigned timestamp for when the connection was created. - -* `effective_annotations` - - All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services. - -* `etag` - - 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. - + +* `update_time` - + Output only. Server assigned timestamp for when the connection was updated. + * `installation_state` - Output only. Installation state of the Connection. - + Structure is [documented below](#nested_installation_state). + * `reconciling` - Output only. Set to true when the connection is being set up or updated in the background. - -* `update_time` - - Output only. Server assigned timestamp for when the connection was updated. - + +* `etag` - + 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. + +* `effective_annotations` - + All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services. + + +The `installation_state` block contains: + +* `stage` - + (Output) + Output only. Current step of the installation process. + +* `message` - + (Output) + Output only. Message of what the user should do next to continue the installation. Empty string if the installation is already complete. + +* `action_uri` - + (Output) + Output only. Link to follow for next action. Empty string if the installation is already complete. + ## Timeouts This resource provides the following @@ -323,13 +381,16 @@ This resource provides the following ## Import + Connection can be imported using any of these accepted formats: + * `projects/{{project}}/locations/{{location}}/connections/{{name}}` * `{{project}}/{{location}}/{{name}}` * `{{location}}/{{name}}` +* `{{name}}` -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Connection using one of the formats above. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Connection using one of the formats above. For example: ```tf import { @@ -344,7 +405,9 @@ When using the [`terraform import` command](https://developer.hashicorp.com/terr $ terraform import google_cloudbuildv2_connection.default projects/{{project}}/locations/{{location}}/connections/{{name}} $ terraform import google_cloudbuildv2_connection.default {{project}}/{{location}}/{{name}} $ terraform import google_cloudbuildv2_connection.default {{location}}/{{name}} +$ terraform import google_cloudbuildv2_connection.default {{name}} ``` +## User Project Overrides - +This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). diff --git a/website/docs/r/cloudbuildv2_connection_iam.html.markdown b/website/docs/r/cloudbuildv2_connection_iam.html.markdown index d8f54205357..59d709f31f1 100644 --- a/website/docs/r/cloudbuildv2_connection_iam.html.markdown +++ b/website/docs/r/cloudbuildv2_connection_iam.html.markdown @@ -87,6 +87,7 @@ resource "google_cloudbuildv2_connection_iam_member" "member" { The following arguments are supported: * `name` - (Required) Used to find the parent resource to bind the IAM policy to +* `location` - (Required) The location for the resource Used to find the parent resource to bind the IAM policy to * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the project will be parsed from the identifier of the parent resource. If no project is provided in the parent identifier and no project is specified, the provider project is used.