Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
YpNo committed Dec 9, 2024
1 parent e340eb3 commit 05b8bf2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func DataSourceGoogleGkeHubFeature() *schema.Resource {
dsSchema := tpgresource.DatasourceSchemaFromResourceSchema(ResourceGKEHub2Feature().Schema)
tpgresource.AddRequiredFieldsToSchema(dsSchema, "location")
tpgresource.AddRequiredFieldsToSchema(dsSchema, "project")
tpgresource.AddRequiredFieldsToSchema(dsSchema, "feature")
tpgresource.AddRequiredFieldsToSchema(dsSchema, "name")

return &schema.Resource{
Read: dataSourceGoogleGkeHubFeatureRead,
Expand All @@ -23,7 +23,7 @@ func DataSourceGoogleGkeHubFeature() *schema.Resource {
func dataSourceGoogleGkeHubFeatureRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)

id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/features/{{feature}}")
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/features/{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,42 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)

func TestAccDataSourceGoogleGKEHub2Feature_basic(t *testing.T) {
func TestAccDataSourceGoogleGkeHubFeature_basic(t *testing.T) {
t.Parallel()

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckGKEHub2FeatureDestroyProducer(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
PreCheck: func() { acctest.AccTestPreCheck(t) },
Providers: acctest.TestAccProviders,
CheckDestroy: testAccCheckGoogleGkeHubFeatureDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleGKEHub2Feature_basic(context),
Config: testAccDataSourceGoogleGkeHubFeature_basic(context),
Check: resource.ComposeTestCheckFunc(
acctest.CheckDataSourceStateMatchesResourceState("data.google_gke_hub_feature.feature", "google_gke_hub_feature.feature"),
acctest.CheckDataSourceStateMatchesResourceState("data.google_gke_hub_feature.example", "google_gke_hub_feature.example"),
),
},
},
})
}

func testAccDataSourceGoogleGKEHub2Feature_basic(context map[string]interface{}) string {
func testAccDataSourceGoogleGkeHubFeature_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_project" "project" {}
resource "google_gke_hub_feature" "feature" {
name = "servicemesh"
location = "global"
project = data.google_project.project.project_id
depends_on = [time_sleep.wait_for_gkehub_enablement]
resource "google_gke_hub_feature" "example" {
location = "us-central1"
project = "%{project}"
name = "configmanagement"
}
data "google_gke_hub_feature" "feature" {
data "google_gke_hub_feature" "example" {
location = google_gke_hub_feature.feature.location
project = data.google_project.project.project_id
feature = google_gke_hub_feature.feature.name
project = google_gke_hub_feature.feature.project
name = google_gke_hub_feature.feature.name
}
`, context)
}

0 comments on commit 05b8bf2

Please sign in to comment.