Google Cloud DNS Policy

This page shows how to write Terraform for Cloud DNS Policy and write them securely.

google_dns_policy (Terraform)

The Policy in Cloud DNS can be configured in Terraform with the resource name google_dns_policy. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

dns.tf#L5
resource "google_dns_policy" "default_policy" {
  provider                  = google-beta
  project                   = var.project_id
  name                      = "default-policy"
  enable_inbound_forwarding = var.dns_enable_inbound_forwarding
  enable_logging            = var.dns_enable_logging
main.tf#L7
resource "google_dns_policy" "this" {
  description               = var.description
  enable_inbound_forwarding = var.enable_inbound_forwarding
  enable_logging            = var.enable_logging
  name                      = var.name
  project                   = var.project
dns.tf#L21
resource "google_dns_policy" "default_policy" {
  provider                  = google-beta
  project                   = var.project_id
  name                      = "default-policy"
  enable_inbound_forwarding = var.dns_enable_inbound_forwarding
  enable_logging            = var.dns_enable_logging

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

A textual description field. Defaults to 'Managed by Terraform'.

Allows networks bound to this policy to receive DNS queries sent by VMs or applications over VPN connections. When enabled, a virtual IP address will be allocated from each of the sub-networks that are bound to this policy.

Controls whether logging is enabled for the networks bound to this policy. Defaults to no logging if not set.

  • id optional computed - string
  • name required - string

User assigned name for this policy.

Explanation in Terraform Registry

A policy is a collection of DNS rules applied to one or more Virtual Private Cloud resources. To get more information about Policy, see:

Tips: Best Practices for The Other Google Cloud DNS Resources

In addition to the google_dns_managed_zone, Google Cloud DNS has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

google_dns_managed_zone

Ensure DNSSEC for your Cloud DNS zone is enabled

It is better to enable DNSSEC unless the zone is private. DNSSEC prevents attackers from running several attacks for the DNS zone.

Review your Google Cloud DNS settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Frequently asked questions

What is Google Cloud DNS Policy?

Google Cloud DNS Policy is a resource for Cloud DNS of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud DNS Policy?

For Terraform, the nhsy/gcp-terragrunt-bootstrap, niveklabs/google and caleonardo/jenkins-pipeline-test-03 source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.