1. Answers
  2. Creating DNS forwarder rules with Azure DNS Resolver

How do I create DNS forwarder rules with Azure DNS Resolver?

To create DNS forwarder rules with Azure DNS Resolver using Pulumi, you need to set up a DNS forwarding ruleset and associated forwarding rules. Below is a detailed Pulumi program written in TypeScript that demonstrates how to accomplish this.

import * as pulumi from "@pulumi/pulumi";
import * as azureNative from "@pulumi/azure-native";

// Create a resource group
const resourceGroup = new azureNative.resources.ResourceGroup("dnsForwarderResourceGroup", {
    location: "WestEurope",
});

// Create a DNS resolver
const dnsResolver = new azureNative.network.DnsResolver("dnsResolver", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    virtualNetwork: {
        id: "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>",
    },
});

// Create an outbound endpoint for the DNS resolver
const outboundEndpoint = new azureNative.network.OutboundEndpoint("outboundEndpoint", {
    resourceGroupName: resourceGroup.name,
    dnsResolverName: dnsResolver.name,
    location: dnsResolver.location,
    subnet: {
        id: "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<vnet-name>/subnets/<subnet-name>",
    },
});

// Create a DNS forwarding ruleset
const dnsForwardingRuleset = new azureNative.network.DnsForwardingRuleset("dnsForwardingRuleset", {
    resourceGroupName: resourceGroup.name,
    location: resourceGroup.location,
    dnsResolverOutboundEndpoints: [
        {
            id: outboundEndpoint.id,
        },
    ],
});

// Create a forwarding rule
const forwardingRule = new azureNative.network.ForwardingRule("forwardingRule", {
    resourceGroupName: resourceGroup.name,
    dnsForwardingRulesetName: dnsForwardingRuleset.name,
    domainName: "example.com",
    targetDnsServers: [
        {
            ipAddress: "8.8.8.8",
            port: 53,
        },
    ],
    forwardingRuleState: "Enabled",
});

export const dnsResolverId = dnsResolver.id;
export const outboundEndpointId = outboundEndpoint.id;
export const dnsForwardingRulesetId = dnsForwardingRuleset.id;
export const forwardingRuleId = forwardingRule.id;

In this program:

  1. We create a resource group to contain all our resources.
  2. We create a DNS resolver within the specified resource group and associate it with a virtual network.
  3. We create an outbound endpoint for the DNS resolver to handle outbound DNS queries.
  4. We create a DNS forwarding ruleset and associate it with the outbound endpoint.
  5. We create a forwarding rule within the ruleset to forward DNS queries for a specific domain (example.com) to a target DNS server (8.8.8.8).

All resources are defined and managed using Pulumi’s Azure Native provider, making it easy to define and deploy infrastructure as code.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up