Repository: GoogleCloudPlatform/terraform-validator
Pull request #408 (2021-11-24 20:01:36)

Add support for google_dns_policy
<!-- 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_dns_policy https://github.com/GoogleCloudPlatform/terraform-validator/issues/223


<!--
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/5487


Patch:
diff --git a/converters/google/resources/resource_converters.go b/converters/google/resources/resource_converters.go
index 39e77425..53174bf4 100644
--- a/converters/google/resources/resource_converters.go
+++ b/converters/google/resources/resource_converters.go
@@ -35,6 +35,7 @@ func ResourceConverters() map[string][]ResourceConverter {
 		"google_compute_subnetwork":                        {resourceConverterComputeSubnetwork()},
 		"google_compute_ssl_policy":                        {resourceConverterComputeSslPolicy()},
 		"google_dns_managed_zone":                          {resourceConverterDNSManagedZone()},
+		"google_dns_policy":                                {resourceConverterDNSPolicy()},
 		"google_storage_bucket":                            {resourceConverterStorageBucket()},
 		"google_sql_database_instance":                     {resourceConverterSQLDatabaseInstance()},
 		"google_container_cluster":                         {resourceConverterContainerCluster()},


Test patch:
diff --git a/test/cli_test.go b/test/cli_test.go
index 03634233..3e1c26a4 100644
--- a/test/cli_test.go
+++ b/test/cli_test.go
@@ -91,6 +91,7 @@ func TestCLI(t *testing.T) {
 		{name: "example_compute_subnetwork"},
 		{name: "example_container_cluster"},
 		{name: "example_dns_managed_zone"},
+		{name: "example_dns_policy"},
 		{name: "example_filestore_instance"},
 		{name: "example_kms_crypto_key"},
 		{name: "example_kms_crypto_key_iam_binding"},
diff --git a/test/read_test.go b/test/read_test.go
index 71c8a041..532fd3b0 100644
--- a/test/read_test.go
+++ b/test/read_test.go
@@ -50,6 +50,7 @@ func TestReadPlannedAssetsCoverage(t *testing.T) {
 		{name: "example_compute_subnetwork"},
 		{name: "example_container_cluster"},
 		{name: "example_dns_managed_zone"},
+		{name: "example_dns_policy"},
 		{name: "example_filestore_instance"},
 		{name: "example_kms_crypto_key"},
 		{name: "example_kms_crypto_key_iam_binding"},
diff --git a/testdata/templates/example_dns_policy.json b/testdata/templates/example_dns_policy.json
new file mode 100644
index 00000000..cd98d60e
--- /dev/null
+++ b/testdata/templates/example_dns_policy.json
@@ -0,0 +1,60 @@
+[
+  {
+    "name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/network-1",
+    "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": false,
+        "name": "network-1"
+      }
+    }
+  },
+  {
+    "name": "//compute.googleapis.com/projects/{{.Provider.project}}/global/networks/network-2",
+    "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": false,
+        "name": "network-2"
+      }
+    }
+  },
+  {
+    "name": "//dns.googleapis.com/projects/{{.Provider.project}}/policies/example-policy",
+    "asset_type": "dns.googleapis.com/Policy",
+    "ancestry_path": "{{.Ancestry}}/project/{{.Provider.project}}",
+    "resource": {
+      "version": "v1",
+      "discovery_document_uri": "https://www.googleapis.com/discovery/v1/apis/dns/v1/rest",
+      "discovery_name": "Policy",
+      "parent": "//cloudresourcemanager.googleapis.com/projects/{{.Provider.project}}",
+      "data": {
+        "alternativeNameServerConfig": {
+          "targetNameServers": [
+            {
+              "ipv4Address": "172.16.1.20"
+            },
+            {
+              "forwardingPath": "private",
+              "ipv4Address": "172.16.1.10"
+            }
+          ]
+        },
+        "description": "Managed by Terraform",
+        "enableInboundForwarding": true,
+        "enableLogging": true,
+        "name": "example-policy"
+      }
+    }
+  }
+]
diff --git a/testdata/templates/example_dns_policy.tf b/testdata/templates/example_dns_policy.tf
new file mode 100644
index 00000000..35eec992
--- /dev/null
+++ b/testdata/templates/example_dns_policy.tf
@@ -0,0 +1,62 @@
+/**
+ * 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_dns_policy" "example-policy" {
+  name                      = "example-policy"
+  enable_inbound_forwarding = true
+
+  enable_logging = true
+
+  alternative_name_server_config {
+    target_name_servers {
+      ipv4_address    = "172.16.1.10"
+      forwarding_path = "private"
+    }
+    target_name_servers {
+      ipv4_address = "172.16.1.20"
+    }
+  }
+
+  networks {
+    network_url = google_compute_network.network-1.id
+  }
+  networks {
+    network_url = google_compute_network.network-2.id
+  }
+}
+
+resource "google_compute_network" "network-1" {
+  name                    = "network-1"
+  auto_create_subnetworks = false
+}
+
+resource "google_compute_network" "network-2" {
+  name                    = "network-2"
+  auto_create_subnetworks = false
+}
diff --git a/testdata/templates/example_dns_policy.tfplan.json b/testdata/templates/example_dns_policy.tfplan.json
new file mode 100644
index 00000000..3afed08c
--- /dev/null
+++ b/testdata/templates/example_dns_policy.tfplan.json
@@ -0,0 +1,328 @@
+{
+  "format_version": "0.2",
+  "terraform_version": "1.0.10",
+  "planned_values": {
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_compute_network.network-1",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "network-1",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "auto_create_subnetworks": false,
+            "delete_default_routes_on_create": false,
+            "description": null,
+            "name": "network-1",
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
+        {
+          "address": "google_compute_network.network-2",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "network-2",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "auto_create_subnetworks": false,
+            "delete_default_routes_on_create": false,
+            "description": null,
+            "name": "network-2",
+            "timeouts": null
+          },
+          "sensitive_values": {}
+        },
+        {
+          "address": "google_dns_policy.example-policy",
+          "mode": "managed",
+          "type": "google_dns_policy",
+          "name": "example-policy",
+          "provider_name": "registry.terraform.io/hashicorp/google",
+          "schema_version": 0,
+          "values": {
+            "alternative_name_server_config": [
+              {
+                "target_name_servers": [
+                  {
+                    "forwarding_path": "",
+                    "ipv4_address": "172.16.1.20"
+                  },
+                  {
+                    "forwarding_path": "private",
+                    "ipv4_address": "172.16.1.10"
+                  }
+                ]
+              }
+            ],
+            "description": "Managed by Terraform",
+            "enable_inbound_forwarding": true,
+            "enable_logging": true,
+            "name": "example-policy",
+            "networks": [
+              {},
+              {}
+            ],
+            "timeouts": null
+          },
+          "sensitive_values": {
+            "alternative_name_server_config": [
+              {
+                "target_name_servers": [
+                  {},
+                  {}
+                ]
+              }
+            ],
+            "networks": [
+              {},
+              {}
+            ]
+          }
+        }
+      ]
+    }
+  },
+  "resource_changes": [
+    {
+      "address": "google_compute_network.network-1",
+      "mode": "managed",
+      "type": "google_compute_network",
+      "name": "network-1",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "auto_create_subnetworks": false,
+          "delete_default_routes_on_create": false,
+          "description": null,
+          "name": "network-1",
+          "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_compute_network.network-2",
+      "mode": "managed",
+      "type": "google_compute_network",
+      "name": "network-2",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "auto_create_subnetworks": false,
+          "delete_default_routes_on_create": false,
+          "description": null,
+          "name": "network-2",
+          "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_dns_policy.example-policy",
+      "mode": "managed",
+      "type": "google_dns_policy",
+      "name": "example-policy",
+      "provider_name": "registry.terraform.io/hashicorp/google",
+      "change": {
+        "actions": [
+          "create"
+        ],
+        "before": null,
+        "after": {
+          "alternative_name_server_config": [
+            {
+              "target_name_servers": [
+                {
+                  "forwarding_path": "",
+                  "ipv4_address": "172.16.1.20"
+                },
+                {
+                  "forwarding_path": "private",
+                  "ipv4_address": "172.16.1.10"
+                }
+              ]
+            }
+          ],
+          "description": "Managed by Terraform",
+          "enable_inbound_forwarding": true,
+          "enable_logging": true,
+          "name": "example-policy",
+          "networks": [
+            {},
+            {}
+          ],
+          "timeouts": null
+        },
+        "after_unknown": {
+          "alternative_name_server_config": [
+            {
+              "target_name_servers": [
+                {},
+                {}
+              ]
+            }
+          ],
+          "id": true,
+          "networks": [
+            {
+              "network_url": true
+            },
+            {
+              "network_url": true
+            }
+          ],
+          "project": true
+        },
+        "before_sensitive": false,
+        "after_sensitive": {
+          "alternative_name_server_config": [
+            {
+              "target_name_servers": [
+                {},
+                {}
+              ]
+            }
+          ],
+          "networks": [
+            {},
+            {}
+          ]
+        }
+      }
+    }
+  ],
+  "configuration": {
+    "provider_config": {
+      "google": {
+        "name": "google",
+        "expressions": {
+          "project": {
+            "constant_value": "{{.Provider.project}}"
+          }
+        }
+      }
+    },
+    "root_module": {
+      "resources": [
+        {
+          "address": "google_compute_network.network-1",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "network-1",
+          "provider_config_key": "google",
+          "expressions": {
+            "auto_create_subnetworks": {
+              "constant_value": false
+            },
+            "name": {
+              "constant_value": "network-1"
+            }
+          },
+          "schema_version": 0
+        },
+        {
+          "address": "google_compute_network.network-2",
+          "mode": "managed",
+          "type": "google_compute_network",
+          "name": "network-2",
+          "provider_config_key": "google",
+          "expressions": {
+            "auto_create_subnetworks": {
+              "constant_value": false
+            },
+            "name": {
+              "constant_value": "network-2"
+            }
+          },
+          "schema_version": 0
+        },
+        {
+          "address": "google_dns_policy.example-policy",
+          "mode": "managed",
+          "type": "google_dns_policy",
+          "name": "example-policy",
+          "provider_config_key": "google",
+          "expressions": {
+            "alternative_name_server_config": [
+              {
+                "target_name_servers": [
+                  {
+                    "forwarding_path": {
+                      "constant_value": "private"
+                    },
+                    "ipv4_address": {
+                      "constant_value": "172.16.1.10"
+                    }
+                  },
+                  {
+                    "ipv4_address": {
+                      "constant_value": "172.16.1.20"
+                    }
+                  }
+                ]
+              }
+            ],
+            "enable_inbound_forwarding": {
+              "constant_value": true
+            },
+            "enable_logging": {
+              "constant_value": true
+            },
+            "name": {
+              "constant_value": "example-policy"
+            },
+            "networks": [
+              {
+                "network_url": {
+                  "references": [
+                    "google_compute_network.network-1.id",
+                    "google_compute_network.network-1"
+                  ]
+                }
+              },
+              {
+                "network_url": {
+                  "references": [
+                    "google_compute_network.network-2.id",
+                    "google_compute_network.network-2"
+                  ]
+                }
+              }
+            ]
+          },
+          "schema_version": 0
+        }
+      ]
+    }
+  }
+}