Repository: GoogleCloudPlatform/terraform-validator
Pull request #413 (2021-12-01 16:55:06)

Add support for google_redis_instance
<!-- 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_redis_instance


<!--
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).
- [X] [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/5496


Patch:
diff --git a/converters/google/resources/resource_converters.go b/converters/google/resources/resource_converters.go
index dbeac100..6d4fb727 100644
--- a/converters/google/resources/resource_converters.go
+++ b/converters/google/resources/resource_converters.go
@@ -45,6 +45,7 @@ func ResourceConverters() map[string][]ResourceConverter {
 		"google_bigquery_dataset_iam_binding":              {resourceConverterBigqueryDatasetIamBinding()},
 		"google_bigquery_dataset_iam_member":               {resourceConverterBigqueryDatasetIamMember()},
 		"google_bigquery_table":                            {resourceConverterBigQueryTable()},
+		"google_redis_instance":                            {resourceConverterRedisInstance()},
 		"google_spanner_database":                          {resourceConverterSpannerDatabase()},
 		"google_spanner_database_iam_policy":               {resourceConverterSpannerDatabaseIamPolicy()},
 		"google_spanner_database_iam_binding":              {resourceConverterSpannerDatabaseIamBinding()},


Test patch:
diff --git a/test/cli_test.go b/test/cli_test.go
index ed843b8f..ecf63b30 100644
--- a/test/cli_test.go
+++ b/test/cli_test.go
@@ -116,6 +116,7 @@ func TestCLI(t *testing.T) {
 		{name: "example_project_service"},
 		{name: "example_pubsub_subscription"},
 		{name: "example_pubsub_topic"},
+		{name: "example_redis_instance"},
 		{name: "example_spanner_database"},
 		{name: "example_spanner_database_iam_binding"},
 		{name: "example_spanner_database_iam_member"},
diff --git a/test/read_test.go b/test/read_test.go
index ce68b140..18b9d568 100644
--- a/test/read_test.go
+++ b/test/read_test.go
@@ -75,6 +75,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
 		{name: "example_project_service"},
 		{name: "example_pubsub_subscription"},
 		{name: "example_pubsub_topic"},
+		{name: "example_redis_instance"},
 		{name: "example_spanner_database"},
 		{name: "example_spanner_database_iam_binding"},
 		{name: "example_spanner_database_iam_member"},
diff --git a/testdata/templates/example_redis_instance.json b/testdata/templates/example_redis_instance.json
new file mode 100644
index 00000000..c767a295
--- /dev/null
+++ b/testdata/templates/example_redis_instance.json
@@ -0,0 +1,44 @@
+[
+  {
+    "name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/redis-test-network",
+    "asset_type": "compute.googleapis.com/Network",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/compute/v1/rest",
+      "discovery_name": "Network",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "autoCreateSubnetworks": true,
+        "name": "redis-test-network"
+      }
+    }
+  },
+  {
+    "name": "//redis.googleapis.com/projects/{{.Provider.project}}/locations/us-central1/instances/ha-memory-cache",
+    "asset_type": "redis.googleapis.com/Instance",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/redis/v1/rest",
+      "discovery_name": "Instance",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "alternativeLocationId": "us-central1-f",
+        "connectMode": "DIRECT_PEERING",
+        "displayName": "Terraform Test Instance",
+        "labels": {
+          "my_key": "my_val",
+          "other_key": "other_val"
+        },
+        "locationId": "us-central1-a",
+        "memorySizeGb": 1,
+        "name": "projects/{{.Provider.project}}/locations/us-central1/instances/ha-memory-cache",
+        "redisVersion": "REDIS_4_0",
+        "reservedIpRange": "192.168.0.0/29",
+        "tier": "STANDARD_HA",
+        "transitEncryptionMode": "DISABLED"
+      }
+    }
+  }
+]
diff --git a/testdata/templates/example_redis_instance.tf b/testdata/templates/example_redis_instance.tf
new file mode 100644
index 00000000..4ac28c6d
--- /dev/null
+++ b/testdata/templates/example_redis_instance.tf
@@ -0,0 +1,52 @@
+/**
+ * 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_compute_network" "redis-network" {
+  name = "redis-test-network"
+}
+
+resource "google_redis_instance" "cache" {
+  name           = "ha-memory-cache"
+  tier           = "STANDARD_HA"
+  memory_size_gb = 1
+
+  region = "us-central1"
+  location_id             = "us-central1-a"
+  alternative_location_id = "us-central1-f"
+
+  authorized_network = google_compute_network.redis-network.id
+
+  redis_version     = "REDIS_4_0"
+  display_name      = "Terraform Test Instance"
+  reserved_ip_range = "192.168.0.0/29"
+
+  labels = {
+    my_key    = "my_val"
+    other_key = "other_val"
+  }
+}
diff --git a/testdata/templates/example_redis_instance.tfplan.json b/testdata/templates/example_redis_instance.tfplan.json
new file mode 100644
index 00000000..f2d6e130
--- /dev/null
+++ b/testdata/templates/example_redis_instance.tfplan.json
@@ -0,0 +1,220 @@
+{
+  "format_version": "0.2",
+  "terraform_version": "1.0.10",
+  "planned_values": {
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_compute_network.redis-network",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "redis-network",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "auto_create_subnetworks": true,
+            "delete_default_routes_on_create": false,
+            "description": null,
+            "name": "redis-test-network",
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
+        {
+          "address": "google_redis_instance.cache",
+          "mode": "managed",
+          "type": "google_redis_instance",
+          "name": "cache",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "alternative_location_id": "us-central1-f",
+            "auth_enabled": false,
+            "connect_mode": "DIRECT_PEERING",
+            "display_name": "Terraform Test Instance",
+            "labels": {
+              "my_key": "my_val",
+              "other_key": "other_val"
+            },
+            "location_id": "us-central1-a",
+            "memory_size_gb": 1,
+            "name": "ha-memory-cache",
+            "redis_configs": null,
+            "redis_version": "REDIS_4_0",
+            "region": "us-central1",
+            "reserved_ip_range": "192.168.0.0/29",
+            "tier": "STANDARD_HA",
+            "timeouts": null,
+            "transit_encryption_mode": "DISABLED"
+          },
+          "sensitive_values": {
+            "labels": {},
+            "server_ca_certs": []
+          }
+        }
+      ]
+    }
+  },
+  "resource_changes": [
+    {
+      "address": "google_compute_network.redis-network",
+      "mode": "managed",
+      "type": "google_compute_network",
+      "name": "redis-network",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "auto_create_subnetworks": true,
+          "delete_default_routes_on_create": false,
+          "description": null,
+          "name": "redis-test-network",
+          "timeouts": null
+        },
+        "after_unknown": {
+          "gateway_ipv4": true,
+          "id": true,
+          "mtu": true,
+          "project": true,
+          "routing_mode": true,
+          "self_link": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {}
+      }
+    },
+    {
+      "address": "google_redis_instance.cache",
+      "mode": "managed",
+      "type": "google_redis_instance",
+      "name": "cache",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "alternative_location_id": "us-central1-f",
+          "auth_enabled": false,
+          "connect_mode": "DIRECT_PEERING",
+          "display_name": "Terraform Test Instance",
+          "labels": {
+            "my_key": "my_val",
+            "other_key": "other_val"
+          },
+          "location_id": "us-central1-a",
+          "memory_size_gb": 1,
+          "name": "ha-memory-cache",
+          "redis_configs": null,
+          "redis_version": "REDIS_4_0",
+          "region": "us-central1",
+          "reserved_ip_range": "192.168.0.0/29",
+          "tier": "STANDARD_HA",
+          "timeouts": null,
+          "transit_encryption_mode": "DISABLED"
+        },
+        "after_unknown": {
+          "auth_string": true,
+          "authorized_network": true,
+          "create_time": true,
+          "current_location_id": true,
+          "host": true,
+          "id": true,
+          "labels": {},
+          "persistence_iam_identity": true,
+          "port": true,
+          "project": true,
+          "server_ca_certs": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "auth_string": true,
+          "labels": {},
+          "server_ca_certs": []
+        }
+      }
+    }
+  ],
+  "configuration": {
+    "provider_config": {
+      "google": {
+        "name": "google",
+        "expressions": {
+          "project": {
+            "constant_value": "{{.Provider.project}}"
+          }
+        }
+      }
+    },
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_compute_network.redis-network",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "redis-network",
+          "provider_config_key": "google",
+          "expressions": {
+            "name": {
+              "constant_value": "redis-test-network"
+            }
+          },
+          "schema_version": 0
+        },
+        {
+          "address": "google_redis_instance.cache",
+          "mode": "managed",
+          "type": "google_redis_instance",
+          "name": "cache",
+          "provider_config_key": "google",
+          "expressions": {
+            "alternative_location_id": {
+              "constant_value": "us-central1-f"
+            },
+            "authorized_network": {
+              "references": [
+                "google_compute_network.redis-network.id",
+                "google_compute_network.redis-network"
+              ]
+            },
+            "display_name": {
+              "constant_value": "Terraform Test Instance"
+            },
+            "labels": {
+              "constant_value": {
+                "my_key": "my_val",
+                "other_key": "other_val"
+              }
+            },
+            "location_id": {
+              "constant_value": "us-central1-a"
+            },
+            "memory_size_gb": {
+              "constant_value": 1
+            },
+            "name": {
+              "constant_value": "ha-memory-cache"
+            },
+            "redis_version": {
+              "constant_value": "REDIS_4_0"
+            },
+            "region": {
+              "constant_value": "us-central1"
+            },
+            "reserved_ip_range": {
+              "constant_value": "192.168.0.0/29"
+            },
+            "tier": {
+              "constant_value": "STANDARD_HA"
+            }
+          },
+          "schema_version": 0
+        }
+      ]
+    }
+  }
+}