published on Monday, Mar 30, 2026 by Pulumi
published on Monday, Mar 30, 2026 by Pulumi
The consul.AclTokenRoleAttachment resource links a Consul Token and an ACL
role. The link is implemented through an update to the Consul ACL token.
NOTE: This resource is only useful to attach roles 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
rolesattribute ofconsul.AclToken.
Example Usage
Attach a role to the anonymous token
import * as pulumi from "@pulumi/pulumi";
import * as consul from "@pulumi/consul";
const role = new consul.AclRole("role", {
name: "foo",
description: "Foo",
serviceIdentities: [{
serviceName: "foo",
}],
});
const attachment = new consul.AclTokenRoleAttachment("attachment", {
tokenId: "00000000-0000-0000-0000-000000000002",
roleId: role.id,
});
import pulumi
import pulumi_consul as consul
role = consul.AclRole("role",
name="foo",
description="Foo",
service_identities=[{
"service_name": "foo",
}])
attachment = consul.AclTokenRoleAttachment("attachment",
token_id="00000000-0000-0000-0000-000000000002",
role_id=role.id)
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 {
role, err := consul.NewAclRole(ctx, "role", &consul.AclRoleArgs{
Name: pulumi.String("foo"),
Description: pulumi.String("Foo"),
ServiceIdentities: consul.AclRoleServiceIdentityArray{
&consul.AclRoleServiceIdentityArgs{
ServiceName: pulumi.String("foo"),
},
},
})
if err != nil {
return err
}
_, err = consul.NewAclTokenRoleAttachment(ctx, "attachment", &consul.AclTokenRoleAttachmentArgs{
TokenId: pulumi.String("00000000-0000-0000-0000-000000000002"),
RoleId: role.ID(),
})
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 role = new Consul.AclRole("role", new()
{
Name = "foo",
Description = "Foo",
ServiceIdentities = new[]
{
new Consul.Inputs.AclRoleServiceIdentityArgs
{
ServiceName = "foo",
},
},
});
var attachment = new Consul.AclTokenRoleAttachment("attachment", new()
{
TokenId = "00000000-0000-0000-0000-000000000002",
RoleId = role.Id,
});
});
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.inputs.AclRoleServiceIdentityArgs;
import com.pulumi.consul.AclTokenRoleAttachment;
import com.pulumi.consul.AclTokenRoleAttachmentArgs;
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 role = new AclRole("role", AclRoleArgs.builder()
.name("foo")
.description("Foo")
.serviceIdentities(AclRoleServiceIdentityArgs.builder()
.serviceName("foo")
.build())
.build());
var attachment = new AclTokenRoleAttachment("attachment", AclTokenRoleAttachmentArgs.builder()
.tokenId("00000000-0000-0000-0000-000000000002")
.roleId(role.id())
.build());
}
}
resources:
role:
type: consul:AclRole
properties:
name: foo
description: Foo
serviceIdentities:
- serviceName: foo
attachment:
type: consul:AclTokenRoleAttachment
properties:
tokenId: 00000000-0000-0000-0000-000000000002
roleId: ${role.id}
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: "5914ee49-eb8d-4837-9767-9299ec155000",
description: "my test token",
local: true,
});
import pulumi
import pulumi_consul as consul
test = consul.AclToken("test",
accessor_id="5914ee49-eb8d-4837-9767-9299ec155000",
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("5914ee49-eb8d-4837-9767-9299ec155000"),
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 = "5914ee49-eb8d-4837-9767-9299ec155000",
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("5914ee49-eb8d-4837-9767-9299ec155000")
.description("my test token")
.local(true)
.build());
}
}
resources:
test:
type: consul:AclToken
properties:
accessorId: 5914ee49-eb8d-4837-9767-9299ec155000
description: my test token
local: true
In second_configuration/main.tf
import * as pulumi from "@pulumi/pulumi";
import * as consul from "@pulumi/consul";
const role = new consul.AclRole("role", {
name: "foo",
description: "Foo",
serviceIdentities: [{
serviceName: "foo",
}],
});
const attachment = new consul.AclTokenRoleAttachment("attachment", {
tokenId: "00000000-0000-0000-0000-000000000002",
roleId: role.id,
});
import pulumi
import pulumi_consul as consul
role = consul.AclRole("role",
name="foo",
description="Foo",
service_identities=[{
"service_name": "foo",
}])
attachment = consul.AclTokenRoleAttachment("attachment",
token_id="00000000-0000-0000-0000-000000000002",
role_id=role.id)
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 {
role, err := consul.NewAclRole(ctx, "role", &consul.AclRoleArgs{
Name: pulumi.String("foo"),
Description: pulumi.String("Foo"),
ServiceIdentities: consul.AclRoleServiceIdentityArray{
&consul.AclRoleServiceIdentityArgs{
ServiceName: pulumi.String("foo"),
},
},
})
if err != nil {
return err
}
_, err = consul.NewAclTokenRoleAttachment(ctx, "attachment", &consul.AclTokenRoleAttachmentArgs{
TokenId: pulumi.String("00000000-0000-0000-0000-000000000002"),
RoleId: role.ID(),
})
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 role = new Consul.AclRole("role", new()
{
Name = "foo",
Description = "Foo",
ServiceIdentities = new[]
{
new Consul.Inputs.AclRoleServiceIdentityArgs
{
ServiceName = "foo",
},
},
});
var attachment = new Consul.AclTokenRoleAttachment("attachment", new()
{
TokenId = "00000000-0000-0000-0000-000000000002",
RoleId = role.Id,
});
});
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.inputs.AclRoleServiceIdentityArgs;
import com.pulumi.consul.AclTokenRoleAttachment;
import com.pulumi.consul.AclTokenRoleAttachmentArgs;
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 role = new AclRole("role", AclRoleArgs.builder()
.name("foo")
.description("Foo")
.serviceIdentities(AclRoleServiceIdentityArgs.builder()
.serviceName("foo")
.build())
.build());
var attachment = new AclTokenRoleAttachment("attachment", AclTokenRoleAttachmentArgs.builder()
.tokenId("00000000-0000-0000-0000-000000000002")
.roleId(role.id())
.build());
}
}
resources:
role:
type: consul:AclRole
properties:
name: foo
description: Foo
serviceIdentities:
- serviceName: foo
attachment:
type: consul:AclTokenRoleAttachment
properties:
tokenId: 00000000-0000-0000-0000-000000000002
roleId: ${role.id}
NOTE: consul.AclToken would attempt to enforce an empty set of roles,
because its roles attribute is empty. For this reason it is necessary to add
the lifecycle clause to prevent Terraform from attempting to clear the set of
roles associated to the token.
Create AclTokenRoleAttachment Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new AclTokenRoleAttachment(name: string, args: AclTokenRoleAttachmentArgs, opts?: CustomResourceOptions);@overload
def AclTokenRoleAttachment(resource_name: str,
args: AclTokenRoleAttachmentArgs,
opts: Optional[ResourceOptions] = None)
@overload
def AclTokenRoleAttachment(resource_name: str,
opts: Optional[ResourceOptions] = None,
role: Optional[str] = None,
token_id: Optional[str] = None)func NewAclTokenRoleAttachment(ctx *Context, name string, args AclTokenRoleAttachmentArgs, opts ...ResourceOption) (*AclTokenRoleAttachment, error)public AclTokenRoleAttachment(string name, AclTokenRoleAttachmentArgs args, CustomResourceOptions? opts = null)
public AclTokenRoleAttachment(String name, AclTokenRoleAttachmentArgs args)
public AclTokenRoleAttachment(String name, AclTokenRoleAttachmentArgs args, CustomResourceOptions options)
type: consul:AclTokenRoleAttachment
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 AclTokenRoleAttachmentArgs
- 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 AclTokenRoleAttachmentArgs
- 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 AclTokenRoleAttachmentArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args AclTokenRoleAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args AclTokenRoleAttachmentArgs
- 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 aclTokenRoleAttachmentResource = new Consul.AclTokenRoleAttachment("aclTokenRoleAttachmentResource", new()
{
Role = "string",
TokenId = "string",
});
example, err := consul.NewAclTokenRoleAttachment(ctx, "aclTokenRoleAttachmentResource", &consul.AclTokenRoleAttachmentArgs{
Role: pulumi.String("string"),
TokenId: pulumi.String("string"),
})
var aclTokenRoleAttachmentResource = new AclTokenRoleAttachment("aclTokenRoleAttachmentResource", AclTokenRoleAttachmentArgs.builder()
.role("string")
.tokenId("string")
.build());
acl_token_role_attachment_resource = consul.AclTokenRoleAttachment("aclTokenRoleAttachmentResource",
role="string",
token_id="string")
const aclTokenRoleAttachmentResource = new consul.AclTokenRoleAttachment("aclTokenRoleAttachmentResource", {
role: "string",
tokenId: "string",
});
type: consul:AclTokenRoleAttachment
properties:
role: string
tokenId: string
AclTokenRoleAttachment 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 AclTokenRoleAttachment resource accepts the following input properties:
Outputs
All input properties are implicitly available as output properties. Additionally, the AclTokenRoleAttachment 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 AclTokenRoleAttachment Resource
Get an existing AclTokenRoleAttachment 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?: AclTokenRoleAttachmentState, opts?: CustomResourceOptions): AclTokenRoleAttachment@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
role: Optional[str] = None,
token_id: Optional[str] = None) -> AclTokenRoleAttachmentfunc GetAclTokenRoleAttachment(ctx *Context, name string, id IDInput, state *AclTokenRoleAttachmentState, opts ...ResourceOption) (*AclTokenRoleAttachment, error)public static AclTokenRoleAttachment Get(string name, Input<string> id, AclTokenRoleAttachmentState? state, CustomResourceOptions? opts = null)public static AclTokenRoleAttachment get(String name, Output<String> id, AclTokenRoleAttachmentState state, CustomResourceOptions options)resources: _: type: consul:AclTokenRoleAttachment 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.
Import
consul.AclTokenRoleAttachment 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/aclTokenRoleAttachment:AclTokenRoleAttachment anonymous token_id:role_id
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
consulTerraform Provider.
published on Monday, Mar 30, 2026 by Pulumi
