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

prepared query: add missing RemoveEmptyTag and Name should be optional #312

Merged
merged 4 commits into from
Jul 24, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions consul/resource_consul_prepared_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ Managing prepared queries is done using Consul's REST API. This resource is usef
Required: true,
Description: "The regular expression to match with. When using `name_prefix_match`, this regex is applied against the query name.",
},
"remove_empty_tags": {
Type: schema.TypeBool,
Optional: true,
Description: "If set to true, will cause the tags list inside the service structure to be stripped of any empty strings.",
},
},
},
},
Expand Down Expand Up @@ -295,8 +300,9 @@ func resourceConsulPreparedQueryRead(d *schema.ResourceData, meta interface{}) e

if userWroteTemplate || pq.Template.Type != "" {
template = append(template, map[string]interface{}{
"type": pq.Template.Type,
"regexp": pq.Template.Regexp,
"type": pq.Template.Type,
"regexp": pq.Template.Regexp,
"remove_empty_tags": pq.Template.RemoveEmptyTags,
})
}
sw.set("template", template)
Expand Down Expand Up @@ -377,8 +383,9 @@ func preparedQueryDefinitionFromResourceData(d *schema.ResourceData) *consulapi.

if _, ok := d.GetOk("template.0"); ok {
pq.Template = consulapi.QueryTemplate{
Type: d.Get("template.0.type").(string),
Regexp: d.Get("template.0.regexp").(string),
Type: d.Get("template.0.type").(string),
Regexp: d.Get("template.0.regexp").(string),
RemoveEmptyTags: d.Get("template.0.remove_empty_tags").(bool),
}
}

Expand Down
6 changes: 4 additions & 2 deletions consul/resource_consul_prepared_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAccConsulPreparedQuery_basic(t *testing.T) {
resource.TestCheckResourceAttr("consul_prepared_query.foo", "failover.0.datacenters.#", "2"),
resource.TestCheckResourceAttr("consul_prepared_query.foo", "template.0.type", "name_prefix_match"),
resource.TestCheckResourceAttr("consul_prepared_query.foo", "template.0.regexp", "hello"),
resource.TestCheckResourceAttr("consul_prepared_query.foo", "template.0.remove_empty_tags", "true"),
resource.TestCheckResourceAttr("consul_prepared_query.foo", "dns.0.ttl", "8m"),
),
},
Expand Down Expand Up @@ -305,8 +306,9 @@ resource "consul_prepared_query" "foo" {
}

template {
type = "name_prefix_match"
regexp = "hello"
type = "name_prefix_match"
regexp = "hello"
remove_empty_tags = true
}

dns {
Expand Down
37 changes: 37 additions & 0 deletions docs/resources/certificate_authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,44 @@ The `consul_certificate_authority` resource can be used to manage the configurat

-> **Note:** The keys in the `config` argument must be using Camel case.

## Example Usage

```terraform
# Using the built-in CA with specific TTL
resource "consul_certificate_authority" "connect" {
connect_provider = "consul"

config_json = jsondecode({
LeafCertTTL = "24h"
RotationPeriod = "2160h"
IntermediateCertTTL = "8760h"
})
}


# Using Vault to manage and sign certificates
resource "consul_certificate_authority" "connect" {
connect_provider = "vault"

config_json = jsonencode({
Address = "http://localhost:8200"
Token = "..."
RootPKIPath = "connect-root"
IntermediatePKIPath = "connect-intermediate"
})
}


# Using the AWS Certificate Manager Private Certificate Authority
# * https://aws.amazon.com/certificate-manager/private-certificate-authority/
resource "consul_certificate_authority" "connect" {
connect_provider = "aws-pca"

config_json = jsonencode({
ExistingARN = "arn:aws:acm-pca:region:account:certificate-authority/12345678-1234-1234-123456789012"
})
}
```

<!-- schema generated by tfplugindocs -->
## Schema
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/config_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ resource "consul_config_entry" "mesh" {
resource "consul_config_entry" "jwt_provider" {
name = "provider-name"
kind = "jwt-provider"

config_json = jsonencode({
Issuer = "https://your.issuer.com"
JSONWebKeySet = {
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/prepared_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ Required:
- `regexp` (String) The regular expression to match with. When using `name_prefix_match`, this regex is applied against the query name.
- `type` (String) The type of template matching to perform. Currently only `name_prefix_match` is supported.

Optional:

- `remove_empty_tags` (Boolean) If set to true, will cause the tags list inside the service structure to be stripped of any empty strings.

## Import

Import is supported using the following syntax:
Expand Down
48 changes: 48 additions & 0 deletions templates/resources/config_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ resource "consul_config_entry" "sd" {
})
}

resource "consul_config_entry" "jwt_provider" {
name = "test-provider"
kind = "jwt-provider"

config_json = jsonencode({
Issuer = "test-issuer"
JSONWebKeySet = {
Remote = {
URI = "https://127.0.0.1:9091"
FetchAsynchronously = true
}
}
Forwarding = {
HeaderName = "test-token"
}
})
}

resource "consul_config_entry" "service_intentions" {
name = consul_config_entry.sd.name
kind = "service-intentions"
Expand All @@ -186,6 +204,13 @@ resource "consul_config_entry" "service_intentions" {
Methods = ["GET", "HEAD"]
PathExact = "/healtz"
}
JWT = {
Providers = [
{
Name = consul_config_entry.jwt_provider.name
}
]
}
}
]
Precedence = 9
Expand Down Expand Up @@ -250,6 +275,29 @@ resource "consul_config_entry" "mesh" {
}
```

### `jwt-provider` config entry

```hcl
resource "consul_config_entry" "jwt_provider" {
name = "provider-name"
kind = "jwt-provider"

config_json = jsonencode({
Issuer = "https://your.issuer.com"
JSONWebKeySet = {
Remote = {
URI = "https://your-remote.jwks.com"
FetchAsynchronously = true
CacheDuration = "10s"
}
}
Forwarding = {
HeaderName = "test-token"
}
})
}
```


## Argument Reference

Expand Down
Loading