diff --git a/build/terraform b/build/terraform index 061107bc5921..ebf4ad1bbac6 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 061107bc592185db0b2dc0abca089d62ce091cc1 +Subproject commit ebf4ad1bbac6d8745798cd2dbde5178aa8293ece diff --git a/build/terraform-beta b/build/terraform-beta index e5fb5ef73647..b18c102dd966 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit e5fb5ef736475f01b8d3629631393a0ef4b0f980 +Subproject commit b18c102dd966df7cee07188746e6c72574dfb916 diff --git a/third_party/terraform/resources/resource_cloudiot_registry.go b/third_party/terraform/resources/resource_cloudiot_registry.go index f925536d036c..1f616c4fd83c 100644 --- a/third_party/terraform/resources/resource_cloudiot_registry.go +++ b/third_party/terraform/resources/resource_cloudiot_registry.go @@ -178,12 +178,17 @@ func buildEventNotificationConfigs(v []interface{}) []*cloudiot.EventNotificatio } func buildEventNotificationConfig(config map[string]interface{}) *cloudiot.EventNotificationConfig { + if len(config) == 0 { + return nil + } + cfg := &cloudiot.EventNotificationConfig{} if v, ok := config["pubsub_topic_name"]; ok { - return &cloudiot.EventNotificationConfig{ - PubsubTopicName: v.(string), - } + cfg.PubsubTopicName = v.(string) } - return nil + if v, ok := config["subfolder_matches"]; ok { + cfg.SubfolderMatches = v.(string) + } + return cfg } func buildStateNotificationConfig(config map[string]interface{}) *cloudiot.StateNotificationConfig { diff --git a/third_party/terraform/tests/resource_cloudiot_registry_test.go b/third_party/terraform/tests/resource_cloudiot_registry_test.go index 984873f4f24f..472e28b62039 100644 --- a/third_party/terraform/tests/resource_cloudiot_registry_test.go +++ b/third_party/terraform/tests/resource_cloudiot_registry_test.go @@ -137,6 +137,11 @@ func TestAccCloudIoTRegistry_eventNotificationConfigDeprecatedSingleToPlural(t * "google_cloudiot_registry.foobar", "event_notification_configs.#", "1"), ), }, + { + 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), @@ -147,6 +152,29 @@ func TestAccCloudIoTRegistry_eventNotificationConfigDeprecatedSingleToPlural(t * }) } +func TestAccCloudIoTRegistry_eventNotificationConfigMultiple(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{ + { + Config: testAccCloudIoTRegistry_multipleEventNotificationConfigs(topic, registryName), + }, + { + ResourceName: "google_cloudiot_registry.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccCloudIoTRegistry_eventNotificationConfigPluralToDeprecatedSingle(t *testing.T) { t.Parallel() @@ -159,7 +187,7 @@ func TestAccCloudIoTRegistry_eventNotificationConfigPluralToDeprecatedSingle(t * CheckDestroy: testAccCheckCloudIoTRegistryDestroy, Steps: []resource.TestStep{ { - // Use new field (event_notification_config) to create + // Use new field (event_notification_configs) to create Config: testAccCloudIoTRegistry_pluralEventNotificationConfigs(topic, registryName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( @@ -167,7 +195,12 @@ func TestAccCloudIoTRegistry_eventNotificationConfigPluralToDeprecatedSingle(t * ), }, { - // Use new field (event_notification_configs) to see if plan changed + 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, @@ -235,7 +268,7 @@ resource "google_cloudiot_registry" "foobar" { name = "%s" - event_notification_config = { + event_notification_configs { pubsub_topic_name = "${google_pubsub_topic.default-devicestatus.id}" } @@ -308,3 +341,36 @@ resource "google_cloudiot_registry" "foobar" { } `, topic, registryName) } + +func testAccCloudIoTRegistry_multipleEventNotificationConfigs(topic, registryName string) string { + return fmt.Sprintf(` +resource "google_project_iam_binding" "cloud-iot-iam-binding" { + members = ["serviceAccount:cloud-iot@system.gserviceaccount.com"] + role = "roles/pubsub.publisher" +} + +resource "google_pubsub_topic" "event-topic-1" { + name = "%s" +} + +resource "google_pubsub_topic" "event-topic-2" { + name = "%s-alt" +} + +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 = "test" + } + + event_notification_configs { + pubsub_topic_name = "${google_pubsub_topic.event-topic-2.id}" + subfolder_matches = "" + } +} +`, topic, topic, registryName) +} diff --git a/third_party/terraform/website/docs/r/cloudiot_registry.html.markdown b/third_party/terraform/website/docs/r/cloudiot_registry.html.markdown index 628fa84c1796..fd97e728a971 100644 --- a/third_party/terraform/website/docs/r/cloudiot_registry.html.markdown +++ b/third_party/terraform/website/docs/r/cloudiot_registry.html.markdown @@ -27,7 +27,7 @@ resource "google_pubsub_topic" "default-telemetry" { resource "google_cloudiot_registry" "default-registry" { name = "default-registry" - event_notification_config = { + event_notification_configs { pubsub_topic_name = "${google_pubsub_topic.default-telemetry.id}" }