Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support partitioned tokens in ACL secret id data source #315

Merged
merged 3 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 2.15.1 (Unreleased)

IMPROVEMENTS:

* The `consul_acl_token_secret` datasource now supports reading tokens in a Consul Admin Partition ([#315](https://github.com/hashicorp/terraform-provider-consul/pull/315)).

BUG FIXES:

* The support of Admin Partition has been fixed for `consul_config_entry`: a new `partition` argument is now present and should be used instead of setting `Partition` in `config_json`.
Expand Down
5 changes: 5 additions & 0 deletions consul/data_source_consul_acl_token_secret_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func dataSourceConsulACLTokenSecretID() *schema.Resource {
Optional: true,
},

"partition": {
Type: schema.TypeString,
Optional: true,
},

// Out parameters
"secret_id": {
Type: schema.TypeString,
Expand Down
67 changes: 67 additions & 0 deletions consul/data_source_consul_acl_token_secret_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ func TestAccDataACLTokenSecretID_namespaceEE(t *testing.T) {
})
}

func TestAccDataACLTokenSecretID_partitionCE(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
Providers: providers,
PreCheck: func() { skipTestOnConsulEnterpriseEdition(t) },
Steps: []resource.TestStep{
{
Config: testAccDataACLTokenSecretIDConfigPartitionCE,
ExpectError: regexp.MustCompile("(?i)Consul Enterprise feature"),
},
},
})
}

func TestAccDataACLTokenSecretID_partitionEE(t *testing.T) {
providers, _ := startTestServer(t)

resource.Test(t, resource.TestCase{
Providers: providers,
PreCheck: func() { skipTestOnConsulCommunityEdition(t) },
Steps: []resource.TestStep{
{
Config: testAccDataACLTokenSecretIDConfigPartitionEE,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.consul_acl_token_secret_id.read", "pgp_key", ""),
resource.TestCheckResourceAttr("data.consul_acl_token_secret_id.read", "encrypted_secret_id", ""),
resource.TestCheckResourceAttr("data.consul_acl_token_secret_id.read", "partition", "test-data-token-secret"),
testAccCheckTokenExistsAndValidUUID("data.consul_acl_token_secret_id.read", "secret_id"),
),
},
},
})
}

func TestAccDataACLTokenSecretID_PGP(t *testing.T) {
providers, _ := startTestServer(t)

Expand Down Expand Up @@ -163,3 +198,35 @@ data "consul_acl_token_secret_id" "read" {
namespace = consul_namespace.test.name
}
`

const testAccDataACLTokenSecretIDConfigPartitionCE = `
data "consul_acl_token" "read" {
accessor_id = "foo"
partition = "test-data-token"
}
`

const testAccDataACLTokenSecretIDConfigPartitionEE = `
resource "consul_admin_partition" "test" {
name = "test-data-token-secret"
}

resource "consul_acl_policy" "test" {
name = "test-data-token-secret"
rules = "node \"\" { policy = \"read\" }"
datacenters = [ "dc1" ]
partition = consul_admin_partition.test.name
}

resource "consul_acl_token" "test" {
description = "test"
policies = [consul_acl_policy.test.name]
local = true
partition = consul_admin_partition.test.name
}

data "consul_acl_token_secret_id" "read" {
accessor_id = consul_acl_token.test.id
partition = consul_admin_partition.test.name
}
`
1 change: 1 addition & 0 deletions website/docs/d/acl_token_secret_id.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ The following arguments are supported:

* `accessor_id` - (Required) The accessor ID of the ACL token.
* `namespace` - (Optional, Enterprise Only) The namespace to lookup the token.
* `partition` - (Optional, Enterprise Only) The partition to lookup the token.
* `pgp_key` - (Optional) Either a base-64 encoded PGP public key, or a keybase
username in the form `keybase:some_person_that_exists`. **If you do not set this
argument, the token secret ID will be written as plain text in the Terraform
Expand Down