Repository: GoogleCloudPlatform/terraform-validator
Pull request #437 (2021-12-14 20:05:48)

Add support for google_pubsub_lite_topic
<!-- Put a description of what this PR is for here, along with any references to issues that this resolves or contributes to -->

Add support for google_pubsub_lite_topic


<!--
Replace each [ ] with [X] to check it. Switch to the preview view to make it easier to click on links.
These steps will speed up the review process, and we appreciate you spending time on them before sending
your code to be reviewed.
-->
If this PR is for Terraform, I acknowledge that I have:

- [X] Searched through the [issue tracker](https://github.com/hashicorp/terraform-provider-google/issues) for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
- [ ] [Generated Terraform](https://github.com/GoogleCloudPlatform/magic-modules#generating-downstream-tools), and ran `make test` and `make lint` to ensure it passes unit and linter tests.
- [ ] Ensured that all new fields I added that can be set by a user appear in at least one [example](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/templates/terraform/examples) (for generated resources) or [third_party test](https://github.com/GoogleCloudPlatform/magic-modules/tree/master/third_party/terraform/tests) (for handwritten resources or update tests).
- [ ] [Ran](https://github.com/hashicorp/terraform-provider-google/blob/master/.github/CONTRIBUTING.md#tests) relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
- [X] Read the [Release Notes Guide](https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md) before writing my release note below.

<!-- AUTOCHANGELOG for Downstream PRs.

Please select one of the following "release-note:" headings:
    - release-note:enhancement
    - release-note:bug
    - release-note:note
    - release-note:new-resource
    - release-note:new-datasource
    - release-note:deprecation
    - release-note:breaking-change
    - release-note:none
    
Unless you choose release-note:none, please add a release note.

See .ci/RELEASE_NOTES_GUIDE.md for writing good release notes.

You can add more release note blocks if you want more than one CHANGELOG
entry for this PR.
-->
**Release Note Template for Downstream PRs (will be copied)**

```release-note:enhancement

```

Derived from https://github.com/GoogleCloudPlatform/magic-modules/pull/5549


Patch:
diff --git a/converters/google/resources/pubsublite_reservation.go b/converters/google/resources/pubsublite_reservation.go
index b4bbd665..e8372863 100644
--- a/converters/google/resources/pubsublite_reservation.go
+++ b/converters/google/resources/pubsublite_reservation.go
@@ -16,7 +16,7 @@ package google
 
 import "reflect"
 
-const PubsubLiteReservationAssetType string = "{{region}}-pubsublite.googleapis.com/Reservation"
+const PubsubLiteReservationAssetType string = "pubsublite.googleapis.com/Reservation"
 
 func resourceConverterPubsubLiteReservation() ResourceConverter {
 	return ResourceConverter{
@@ -26,7 +26,7 @@ func resourceConverterPubsubLiteReservation() ResourceConverter {
 }
 
 func GetPubsubLiteReservationCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
-	name, err := assetName(d, config, "//{{region}}-pubsublite.googleapis.com/projects/{{project}}/locations/{{region}}/reservations/{{name}}")
+	name, err := assetName(d, config, "//pubsublite.googleapis.com/projects/{{project}}/locations/{{region}}/reservations/{{name}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -36,7 +36,7 @@ func GetPubsubLiteReservationCaiObject(d TerraformResourceData, config *Config)
 			Type: PubsubLiteReservationAssetType,
 			Resource: &AssetResource{
 				Version:              "admin",
-				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/{{region}}-pubsublite/admin/rest",
+				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/pubsublite/admin/rest",
 				DiscoveryName:        "Reservation",
 				Data:                 obj,
 			},
diff --git a/converters/google/resources/pubsublite_subscription.go b/converters/google/resources/pubsublite_subscription.go
index 0abe44b8..09333371 100644
--- a/converters/google/resources/pubsublite_subscription.go
+++ b/converters/google/resources/pubsublite_subscription.go
@@ -20,7 +20,7 @@ import (
 	"regexp"
 )
 
-const PubsubLiteSubscriptionAssetType string = "{{region}}-pubsublite.googleapis.com/Subscription"
+const PubsubLiteSubscriptionAssetType string = "pubsublite.googleapis.com/Subscription"
 
 func resourceConverterPubsubLiteSubscription() ResourceConverter {
 	return ResourceConverter{
@@ -30,7 +30,7 @@ func resourceConverterPubsubLiteSubscription() ResourceConverter {
 }
 
 func GetPubsubLiteSubscriptionCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
-	name, err := assetName(d, config, "//{{region}}-pubsublite.googleapis.com/projects/{{project}}/locations/{{zone}}/subscriptions/{{name}}")
+	name, err := assetName(d, config, "//pubsublite.googleapis.com/projects/{{project}}/locations/{{zone}}/subscriptions/{{name}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -40,7 +40,7 @@ func GetPubsubLiteSubscriptionCaiObject(d TerraformResourceData, config *Config)
 			Type: PubsubLiteSubscriptionAssetType,
 			Resource: &AssetResource{
 				Version:              "admin",
-				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/{{region}}-pubsublite/admin/rest",
+				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/pubsublite/admin/rest",
 				DiscoveryName:        "Subscription",
 				Data:                 obj,
 			},
diff --git a/converters/google/resources/pubsublite_topic.go b/converters/google/resources/pubsublite_topic.go
index d01bb1d7..58d303b2 100644
--- a/converters/google/resources/pubsublite_topic.go
+++ b/converters/google/resources/pubsublite_topic.go
@@ -19,7 +19,7 @@ import (
 	"reflect"
 )
 
-const PubsubLiteTopicAssetType string = "{{region}}-pubsublite.googleapis.com/Topic"
+const PubsubLiteTopicAssetType string = "pubsublite.googleapis.com/Topic"
 
 func resourceConverterPubsubLiteTopic() ResourceConverter {
 	return ResourceConverter{
@@ -29,7 +29,7 @@ func resourceConverterPubsubLiteTopic() ResourceConverter {
 }
 
 func GetPubsubLiteTopicCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) {
-	name, err := assetName(d, config, "//{{region}}-pubsublite.googleapis.com/projects/{{project}}/locations/{{zone}}/topics/{{name}}")
+	name, err := assetName(d, config, "//pubsublite.googleapis.com/projects/{{project}}/locations/{{zone}}/topics/{{name}}")
 	if err != nil {
 		return []Asset{}, err
 	}
@@ -39,7 +39,7 @@ func GetPubsubLiteTopicCaiObject(d TerraformResourceData, config *Config) ([]Ass
 			Type: PubsubLiteTopicAssetType,
 			Resource: &AssetResource{
 				Version:              "admin",
-				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/{{region}}-pubsublite/admin/rest",
+				DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/pubsublite/admin/rest",
 				DiscoveryName:        "Topic",
 				Data:                 obj,
 			},
diff --git a/converters/google/resources/resource_converters.go b/converters/google/resources/resource_converters.go
index 9cf5ae9d..ec6bccd9 100644
--- a/converters/google/resources/resource_converters.go
+++ b/converters/google/resources/resource_converters.go
@@ -56,6 +56,7 @@ func ResourceConverters() map[string][]ResourceConverter {
 		"google_spanner_instance_iam_binding":              {resourceConverterSpannerInstanceIamBinding()},
 		"google_spanner_instance_iam_member":               {resourceConverterSpannerInstanceIamMember()},
 		"google_project_service":                           {resourceConverterServiceUsage()},
+		"google_pubsub_lite_topic":                         {resourceConverterPubsubLiteTopic()},
 		"google_pubsub_schema":                             {resourceConverterPubsubSchema()},
 		"google_pubsub_subscription":                       {resourceConverterPubsubSubscription()},
 		"google_pubsub_subscription_iam_policy":            {resourceConverterPubsubSubscriptionIamPolicy()},


Test patch:
diff --git a/test/cli_test.go b/test/cli_test.go
index 23fdcfcb..cbd930b4 100644
--- a/test/cli_test.go
+++ b/test/cli_test.go
@@ -114,6 +114,7 @@ func TestCLI(t *testing.T) {
 		{name: "example_project_in_org"},
 		{name: "example_project_organization_policy"},
 		{name: "example_project_service"},
+		{name: "example_pubsub_lite_topic"},
 		{name: "example_pubsub_schema"},
 		{name: "example_pubsub_subscription"},
 		{name: "example_pubsub_subscription_iam_binding"},
diff --git a/test/read_test.go b/test/read_test.go
index 60312609..76f6da9e 100644
--- a/test/read_test.go
+++ b/test/read_test.go
@@ -73,6 +73,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
 		{name: "example_project_in_org"},
 		{name: "example_project_organization_policy"},
 		{name: "example_project_service"},
+		{name: "example_pubsub_lite_topic"},
 		{name: "example_pubsub_schema"},
 		{name: "example_pubsub_subscription"},
 		{name: "example_pubsub_subscription_iam_binding"},
diff --git a/testdata/templates/example_pubsub_lite_topic.json b/testdata/templates/example_pubsub_lite_topic.json
new file mode 100644
index 00000000..0edf91c7
--- /dev/null
+++ b/testdata/templates/example_pubsub_lite_topic.json
@@ -0,0 +1,28 @@
+[
+  {
+    "name": "//pubsublite.googleapis.com/projects/{{.Provider.project}}/locations/us-central1a/topics/example-topic",
+    "asset_type": "pubsublite.googleapis.com/Topic",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "admin",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/pubsublite/admin/rest",
+      "discovery_name": "Topic",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "partitionConfig": {
+          "capacity": {
+            "publishMibPerSec": 4,
+            "subscribeMibPerSec": 8
+          },
+          "count": 1
+        },
+        "reservationConfig": {
+          "throughputReservation": "projects/{{.Provider.project}}/locations/us-central/reservations/example-reservation"
+        },
+        "retentionConfig": {
+          "perPartitionBytes": "32212254720"
+        }
+      }
+    }
+  }
+]
diff --git a/testdata/templates/example_pubsub_lite_topic.tf b/testdata/templates/example_pubsub_lite_topic.tf
new file mode 100644
index 00000000..0d7a7fa0
--- /dev/null
+++ b/testdata/templates/example_pubsub_lite_topic.tf
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+terraform {
+  required_providers {
+    google = {
+      source = "hashicorp/google"
+      version = "~> {{.Provider.version}}"
+    }
+  }
+}
+
+provider "google" {
+  {{if .Provider.credentials }}credentials = "{{.Provider.credentials}}"{{end}}
+}
+
+resource "google_pubsub_lite_topic" "example" {
+  name = "example-topic"
+  zone = "us-central1a"
+
+  partition_config {
+    count = 1
+    capacity {
+      publish_mib_per_sec = 4
+      subscribe_mib_per_sec = 8
+    }
+  }
+
+  retention_config {
+    per_partition_bytes = 32212254720
+  }
+
+  reservation_config {
+    throughput_reservation = "example-reservation"
+  }
+}
diff --git a/testdata/templates/example_pubsub_lite_topic.tfplan.json b/testdata/templates/example_pubsub_lite_topic.tfplan.json
new file mode 100644
index 00000000..7cbed887
--- /dev/null
+++ b/testdata/templates/example_pubsub_lite_topic.tfplan.json
@@ -0,0 +1,190 @@
+{
+  "format_version": "0.2",
+  "terraform_version": "1.0.10",
+  "planned_values": {
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_pubsub_lite_topic.example",
+          "mode": "managed",
+          "type": "google_pubsub_lite_topic",
+          "name": "example",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "name": "example-topic",
+            "partition_config": [
+              {
+                "capacity": [
+                  {
+                    "publish_mib_per_sec": 4,
+                    "subscribe_mib_per_sec": 8
+                  }
+                ],
+                "count": 1
+              }
+            ],
+            "region": null,
+            "reservation_config": [
+              {
+                "throughput_reservation": "example-reservation"
+              }
+            ],
+            "retention_config": [
+              {
+                "per_partition_bytes": "32212254720",
+                "period": null
+              }
+            ],
+            "timeouts": null,
+            "zone": "us-central1a"
+          },
+          "sensitive_values": {
+            "partition_config": [
+              {
+                "capacity": [
+                  {}
+                ]
+              }
+            ],
+            "reservation_config": [
+              {}
+            ],
+            "retention_config": [
+              {}
+            ]
+          }
+        }
+      ]
+    }
+  },
+  "resource_changes": [
+    {
+      "address": "google_pubsub_lite_topic.example",
+      "mode": "managed",
+      "type": "google_pubsub_lite_topic",
+      "name": "example",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "name": "example-topic",
+          "partition_config": [
+            {
+              "capacity": [
+                {
+                  "publish_mib_per_sec": 4,
+                  "subscribe_mib_per_sec": 8
+                }
+              ],
+              "count": 1
+            }
+          ],
+          "region": null,
+          "reservation_config": [
+            {
+              "throughput_reservation": "example-reservation"
+            }
+          ],
+          "retention_config": [
+            {
+              "per_partition_bytes": "32212254720",
+              "period": null
+            }
+          ],
+          "timeouts": null,
+          "zone": "us-central1a"
+        },
+        "after_unknown": {
+          "id": true,
+          "partition_config": [
+            {
+              "capacity": [
+                {}
+              ]
+            }
+          ],
+          "project": true,
+          "reservation_config": [
+            {}
+          ],
+          "retention_config": [
+            {}
+          ]
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "partition_config": [
+            {
+              "capacity": [
+                {}
+              ]
+            }
+          ],
+          "reservation_config": [
+            {}
+          ],
+          "retention_config": [
+            {}
+          ]
+        }
+      }
+    }
+  ],
+  "configuration": {
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_pubsub_lite_topic.example",
+          "mode": "managed",
+          "type": "google_pubsub_lite_topic",
+          "name": "example",
+          "provider_config_key": "google",
+          "expressions": {
+            "name": {
+              "constant_value": "example-topic"
+            },
+            "partition_config": [
+              {
+                "capacity": [
+                  {
+                    "publish_mib_per_sec": {
+                      "constant_value": 4
+                    },
+                    "subscribe_mib_per_sec": {
+                      "constant_value": 8
+                    }
+                  }
+                ],
+                "count": {
+                  "constant_value": 1
+                }
+              }
+            ],
+            "reservation_config": [
+              {
+                "throughput_reservation": {
+                  "constant_value": "example-reservation"
+                }
+              }
+            ],
+            "retention_config": [
+              {
+                "per_partition_bytes": {
+                  "constant_value": 32212254720
+                }
+              }
+            ],
+            "zone": {
+              "constant_value": "us-central1a"
+            }
+          },
+          "schema_version": 0
+        }
+      ]
+    }
+  }
+}