1. Packages
  2. Packages
  3. Consul Provider
  4. API Docs
  5. NamespacePolicyAttachment
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.NamespacePolicyAttachment resource links a Consul Namespace and an ACL policy. The link is implemented through an update to the Consul Namespace.

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

    Example Usage

    Attach a policy to the default namespace

    import * as pulumi from "@pulumi/pulumi";
    import * as consul from "@pulumi/consul";
    
    const agent = new consul.AclPolicy("agent", {
        name: "agent",
        rules: `node_prefix \\"\\" {
      policy = \\"read\\"
    }
    `,
    });
    const attachment = new consul.NamespacePolicyAttachment("attachment", {
        namespace: "default",
        policy: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclPolicy("agent",
        name="agent",
        rules="""node_prefix \"\" {
      policy = \"read\"
    }
    """)
    attachment = consul.NamespacePolicyAttachment("attachment",
        namespace="default",
        policy=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.NewAclPolicy(ctx, "agent", &consul.AclPolicyArgs{
    			Name:  pulumi.String("agent"),
    			Rules: pulumi.String("node_prefix \\\"\\\" {\n  policy = \\\"read\\\"\n}\n"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = consul.NewNamespacePolicyAttachment(ctx, "attachment", &consul.NamespacePolicyAttachmentArgs{
    			Namespace: pulumi.String("default"),
    			Policy:    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.AclPolicy("agent", new()
        {
            Name = "agent",
            Rules = @"node_prefix \""\"" {
      policy = \""read\""
    }
    ",
        });
    
        var attachment = new Consul.NamespacePolicyAttachment("attachment", new()
        {
            Namespace = "default",
            Policy = agent.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.AclPolicy;
    import com.pulumi.consul.AclPolicyArgs;
    import com.pulumi.consul.NamespacePolicyAttachment;
    import com.pulumi.consul.NamespacePolicyAttachmentArgs;
    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 AclPolicy("agent", AclPolicyArgs.builder()
                .name("agent")
                .rules("""
    node_prefix \"\" {
      policy = \"read\"
    }
                """)
                .build());
    
            var attachment = new NamespacePolicyAttachment("attachment", NamespacePolicyAttachmentArgs.builder()
                .namespace("default")
                .policy(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclPolicy
        properties:
          name: agent
          rules: |
            node_prefix \"\" {
              policy = \"read\"
            }
      attachment:
        type: consul:NamespacePolicyAttachment
        properties:
          namespace: default
          policy: ${agent.name}
    

    Attach a policy 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.AclPolicy("agent", {
        name: "agent",
        rules: `node_prefix \\"\\" {
      policy = \\"read\\"
    }
    `,
    });
    const attachment = new consul.NamespacePolicyAttachment("attachment", {
        namespace: "qa",
        policy: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclPolicy("agent",
        name="agent",
        rules="""node_prefix \"\" {
      policy = \"read\"
    }
    """)
    attachment = consul.NamespacePolicyAttachment("attachment",
        namespace="qa",
        policy=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.NewAclPolicy(ctx, "agent", &consul.AclPolicyArgs{
    			Name:  pulumi.String("agent"),
    			Rules: pulumi.String("node_prefix \\\"\\\" {\n  policy = \\\"read\\\"\n}\n"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = consul.NewNamespacePolicyAttachment(ctx, "attachment", &consul.NamespacePolicyAttachmentArgs{
    			Namespace: pulumi.String("qa"),
    			Policy:    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.AclPolicy("agent", new()
        {
            Name = "agent",
            Rules = @"node_prefix \""\"" {
      policy = \""read\""
    }
    ",
        });
    
        var attachment = new Consul.NamespacePolicyAttachment("attachment", new()
        {
            Namespace = "qa",
            Policy = agent.Name,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.AclPolicy;
    import com.pulumi.consul.AclPolicyArgs;
    import com.pulumi.consul.NamespacePolicyAttachment;
    import com.pulumi.consul.NamespacePolicyAttachmentArgs;
    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 AclPolicy("agent", AclPolicyArgs.builder()
                .name("agent")
                .rules("""
    node_prefix \"\" {
      policy = \"read\"
    }
                """)
                .build());
    
            var attachment = new NamespacePolicyAttachment("attachment", NamespacePolicyAttachmentArgs.builder()
                .namespace("qa")
                .policy(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclPolicy
        properties:
          name: agent
          rules: |
            node_prefix \"\" {
              policy = \"read\"
            }
      attachment:
        type: consul:NamespacePolicyAttachment
        properties:
          namespace: qa
          policy: ${agent.name}
    

    NOTE: consulAclNamespace would attempt to enforce an empty set of default policies, because its policyDefaults 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 NamespacePolicyAttachment Resource

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

    Constructor syntax

    new NamespacePolicyAttachment(name: string, args: NamespacePolicyAttachmentArgs, opts?: CustomResourceOptions);
    @overload
    def NamespacePolicyAttachment(resource_name: str,
                                  args: NamespacePolicyAttachmentArgs,
                                  opts: Optional[ResourceOptions] = None)
    
    @overload
    def NamespacePolicyAttachment(resource_name: str,
                                  opts: Optional[ResourceOptions] = None,
                                  namespace: Optional[str] = None,
                                  policy: Optional[str] = None)
    func NewNamespacePolicyAttachment(ctx *Context, name string, args NamespacePolicyAttachmentArgs, opts ...ResourceOption) (*NamespacePolicyAttachment, error)
    public NamespacePolicyAttachment(string name, NamespacePolicyAttachmentArgs args, CustomResourceOptions? opts = null)
    public NamespacePolicyAttachment(String name, NamespacePolicyAttachmentArgs args)
    public NamespacePolicyAttachment(String name, NamespacePolicyAttachmentArgs args, CustomResourceOptions options)
    
    type: consul:NamespacePolicyAttachment
    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 NamespacePolicyAttachmentArgs
    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 NamespacePolicyAttachmentArgs
    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 NamespacePolicyAttachmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args NamespacePolicyAttachmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args NamespacePolicyAttachmentArgs
    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 namespacePolicyAttachmentResource = new Consul.NamespacePolicyAttachment("namespacePolicyAttachmentResource", new()
    {
        Namespace = "string",
        Policy = "string",
    });
    
    example, err := consul.NewNamespacePolicyAttachment(ctx, "namespacePolicyAttachmentResource", &consul.NamespacePolicyAttachmentArgs{
    	Namespace: pulumi.String("string"),
    	Policy:    pulumi.String("string"),
    })
    
    var namespacePolicyAttachmentResource = new NamespacePolicyAttachment("namespacePolicyAttachmentResource", NamespacePolicyAttachmentArgs.builder()
        .namespace("string")
        .policy("string")
        .build());
    
    namespace_policy_attachment_resource = consul.NamespacePolicyAttachment("namespacePolicyAttachmentResource",
        namespace="string",
        policy="string")
    
    const namespacePolicyAttachmentResource = new consul.NamespacePolicyAttachment("namespacePolicyAttachmentResource", {
        namespace: "string",
        policy: "string",
    });
    
    type: consul:NamespacePolicyAttachment
    properties:
        namespace: string
        policy: string
    

    NamespacePolicyAttachment 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 NamespacePolicyAttachment resource accepts the following input properties:

    Namespace string
    The namespace to attach the policy to.
    Policy string
    The name of the policy attached to the namespace.
    Namespace string
    The namespace to attach the policy to.
    Policy string
    The name of the policy attached to the namespace.
    namespace String
    The namespace to attach the policy to.
    policy String
    The name of the policy attached to the namespace.
    namespace string
    The namespace to attach the policy to.
    policy string
    The name of the policy attached to the namespace.
    namespace str
    The namespace to attach the policy to.
    policy str
    The name of the policy attached to the namespace.
    namespace String
    The namespace to attach the policy to.
    policy String
    The name of the policy attached to the namespace.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the NamespacePolicyAttachment 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 NamespacePolicyAttachment Resource

    Get an existing NamespacePolicyAttachment 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?: NamespacePolicyAttachmentState, opts?: CustomResourceOptions): NamespacePolicyAttachment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            namespace: Optional[str] = None,
            policy: Optional[str] = None) -> NamespacePolicyAttachment
    func GetNamespacePolicyAttachment(ctx *Context, name string, id IDInput, state *NamespacePolicyAttachmentState, opts ...ResourceOption) (*NamespacePolicyAttachment, error)
    public static NamespacePolicyAttachment Get(string name, Input<string> id, NamespacePolicyAttachmentState? state, CustomResourceOptions? opts = null)
    public static NamespacePolicyAttachment get(String name, Output<String> id, NamespacePolicyAttachmentState state, CustomResourceOptions options)
    resources:  _:    type: consul:NamespacePolicyAttachment    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 policy to.
    Policy string
    The name of the policy attached to the namespace.
    Namespace string
    The namespace to attach the policy to.
    Policy string
    The name of the policy attached to the namespace.
    namespace String
    The namespace to attach the policy to.
    policy String
    The name of the policy attached to the namespace.
    namespace string
    The namespace to attach the policy to.
    policy string
    The name of the policy attached to the namespace.
    namespace str
    The namespace to attach the policy to.
    policy str
    The name of the policy attached to the namespace.
    namespace String
    The namespace to attach the policy to.
    policy String
    The name of the policy attached to the namespace.

    Import

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

    $ pulumi import consul:index/namespacePolicyAttachment:NamespacePolicyAttachment default default:policy_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.