Skip to content

Commit

Permalink
deprecated-->removed event notification config (#2390)
Browse files Browse the repository at this point in the history
* deprecated-->removed event notification config

* remove singular config from tests/docs

* pluralize

* Update third_party/terraform/tests/resource_cloudiot_registry_test.go

Co-Authored-By: Riley Karson <[email protected]>
  • Loading branch information
emilymye and rileykarson committed Nov 6, 2019
1 parent 374bad7 commit 6818c22
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 83 deletions.
37 changes: 4 additions & 33 deletions third_party/terraform/resources/resource_cloudiot_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,16 @@ func resourceCloudIoTRegistry() *schema.Resource {
[]string{"", "NONE", "ERROR", "INFO", "DEBUG"}, false),
},
"event_notification_config": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Deprecated: "eventNotificationConfig has been deprecated in favor of eventNotificationConfigs (plural). Please switch to using the plural field.",
ConflictsWith: []string{"event_notification_configs"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pubsub_topic_name": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
},
},
Type: schema.TypeMap,
Optional: true,
Computed: true,
Removed: "Please use event_notification_configs instead",
},
"event_notification_configs": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 10,
ConflictsWith: []string{"event_notification_config"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pubsub_topic_name": {
Expand Down Expand Up @@ -241,9 +230,6 @@ func createDeviceRegistry(d *schema.ResourceData) *cloudiot.DeviceRegistry {
deviceRegistry := &cloudiot.DeviceRegistry{}
if v, ok := d.GetOk("event_notification_configs"); ok {
deviceRegistry.EventNotificationConfigs = buildEventNotificationConfigs(v.([]interface{}))
} else if v, ok := d.GetOk("event_notification_config"); ok {
deviceRegistry.EventNotificationConfigs = []*cloudiot.EventNotificationConfig{
buildEventNotificationConfig(v.(map[string]interface{}))}
}

if v, ok := d.GetOk("state_notification_config"); ok {
Expand Down Expand Up @@ -314,15 +300,6 @@ func resourceCloudIoTRegistryUpdate(d *schema.ResourceData, meta interface{}) er
}
}

if d.HasChange("event_notification_config") {
hasChanged = true
updateMask = append(updateMask, "event_notification_configs")
if v, ok := d.GetOk("event_notification_config"); ok {
deviceRegistry.EventNotificationConfigs = []*cloudiot.EventNotificationConfig{
buildEventNotificationConfig(v.(map[string]interface{}))}
}
}

if d.HasChange("state_notification_config") {
hasChanged = true
updateMask = append(updateMask, "state_notification_config.pubsub_topic_name")
Expand Down Expand Up @@ -402,14 +379,8 @@ func resourceCloudIoTRegistryRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("event_notification_configs", cfgs); err != nil {
return fmt.Errorf("Error reading Registry: %s", err)
}
if err := d.Set("event_notification_config", map[string]string{
"pubsub_topic_name": res.EventNotificationConfigs[0].PubsubTopicName,
}); err != nil {
return fmt.Errorf("Error reading Registry: %s", err)
}
} else {
d.Set("event_notification_configs", nil)
d.Set("event_notification_config", nil)
}

pubsubTopicName := res.StateNotificationConfig.PubsubTopicName
Expand Down
75 changes: 27 additions & 48 deletions third_party/terraform/tests/resource_cloudiot_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestAccCloudIoTRegistry_update(t *testing.T) {
})
}

func TestAccCloudIoTRegistry_eventNotificationConfigDeprecatedSingleToPlural(t *testing.T) {
func TestAccCloudIoTRegistry_eventNotificationConfigsSingle(t *testing.T) {
t.Parallel()

registryName := fmt.Sprintf("tf-registry-test-%s", acctest.RandString(10))
Expand All @@ -128,29 +128,18 @@ func TestAccCloudIoTRegistry_eventNotificationConfigDeprecatedSingleToPlural(t *
CheckDestroy: testAccCheckCloudIoTRegistryDestroy,
Steps: []resource.TestStep{
{
// Use deprecated field (event_notification_config) to create
Config: testAccCloudIoTRegistry_singleEventNotificationConfig(topic, registryName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"google_cloudiot_registry.foobar", "event_notification_configs.#", "1"),
),
Config: testAccCloudIoTRegistry_singleEventNotificationConfigs(topic, registryName),
},
{
ResourceName: "google_cloudiot_registry.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
// Use new field (event_notification_configs) to see if plan changed
Config: testAccCloudIoTRegistry_pluralEventNotificationConfigs(topic, registryName),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}

func TestAccCloudIoTRegistry_eventNotificationConfigMultiple(t *testing.T) {
func TestAccCloudIoTRegistry_eventNotificationConfigsMultiple(t *testing.T) {
t.Parallel()

registryName := fmt.Sprintf("tf-registry-test-%s", acctest.RandString(10))
Expand All @@ -173,40 +162,6 @@ func TestAccCloudIoTRegistry_eventNotificationConfigMultiple(t *testing.T) {
})
}

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

registryName := fmt.Sprintf("tf-registry-test-%s", acctest.RandString(10))
topic := fmt.Sprintf("tf-registry-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudIoTRegistryDestroy,
Steps: []resource.TestStep{
{
// Use new field (event_notification_configs) to create
Config: testAccCloudIoTRegistry_pluralEventNotificationConfigs(topic, registryName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"google_cloudiot_registry.foobar", "event_notification_configs.#", "1"),
),
},
{
ResourceName: "google_cloudiot_registry.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
// Use old field (event_notification_config) to see if plan changed
Config: testAccCloudIoTRegistry_singleEventNotificationConfig(topic, registryName),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
},
})
}

func testAccCheckCloudIoTRegistryDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_cloudiot_registry" {
Expand Down Expand Up @@ -322,6 +277,30 @@ resource "google_cloudiot_registry" "foobar" {
`, topic, registryName)
}

func testAccCloudIoTRegistry_singleEventNotificationConfigs(topic, registryName string) string {
return fmt.Sprintf(`
resource "google_project_iam_binding" "cloud-iot-iam-binding" {
members = ["serviceAccount:[email protected]"]
role = "roles/pubsub.publisher"
}
resource "google_pubsub_topic" "event-topic-1" {
name = "%s"
}
resource "google_cloudiot_registry" "foobar" {
depends_on = ["google_project_iam_binding.cloud-iot-iam-binding"]
name = "%s"
event_notification_configs {
pubsub_topic_name = "${google_pubsub_topic.event-topic-1.id}"
subfolder_matches = ""
}
}
`, topic, registryName)
}

func testAccCloudIoTRegistry_multipleEventNotificationConfigs(topic, registryName string) string {
return fmt.Sprintf(`
resource "google_project_iam_binding" "cloud-iot-iam-binding" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ The following arguments are supported:

* `region` - (Optional) The Region in which the created address should reside. If it is not provided, the provider region is used.

* `event_notification_config` - (Deprecated) Use `event_notification_configs` instead.

* `event_notification_configs` - (Optional) List of configurations for event notification, such as
PubSub topics to publish device events to. Structure is documented below.

Expand Down

0 comments on commit 6818c22

Please sign in to comment.