Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync main feature branch provider functions #7150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10291.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
cloud.google.com/go/bigtable v1.19.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.63.0
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.64.0
github.com/apparentlymart/go-cidr v1.1.0
github.com/davecgh/go-spew v1.1.1
github.com/dnaeon/go-vcr v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cloud.google.com/go/longrunning v0.5.5/go.mod h1:WV2LAxD8/rg5Z1cNW6FJ/ZpX4E4VnDn
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.63.0 h1:eSOBYPZVnU2fZul9sAJFGLVCgv6stNVKkmsogKF7UeY=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.63.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.64.0 h1:QA90iKudX8ijAW795f/jVbo0oEo7VoevwxLCNyi2qRc=
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.64.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0=
Expand Down
1 change: 1 addition & 0 deletions google-beta/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
"google_artifact_registry_repository": artifactregistry.DataSourceArtifactRegistryRepository(),
"google_apphub_discovered_workload": apphub.DataSourceApphubDiscoveredWorkload(),
"google_app_engine_default_service_account": appengine.DataSourceGoogleAppEngineDefaultServiceAccount(),
"google_apphub_application": apphub.DataSourceGoogleApphubApplication(),
"google_apphub_discovered_service": apphub.DataSourceApphubDiscoveredService(),
"google_backup_dr_management_server": backupdr.DataSourceGoogleCloudBackupDRService(),
"google_beyondcorp_app_connection": beyondcorp.DataSourceGoogleBeyondcorpAppConnection(),
Expand Down
47 changes: 47 additions & 0 deletions google-beta/services/apphub/data_source_apphub_application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package apphub

import (
"fmt"

"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceGoogleApphubApplication() *schema.Resource {
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceApphubApplication().Schema)
tpgresource.AddRequiredFieldsToSchema(dsSchema, "project")
tpgresource.AddRequiredFieldsToSchema(dsSchema, "application_id")
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location")

return &schema.Resource{
Read: dataSourceGoogleApphubApplicationRead,
Schema: dsSchema,
}
}

func dataSourceGoogleApphubApplicationRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)

id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/applications/{{application_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
err = resourceApphubApplicationRead(d, meta)
if err != nil {
return err
}

if err := tpgresource.SetDataSourceLabels(d); err != nil {
return err
}

if d.Id() == "" {
return fmt.Errorf("%s not found", id)
}
return nil
}
72 changes: 72 additions & 0 deletions google-beta/services/apphub/data_source_apphub_application_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package apphub_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
)

func TestDataSourceApphubApplication_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckApphubApplicationDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testDataSourceApphubApplication_basic(context),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceState("data.google_apphub_application.example_data", "google_apphub_application.example"),
),
},
},
})
}

func testDataSourceApphubApplication_basic(context map[string]interface{}) string {
return acctest.Nprintf(`

data "google_apphub_application" "example_data" {
project = google_apphub_application.example.project
application_id = google_apphub_application.example.application_id
location = google_apphub_application.example.location
}

resource "google_apphub_application" "example" {
location = "us-central1"
application_id = "tf-test-example-application%{random_suffix}"
display_name = "Application Full New%{random_suffix}"
scope {
type = "REGIONAL"
}
attributes {
environment {
type = "STAGING"
}
criticality {
type = "MISSION_CRITICAL"
}
business_owners {
display_name = "Alice%{random_suffix}"
email = "alice@google.com%{random_suffix}"
}
developer_owners {
display_name = "Bob%{random_suffix}"
email = "bob@google.com%{random_suffix}"
}
operator_owners {
display_name = "Charlie%{random_suffix}"
email = "charlie@google.com%{random_suffix}"
}
}
}
`, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withReleaseChannelEnabled(clusterName, "CANARY", networkName, subnetworkName),
ExpectError: regexp.MustCompile(`expected release_channel\.0\.channel to be one of \[UNSPECIFIED RAPID REGULAR STABLE\], got CANARY`),
ExpectError: regexp.MustCompile(`expected release_channel\.0\.channel to be one of \["?UNSPECIFIED"? "?RAPID"? "?REGULAR"? "?STABLE"?\], got CANARY`),
},
},
})
Expand Down Expand Up @@ -3336,7 +3336,7 @@ func TestAccContainerCluster_withInvalidAutoscalingProfile(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAutoscalingProfile(clusterName, "AS_CHEAP_AS_POSSIBLE", networkName, subnetworkName),
ExpectError: regexp.MustCompile(`expected cluster_autoscaling\.0\.autoscaling_profile to be one of \[BALANCED OPTIMIZE_UTILIZATION\], got AS_CHEAP_AS_POSSIBLE`),
ExpectError: regexp.MustCompile(`expected cluster_autoscaling\.0\.autoscaling_profile to be one of \["?BALANCED"? "?OPTIMIZE_UTILIZATION"?\], got AS_CHEAP_AS_POSSIBLE`),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func TestAccContainerNodePool_withInvalidKubeletCpuManagerPolicy(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, true, 1024),
ExpectError: regexp.MustCompile(`.*to be one of \[static none \].*`),
ExpectError: regexp.MustCompile(`.*to be one of \["?static"? "?none"? "?"?\].*`),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func TestAccFirebaseAppCheckServiceConfig_firebaseAppCheckServiceConfigUpdate(t
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckFirebaseAppCheckServiceConfigDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
"time": {},
},
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -86,22 +85,26 @@ resource "google_project_service" "database" {
project = google_project.default.project_id
service = "firebasedatabase.googleapis.com"
disable_on_destroy = false
depends_on = [
google_project_service.firebase,
]
}

resource "google_project_service" "appcheck" {
provider = google-beta
project = google_project.default.project_id
service = "firebaseappcheck.googleapis.com"
disable_on_destroy = false
depends_on = [
google_project_service.database,
]
}

resource "google_firebase_project" "default" {
provider = google-beta
project = google_project.default.project_id

depends_on = [
google_project_service.firebase,
google_project_service.database,
google_project_service.appcheck,
]
}
Expand Down
51 changes: 47 additions & 4 deletions google-beta/services/integrations/resource_integrations_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,54 @@ func resourceIntegrationsClientRead(d *schema.ResourceData, meta interface{}) er
}

func resourceIntegrationsClientDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[WARNING] Integrations Client resources"+
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+
" state, but will still be present on Google Cloud.", d.Id())
d.SetId("")
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}

billingProject := ""

project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Client: %s", err)
}
billingProject = project

lockName, err := tpgresource.ReplaceVars(d, config, "Client/{{location}}")
if err != nil {
return err
}
transport_tpg.MutexStore.Lock(lockName)
defer transport_tpg.MutexStore.Unlock(lockName)

url, err := tpgresource.ReplaceVars(d, config, "{{IntegrationsBasePath}}projects/{{project}}/locations/{{location}}/clients:deprovision")
if err != nil {
return err
}

var obj map[string]interface{}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}

log.Printf("[DEBUG] Deleting Client %q", d.Id())
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutDelete),
})
if err != nil {
return transport_tpg.HandleNotFoundError(err, d, "Client")
}

log.Printf("[DEBUG] Finished deleting Client %q: %#v", d.Id(), res)
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
package integrations_test

import (
"fmt"
"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-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func TestAccIntegrationsClient_integrationsClientBasicExample(t *testing.T) {
Expand All @@ -35,6 +40,7 @@ func TestAccIntegrationsClient_integrationsClientBasicExample(t *testing.T) {
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckIntegrationsClientDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccIntegrationsClient_integrationsClientBasicExample(context),
Expand Down Expand Up @@ -68,6 +74,7 @@ func TestAccIntegrationsClient_integrationsClientAdvanceExample(t *testing.T) {
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckIntegrationsClientDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccIntegrationsClient_integrationsClientAdvanceExample(context),
Expand Down Expand Up @@ -120,3 +127,42 @@ resource "google_integrations_client" "example" {
}
`, context)
}

func testAccCheckIntegrationsClientDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_integrations_client" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}

config := acctest.GoogleProviderConfig(t)

url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{IntegrationsBasePath}}projects/{{project}}/locations/{{location}}/clients")
if err != nil {
return err
}

billingProject := ""

if config.BillingProject != "" {
billingProject = config.BillingProject
}

_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "GET",
Project: billingProject,
RawURL: url,
UserAgent: config.UserAgent,
})
if err == nil {
return fmt.Errorf("IntegrationsClient still exists at %s", url)
}
}

return nil
}
}
Loading