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

deprecated-->removed event notification config #2390

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
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 @@ -118,7 +118,7 @@ func TestAccCloudIoTRegistry_update(t *testing.T) {
})
}

func TestAccCloudIoTRegistry_eventNotificationConfigDeprecatedSingleToPlural(t *testing.T) {
func TestAccCloudIoTRegistry_eventNotificationConfigsSing;e(t *testing.T) {
emilymye marked this conversation as resolved.
Show resolved Hide resolved
t.Parallel()

registryName := fmt.Sprintf("tf-registry-test-%s", acctest.RandString(10))
Expand All @@ -130,29 +130,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 @@ -175,40 +164,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 @@ -342,6 +297,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 @@ -65,8 +65,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