1. Packages
  2. Packages
  3. Consul Provider
  4. API Docs
  5. AclTokenPolicyAttachment
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

    The consul.AclTokenPolicyAttachment resource links a Consul Token and an ACL policy. The link is implemented through an update to the Consul ACL token.

    NOTE: This resource is only useful to attach policies to an ACL token that has been created outside the current Terraform configuration, like the anonymous or the master token. If the token 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 policies attribute of consul.AclToken.

    Example Usage

    Attach a policy to the anonymous token

    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.AclTokenPolicyAttachment("attachment", {
        tokenId: "00000000-0000-0000-0000-000000000002",
        policy: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclPolicy("agent",
        name="agent",
        rules="""node_prefix \"\" {
      policy = \"read\"
    }
    """)
    attachment = consul.AclTokenPolicyAttachment("attachment",
        token_id="00000000-0000-0000-0000-000000000002",
        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.NewAclTokenPolicyAttachment(ctx, "attachment", &consul.AclTokenPolicyAttachmentArgs{
    			TokenId: pulumi.String("00000000-0000-0000-0000-000000000002"),
    			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.AclTokenPolicyAttachment("attachment", new()
        {
            TokenId = "00000000-0000-0000-0000-000000000002",
            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.AclTokenPolicyAttachment;
    import com.pulumi.consul.AclTokenPolicyAttachmentArgs;
    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 AclTokenPolicyAttachment("attachment", AclTokenPolicyAttachmentArgs.builder()
                .tokenId("00000000-0000-0000-0000-000000000002")
                .policy(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclPolicy
        properties:
          name: agent
          rules: |
            node_prefix \"\" {
              policy = \"read\"
            }
      attachment:
        type: consul:AclTokenPolicyAttachment
        properties:
          tokenId: 00000000-0000-0000-0000-000000000002
          policy: ${agent.name}
    

    Attach a policy to a token created in another Terraform configuration

    In first_configuration/main.tf

    import * as pulumi from "@pulumi/pulumi";
    import * as consul from "@pulumi/consul";
    
    const test = new consul.AclToken("test", {
        accessorId: "9b20de68-3ea2-4b70-b4f1-506afad062a4",
        description: "my test token",
        local: true,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    test = consul.AclToken("test",
        accessor_id="9b20de68-3ea2-4b70-b4f1-506afad062a4",
        description="my test token",
        local=True)
    
    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.NewAclToken(ctx, "test", &consul.AclTokenArgs{
    			AccessorId:  pulumi.String("9b20de68-3ea2-4b70-b4f1-506afad062a4"),
    			Description: pulumi.String("my test token"),
    			Local:       pulumi.Bool(true),
    		})
    		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 test = new Consul.AclToken("test", new()
        {
            AccessorId = "9b20de68-3ea2-4b70-b4f1-506afad062a4",
            Description = "my test token",
            Local = true,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.consul.AclToken;
    import com.pulumi.consul.AclTokenArgs;
    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 test = new AclToken("test", AclTokenArgs.builder()
                .accessorId("9b20de68-3ea2-4b70-b4f1-506afad062a4")
                .description("my test token")
                .local(true)
                .build());
    
        }
    }
    
    resources:
      test:
        type: consul:AclToken
        properties:
          accessorId: 9b20de68-3ea2-4b70-b4f1-506afad062a4
          description: my test token
          local: true
    

    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.AclTokenPolicyAttachment("attachment", {
        tokenId: "9b20de68-3ea2-4b70-b4f1-506afad062a4",
        policy: agent.name,
    });
    
    import pulumi
    import pulumi_consul as consul
    
    agent = consul.AclPolicy("agent",
        name="agent",
        rules="""node_prefix \"\" {
      policy = \"read\"
    }
    """)
    attachment = consul.AclTokenPolicyAttachment("attachment",
        token_id="9b20de68-3ea2-4b70-b4f1-506afad062a4",
        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.NewAclTokenPolicyAttachment(ctx, "attachment", &consul.AclTokenPolicyAttachmentArgs{
    			TokenId: pulumi.String("9b20de68-3ea2-4b70-b4f1-506afad062a4"),
    			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.AclTokenPolicyAttachment("attachment", new()
        {
            TokenId = "9b20de68-3ea2-4b70-b4f1-506afad062a4",
            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.AclTokenPolicyAttachment;
    import com.pulumi.consul.AclTokenPolicyAttachmentArgs;
    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 AclTokenPolicyAttachment("attachment", AclTokenPolicyAttachmentArgs.builder()
                .tokenId("9b20de68-3ea2-4b70-b4f1-506afad062a4")
                .policy(agent.name())
                .build());
    
        }
    }
    
    resources:
      agent:
        type: consul:AclPolicy
        properties:
          name: agent
          rules: |
            node_prefix \"\" {
              policy = \"read\"
            }
      attachment:
        type: consul:AclTokenPolicyAttachment
        properties:
          tokenId: 9b20de68-3ea2-4b70-b4f1-506afad062a4
          policy: ${agent.name}
    

    NOTE: consul.AclToken would attempt to enforce an empty set of policies, because its policies 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 token.

    Create AclTokenPolicyAttachment Resource

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

    Constructor syntax

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

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

    Policy string
    The name of the policy attached to the token.
    TokenId string
    The id of the token.
    Policy string
    The name of the policy attached to the token.
    TokenId string
    The id of the token.
    policy String
    The name of the policy attached to the token.
    tokenId String
    The id of the token.
    policy string
    The name of the policy attached to the token.
    tokenId string
    The id of the token.
    policy str
    The name of the policy attached to the token.
    token_id str
    The id of the token.
    policy String
    The name of the policy attached to the token.
    tokenId String
    The id of the token.

    Outputs

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

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

    Import

    consul.AclTokenPolicyAttachment can be imported. This is especially useful to manage the policies attached to the anonymous and the master tokens with Terraform:

    $ pulumi import consul:index/aclTokenPolicyAttachment:AclTokenPolicyAttachment anonymous 00000000-0000-0000-0000-000000000002:policy_name
    $ pulumi import consul:index/aclTokenPolicyAttachment:AclTokenPolicyAttachment master-token 624d94ca-bc5c-f960-4e83-0a609cf588be: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.