1. Packages
  2. Packages
  3. Consul Provider
  4. API Docs
  5. NamespaceRoleAttachment
Viewing docs for Consul v3.14.1
published on Monday, Mar 30, 2026 by Pulumi
consul logo
Viewing docs for Consul v3.14.1
published on Monday, Mar 30, 2026 by Pulumi

    NOTE: This feature requires Consul Enterprise.

    The consul.NamespaceRoleAttachment resource links a Consul Namespace and an ACL role. The link is implemented through an update to the Consul Namespace.

    NOTE: This resource is only useful to attach roles to a namespace that has been created outside the current Terraform configuration, like the default namespace. If the namespace you need to attach a role to has been created in the current Terraform configuration and will only be used in it, you should use the roleDefaults attribute of consul.Namespace.

    Example Usage

    Attach a role to the default namespace

    import * as pulumi from "@pulumi/pulumi";
    import * as consul from "@pulumi/consul";
    
    const agent = new consul.AclRole("agent", {name: "agent"});
    const attachment = new consul.NamespaceRoleAttachment("attachment", {
        namespace: "default",
        role: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclRole("agent", name="agent")
    attachment = consul.NamespaceRoleAttachment("attachment",
        namespace="default",
        role=agent.name)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-consul/sdk/v3/go/consul"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		agent, err := consul.NewAclRole(ctx, "agent", &consul.AclRoleArgs{
    			Name: pulumi.String("agent"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = consul.NewNamespaceRoleAttachment(ctx, "attachment", &consul.NamespaceRoleAttachmentArgs{
    			Namespace: pulumi.String("default"),
    			Role:      agent.Name,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() => 
    {
        var agent = new Consul.AclRole("agent", new()
        {
            Name = "agent",
        });
    
        var attachment = new Consul.NamespaceRoleAttachment("attachment", new()
        {
            Namespace = "default",
            Role = agent.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.AclRole;
    import com.pulumi.consul.AclRoleArgs;
    import com.pulumi.consul.NamespaceRoleAttachment;
    import com.pulumi.consul.NamespaceRoleAttachmentArgs;
    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 agent = new AclRole("agent", AclRoleArgs.builder()
                .name("agent")
                .build());
    
            var attachment = new NamespaceRoleAttachment("attachment", NamespaceRoleAttachmentArgs.builder()
                .namespace("default")
                .role(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclRole
        properties:
          name: agent
      attachment:
        type: consul:NamespaceRoleAttachment
        properties:
          namespace: default
          role: ${agent.name}
    

    Attach a role to a namespace created in another Terraform configuration

    In first_configuration/main.tf

    import * as pulumi from "@pulumi/pulumi";
    import * as consul from "@pulumi/consul";
    
    const qa = new consul.Namespace("qa", {name: "qa"});
    
    import pulumi
    import pulumi_consul as consul
    
    qa = consul.Namespace("qa", name="qa")
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-consul/sdk/v3/go/consul"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := consul.NewNamespace(ctx, "qa", &consul.NamespaceArgs{
    			Name: pulumi.String("qa"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() => 
    {
        var qa = new Consul.Namespace("qa", new()
        {
            Name = "qa",
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.Namespace;
    import com.pulumi.consul.NamespaceArgs;
    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 qa = new Namespace("qa", NamespaceArgs.builder()
                .name("qa")
                .build());
    
        }
    }
    
    resources:
      qa:
        type: consul:Namespace
        properties:
          name: qa
    

    In second_configuration/main.tf

    import * as pulumi from "@pulumi/pulumi";
    import * as consul from "@pulumi/consul";
    
    const agent = new consul.AclRole("agent", {name: "agent"});
    const attachment = new consul.NamespaceRoleAttachment("attachment", {
        namespace: "qa",
        role: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclRole("agent", name="agent")
    attachment = consul.NamespaceRoleAttachment("attachment",
        namespace="qa",
        role=agent.name)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-consul/sdk/v3/go/consul"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		agent, err := consul.NewAclRole(ctx, "agent", &consul.AclRoleArgs{
    			Name: pulumi.String("agent"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = consul.NewNamespaceRoleAttachment(ctx, "attachment", &consul.NamespaceRoleAttachmentArgs{
    			Namespace: pulumi.String("qa"),
    			Role:      agent.Name,
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Consul = Pulumi.Consul;
    
    return await Deployment.RunAsync(() => 
    {
        var agent = new Consul.AclRole("agent", new()
        {
            Name = "agent",
        });
    
        var attachment = new Consul.NamespaceRoleAttachment("attachment", new()
        {
            Namespace = "qa",
            Role = agent.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.AclRole;
    import com.pulumi.consul.AclRoleArgs;
    import com.pulumi.consul.NamespaceRoleAttachment;
    import com.pulumi.consul.NamespaceRoleAttachmentArgs;
    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 agent = new AclRole("agent", AclRoleArgs.builder()
                .name("agent")
                .build());
    
            var attachment = new NamespaceRoleAttachment("attachment", NamespaceRoleAttachmentArgs.builder()
                .namespace("qa")
                .role(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclRole
        properties:
          name: agent
      attachment:
        type: consul:NamespaceRoleAttachment
        properties:
          namespace: qa
          role: ${agent.name}
    

    NOTE: consulAclNamespace would attempt to enforce an empty set of default roles, because its roleDefaults attribute is empty. For this reason it is necessary to add the lifecycle clause to prevent Terraform from attempting to empty the set of policies associated to the namespace.

    Create NamespaceRoleAttachment Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new NamespaceRoleAttachment(name: string, args: NamespaceRoleAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def NamespaceRoleAttachment(resource_name: str,
                                args: NamespaceRoleAttachmentArgs,
                                opts: Optional[ResourceOptions] = None)
    
    @overload
    def NamespaceRoleAttachment(resource_name: str,
                                opts: Optional[ResourceOptions] = None,
                                namespace: Optional[str] = None,
                                role: Optional[str] = None)
    func NewNamespaceRoleAttachment(ctx *Context, name string, args NamespaceRoleAttachmentArgs, opts ...ResourceOption) (*NamespaceRoleAttachment, error)
    public NamespaceRoleAttachment(string name, NamespaceRoleAttachmentArgs args, CustomResourceOptions? opts = null)
    public NamespaceRoleAttachment(String name, NamespaceRoleAttachmentArgs args)
    public NamespaceRoleAttachment(String name, NamespaceRoleAttachmentArgs args, CustomResourceOptions options)
    
    type: consul:NamespaceRoleAttachment
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args NamespaceRoleAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args NamespaceRoleAttachmentArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args NamespaceRoleAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args NamespaceRoleAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args NamespaceRoleAttachmentArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var namespaceRoleAttachmentResource = new Consul.NamespaceRoleAttachment("namespaceRoleAttachmentResource", new()
    {
        Namespace = "string",
        Role = "string",
    });
    
    example, err := consul.NewNamespaceRoleAttachment(ctx, "namespaceRoleAttachmentResource", &consul.NamespaceRoleAttachmentArgs{
    	Namespace: pulumi.String("string"),
    	Role:      pulumi.String("string"),
    })
    
    var namespaceRoleAttachmentResource = new NamespaceRoleAttachment("namespaceRoleAttachmentResource", NamespaceRoleAttachmentArgs.builder()
        .namespace("string")
        .role("string")
        .build());
    
    namespace_role_attachment_resource = consul.NamespaceRoleAttachment("namespaceRoleAttachmentResource",
        namespace="string",
        role="string")
    
    const namespaceRoleAttachmentResource = new consul.NamespaceRoleAttachment("namespaceRoleAttachmentResource", {
        namespace: "string",
        role: "string",
    });
    
    type: consul:NamespaceRoleAttachment
    properties:
        namespace: string
        role: string
    

    NamespaceRoleAttachment Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The NamespaceRoleAttachment resource accepts the following input properties:

    Namespace string
    The namespace to attach the role to.
    Role string
    The name of the role attached to the namespace.
    Namespace string
    The namespace to attach the role to.
    Role string
    The name of the role attached to the namespace.
    namespace String
    The namespace to attach the role to.
    role String
    The name of the role attached to the namespace.
    namespace string
    The namespace to attach the role to.
    role string
    The name of the role attached to the namespace.
    namespace str
    The namespace to attach the role to.
    role str
    The name of the role attached to the namespace.
    namespace String
    The namespace to attach the role to.
    role String
    The name of the role attached to the namespace.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the NamespaceRoleAttachment resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing NamespaceRoleAttachment Resource

    Get an existing NamespaceRoleAttachment resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: NamespaceRoleAttachmentState, opts?: CustomResourceOptions): NamespaceRoleAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            namespace: Optional[str] = None,
            role: Optional[str] = None) -> NamespaceRoleAttachment
    func GetNamespaceRoleAttachment(ctx *Context, name string, id IDInput, state *NamespaceRoleAttachmentState, opts ...ResourceOption) (*NamespaceRoleAttachment, error)
    public static NamespaceRoleAttachment Get(string name, Input<string> id, NamespaceRoleAttachmentState? state, CustomResourceOptions? opts = null)
    public static NamespaceRoleAttachment get(String name, Output<String> id, NamespaceRoleAttachmentState state, CustomResourceOptions options)
    resources:  _:    type: consul:NamespaceRoleAttachment    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Namespace string
    The namespace to attach the role to.
    Role string
    The name of the role attached to the namespace.
    Namespace string
    The namespace to attach the role to.
    Role string
    The name of the role attached to the namespace.
    namespace String
    The namespace to attach the role to.
    role String
    The name of the role attached to the namespace.
    namespace string
    The namespace to attach the role to.
    role string
    The name of the role attached to the namespace.
    namespace str
    The namespace to attach the role to.
    role str
    The name of the role attached to the namespace.
    namespace String
    The namespace to attach the role to.
    role String
    The name of the role attached to the namespace.

    Import

    consul.NamespaceRoleAttachment can be imported. This is especially useful to manage the policies attached to the default namespace:

    $ pulumi import consul:index/namespaceRoleAttachment:NamespaceRoleAttachment default default:role_name
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    HashiCorp Consul pulumi/pulumi-consul
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the consul Terraform Provider.
    consul logo
    Viewing docs for Consul v3.14.1
    published on Monday, Mar 30, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.