From d3ab42a60fac83bebe7509da98fbd179742c393d Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 17 Oct 2018 15:11:23 -0700 Subject: [PATCH] Add import tests for google_cloudiot_registry (#2276) /cc @rileykarson --- google/resource_cloudiot_registry.go | 23 ++++++++++------------- google/resource_cloudiot_registry_test.go | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/google/resource_cloudiot_registry.go b/google/resource_cloudiot_registry.go index a7aa0d06..ae850fcb 100644 --- a/google/resource_cloudiot_registry.go +++ b/google/resource_cloudiot_registry.go @@ -76,6 +76,7 @@ func resourceCloudIoTRegistry() *schema.Resource { }, "mqtt_config": &schema.Schema{ Type: schema.TypeMap, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -90,6 +91,7 @@ func resourceCloudIoTRegistry() *schema.Resource { }, "http_config": &schema.Schema{ Type: schema.TypeMap, + Computed: true, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -233,6 +235,11 @@ func resourceCloudIoTRegistryCreate(d *schema.ResourceData, meta interface{}) er d.SetId("") return err } + + // If we infer project and region, they are never actually set so we set them here + d.Set("project", project) + d.Set("region", region) + return resourceCloudIoTRegistryRead(d, meta) } @@ -317,19 +324,9 @@ func resourceCloudIoTRegistryRead(d *schema.ResourceData, meta interface{}) erro } else { d.Set("state_notification_config", nil) } - // If no config exist for mqtt or http config default values are omitted. - mqttState := res.MqttConfig.MqttEnabledState - _, hasMqttConfig := d.GetOk("mqtt_config") - if mqttState != mqttEnabled || hasMqttConfig { - d.Set("mqtt_config", - map[string]string{"mqtt_enabled_state": mqttState}) - } - httpState := res.HttpConfig.HttpEnabledState - _, hasHttpConfig := d.GetOk("http_config") - if httpState != httpEnabled || hasHttpConfig { - d.Set("http_config", - map[string]string{"http_enabled_state": httpState}) - } + + d.Set("mqtt_config", map[string]string{"mqtt_enabled_state": res.MqttConfig.MqttEnabledState}) + d.Set("http_config", map[string]string{"http_enabled_state": res.HttpConfig.HttpEnabledState}) credentials := make([]map[string]interface{}, len(res.Credentials)) for i, item := range res.Credentials { diff --git a/google/resource_cloudiot_registry_test.go b/google/resource_cloudiot_registry_test.go index e7e61021..03d81c56 100644 --- a/google/resource_cloudiot_registry_test.go +++ b/google/resource_cloudiot_registry_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func TestAccCloudIoTRegistryCreate_basic(t *testing.T) { +func TestAccCloudIoTRegistry_basic(t *testing.T) { t.Parallel() registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) @@ -26,11 +26,16 @@ func TestAccCloudIoTRegistryCreate_basic(t *testing.T) { "google_cloudiot_registry.foobar"), ), }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, }, }) } -func TestAccCloudIoTRegistryCreate_extended(t *testing.T) { +func TestAccCloudIoTRegistry_extended(t *testing.T) { t.Parallel() registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) @@ -47,11 +52,16 @@ func TestAccCloudIoTRegistryCreate_extended(t *testing.T) { "google_cloudiot_registry.foobar"), ), }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, }, }) } -func TestAccCloudIoTRegistryUpdate(t *testing.T) { +func TestAccCloudIoTRegistry_update(t *testing.T) { t.Parallel() registryName := fmt.Sprintf("psregistry-test-%s", acctest.RandString(10)) @@ -74,6 +84,11 @@ func TestAccCloudIoTRegistryUpdate(t *testing.T) { resource.TestStep{ Config: testAccCloudIoTRegistry_basic(registryName), }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, }, }) }