The gcp:dns/dnsManagedZoneIamPolicy:DnsManagedZoneIamPolicy resource, part of the Pulumi GCP provider, controls IAM permissions for Cloud DNS managed zones. This guide focuses on three approaches: authoritative policy management (DnsManagedZoneIamPolicy), role-level member binding (DnsManagedZoneIamBinding), and individual member grants (DnsManagedZoneIamMember).
These resources reference existing managed zones and require appropriate IAM permissions to modify zone-level access. The examples are intentionally small. Combine them with your own managed zones and identity management.
Set complete IAM policy for a managed zone
When you need full control over all IAM permissions for a DNS managed zone, you can define the entire policy in one place.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const admin = gcp.organizations.getIAMPolicy({
bindings: [{
role: "roles/viewer",
members: ["user:jane@example.com"],
}],
});
const policy = new gcp.dns.DnsManagedZoneIamPolicy("policy", {
project: _default.project,
managedZone: _default.name,
policyData: admin.then(admin => admin.policyData),
});
import pulumi
import pulumi_gcp as gcp
admin = gcp.organizations.get_iam_policy(bindings=[{
"role": "roles/viewer",
"members": ["user:jane@example.com"],
}])
policy = gcp.dns.DnsManagedZoneIamPolicy("policy",
project=default["project"],
managed_zone=default["name"],
policy_data=admin.policy_data)
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/dns"
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
admin, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
Bindings: []organizations.GetIAMPolicyBinding{
{
Role: "roles/viewer",
Members: []string{
"user:jane@example.com",
},
},
},
}, nil)
if err != nil {
return err
}
_, err = dns.NewDnsManagedZoneIamPolicy(ctx, "policy", &dns.DnsManagedZoneIamPolicyArgs{
Project: pulumi.Any(_default.Project),
ManagedZone: pulumi.Any(_default.Name),
PolicyData: pulumi.String(admin.PolicyData),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var admin = Gcp.Organizations.GetIAMPolicy.Invoke(new()
{
Bindings = new[]
{
new Gcp.Organizations.Inputs.GetIAMPolicyBindingInputArgs
{
Role = "roles/viewer",
Members = new[]
{
"user:jane@example.com",
},
},
},
});
var policy = new Gcp.Dns.DnsManagedZoneIamPolicy("policy", new()
{
Project = @default.Project,
ManagedZone = @default.Name,
PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.organizations.OrganizationsFunctions;
import com.pulumi.gcp.organizations.inputs.GetIAMPolicyArgs;
import com.pulumi.gcp.dns.DnsManagedZoneIamPolicy;
import com.pulumi.gcp.dns.DnsManagedZoneIamPolicyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var admin = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder()
.bindings(GetIAMPolicyBindingArgs.builder()
.role("roles/viewer")
.members("user:jane@example.com")
.build())
.build());
var policy = new DnsManagedZoneIamPolicy("policy", DnsManagedZoneIamPolicyArgs.builder()
.project(default_.project())
.managedZone(default_.name())
.policyData(admin.policyData())
.build());
}
}
resources:
policy:
type: gcp:dns:DnsManagedZoneIamPolicy
properties:
project: ${default.project}
managedZone: ${default.name}
policyData: ${admin.policyData}
variables:
admin:
fn::invoke:
function: gcp:organizations:getIAMPolicy
arguments:
bindings:
- role: roles/viewer
members:
- user:jane@example.com
The DnsManagedZoneIamPolicy resource replaces the entire IAM policy for the managed zone. The policyData comes from the getIAMPolicy data source, which defines bindings between roles and members. This approach is authoritative: it removes any permissions not explicitly listed. Use this when you want to ensure no unexpected access exists, but be aware it cannot coexist with DnsManagedZoneIamBinding or DnsManagedZoneIamMember resources on the same zone.
Grant a role to multiple members at once
When multiple users or service accounts need the same level of access, you can bind them all to a single role.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const binding = new gcp.dns.DnsManagedZoneIamBinding("binding", {
project: _default.project,
managedZone: _default.name,
role: "roles/viewer",
members: ["user:jane@example.com"],
});
import pulumi
import pulumi_gcp as gcp
binding = gcp.dns.DnsManagedZoneIamBinding("binding",
project=default["project"],
managed_zone=default["name"],
role="roles/viewer",
members=["user:jane@example.com"])
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/dns"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := dns.NewDnsManagedZoneIamBinding(ctx, "binding", &dns.DnsManagedZoneIamBindingArgs{
Project: pulumi.Any(_default.Project),
ManagedZone: pulumi.Any(_default.Name),
Role: pulumi.String("roles/viewer"),
Members: pulumi.StringArray{
pulumi.String("user:jane@example.com"),
},
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var binding = new Gcp.Dns.DnsManagedZoneIamBinding("binding", new()
{
Project = @default.Project,
ManagedZone = @default.Name,
Role = "roles/viewer",
Members = new[]
{
"user:jane@example.com",
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.dns.DnsManagedZoneIamBinding;
import com.pulumi.gcp.dns.DnsManagedZoneIamBindingArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var binding = new DnsManagedZoneIamBinding("binding", DnsManagedZoneIamBindingArgs.builder()
.project(default_.project())
.managedZone(default_.name())
.role("roles/viewer")
.members("user:jane@example.com")
.build());
}
}
resources:
binding:
type: gcp:dns:DnsManagedZoneIamBinding
properties:
project: ${default.project}
managedZone: ${default.name}
role: roles/viewer
members:
- user:jane@example.com
The DnsManagedZoneIamBinding resource is authoritative for a specific role: it replaces all members assigned to that role while preserving other role assignments on the zone. The members property accepts a list of identity strings in the format “user:email”, “serviceAccount:email”, or “group:email”. You can use multiple DnsManagedZoneIamBinding resources on the same zone as long as they manage different roles.
Add a single member to a role incrementally
When you need to grant access to one user without disturbing existing permissions, add individual members non-authoritatively.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const member = new gcp.dns.DnsManagedZoneIamMember("member", {
project: _default.project,
managedZone: _default.name,
role: "roles/viewer",
member: "user:jane@example.com",
});
import pulumi
import pulumi_gcp as gcp
member = gcp.dns.DnsManagedZoneIamMember("member",
project=default["project"],
managed_zone=default["name"],
role="roles/viewer",
member="user:jane@example.com")
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/dns"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := dns.NewDnsManagedZoneIamMember(ctx, "member", &dns.DnsManagedZoneIamMemberArgs{
Project: pulumi.Any(_default.Project),
ManagedZone: pulumi.Any(_default.Name),
Role: pulumi.String("roles/viewer"),
Member: pulumi.String("user:jane@example.com"),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var member = new Gcp.Dns.DnsManagedZoneIamMember("member", new()
{
Project = @default.Project,
ManagedZone = @default.Name,
Role = "roles/viewer",
Member = "user:jane@example.com",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.dns.DnsManagedZoneIamMember;
import com.pulumi.gcp.dns.DnsManagedZoneIamMemberArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var member = new DnsManagedZoneIamMember("member", DnsManagedZoneIamMemberArgs.builder()
.project(default_.project())
.managedZone(default_.name())
.role("roles/viewer")
.member("user:jane@example.com")
.build());
}
}
resources:
member:
type: gcp:dns:DnsManagedZoneIamMember
properties:
project: ${default.project}
managedZone: ${default.name}
role: roles/viewer
member: user:jane@example.com
The DnsManagedZoneIamMember resource adds a single member to a role without affecting other members who already have that role. This is the safest option when multiple teams manage access to the same zone, since it won’t overwrite permissions set elsewhere. The member property takes a single identity string. You can combine DnsManagedZoneIamMember resources with DnsManagedZoneIamBinding resources as long as they don’t grant the same role.
Beyond these examples
These snippets focus on specific IAM management features: authoritative vs non-authoritative IAM management, and policy-level, role-level, and member-level control. They’re intentionally minimal rather than full access control configurations.
The examples reference pre-existing infrastructure such as Cloud DNS managed zones and a GCP project with DNS API enabled. They focus on configuring IAM permissions rather than provisioning zones or DNS records.
To keep things focused, common IAM patterns are omitted, including:
- Conditional IAM bindings (conditions)
- Custom IAM roles
- Service account creation and management
- Managed zone creation and DNS record configuration
These omissions are intentional: the goal is to illustrate how each IAM resource type is wired, not provide drop-in access control modules. See the DNS Managed Zone IAM Policy resource reference for all available configuration options.
Let's manage GCP Cloud DNS IAM Policies
Get started with Pulumi Cloud, then follow our quick setup guide to deploy this infrastructure.
Try Pulumi Cloud for FREEFrequently Asked Questions
Resource Selection & Conflicts
gcp.dns.DnsManagedZoneIamPolicy cannot be used with gcp.dns.DnsManagedZoneIamBinding or gcp.dns.DnsManagedZoneIamMember because they will fight over the policy. Additionally, DnsManagedZoneIamBinding and DnsManagedZoneIamMember can only be used together if they don’t grant privileges to the same role.Choose based on your needs:
DnsManagedZoneIamPolicy- Authoritative control of the entire IAM policy (replaces any existing policy)DnsManagedZoneIamBinding- Authoritative for a specific role (preserves other roles in the policy)DnsManagedZoneIamMember- Non-authoritative addition of individual members (preserves other members for the role)
Configuration & Setup
gcp.organizations.getIAMPolicy data source to define your bindings, then pass its policyData output to the policyData property of gcp.dns.DnsManagedZoneIamPolicy.Import & Migration
[projects/my-project|organizations/my-org]/roles/my-custom-role when importing IAM resources with custom roles.