Skip to content

Commit

Permalink
Added server_external_addresses support to consul_peering_token (#387)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémi Lapeyre <remi.lapeyre@lenstra.fr>
  • Loading branch information
nwmqpa and remilapeyre committed Dec 14, 2023
1 parent 4d11a4d commit ec9cd0a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
26 changes: 16 additions & 10 deletions consul/resource_consul_peering_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ func resourceSourceConsulPeeringToken() *schema.Resource {
[Cluster Peering](https://www.consul.io/docs/connect/cluster-peering) can be used to create connections between two or more independent clusters so that services deployed to different partitions or datacenters can communicate.
The ` + "`cluster_peering_token`" + ` resource can be used to generate a peering token that can later be used to establish a peering connection.
~> **Cluster peering is currently in technical preview:** Functionality associated with cluster peering is subject to change. You should never use the technical preview release in secure environments or production scenarios. Features in technical preview may have performance issues, scaling issues, and limited support.
The functionality described here is available only in Consul version 1.13.0 and later.
`,

Create: resourceConsulPeeringTokenCreate,
Expand Down Expand Up @@ -49,6 +45,13 @@ The functionality described here is available only in Consul version 1.13.0 and
Type: schema.TypeString,
},
},
"server_external_addresses": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
ForceNew: true,
Description: "The addresses for the cluster that generates the peering token. Addresses take the form {host or IP}:port. You can specify one or more load balancers or external IPs that route external traffic to this cluster's Consul servers.",
},
"peering_token": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -63,15 +66,18 @@ func resourceConsulPeeringTokenCreate(d *schema.ResourceData, meta interface{})
client, _, wOpts := getClient(d, meta)
name := d.Get("peer_name").(string)

m := map[string]string{}
for k, v := range d.Get("meta").(map[string]interface{}) {
m[k] = v.(string)
}

req := api.PeeringGenerateTokenRequest{
PeerName: name,
Partition: d.Get("partition").(string),
Meta: m,
Meta: map[string]string{},
}

for k, v := range d.Get("meta").(map[string]interface{}) {
req.Meta[k] = v.(string)
}

for _, address := range d.Get("server_external_addresses").([]interface{}) {
req.ServerExternalAddresses = append(req.ServerExternalAddresses, address.(string))
}

resp, _, err := client.Peerings().GenerateToken(context.Background(), req, wOpts)
Expand Down
14 changes: 13 additions & 1 deletion consul/resource_consul_peering_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,24 @@ func TestAccConsulPeeringToken_basic(t *testing.T) {
return nil
},
},
{
Config: testAcConsulPeeringTokenServerExternalAddresses,
},
},
})
}

const testAccConsulPeeringTokenBasic = `
const (
testAccConsulPeeringTokenBasic = `
resource "consul_peering_token" "basic" {
peer_name = "hello-world"
}
`

testAcConsulPeeringTokenServerExternalAddresses = `
resource "consul_peering_token" "basic" {
peer_name = "hello-world"
server_external_addresses = ["1.2.3.4:8500"]
}
`
)
7 changes: 1 addition & 6 deletions docs/resources/peering_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ subcategory: ""
description: |-
Cluster Peering https://www.consul.io/docs/connect/cluster-peering can be used to create connections between two or more independent clusters so that services deployed to different partitions or datacenters can communicate.
The cluster_peering_token resource can be used to generate a peering token that can later be used to establish a peering connection.
~> Cluster peering is currently in technical preview: Functionality associated with cluster peering is subject to change. You should never use the technical preview release in secure environments or production scenarios. Features in technical preview may have performance issues, scaling issues, and limited support.
The functionality described here is available only in Consul version 1.13.0 and later.
---

# consul_peering_token (Resource)
Expand All @@ -15,10 +13,6 @@ description: |-

The `cluster_peering_token` resource can be used to generate a peering token that can later be used to establish a peering connection.

~> **Cluster peering is currently in technical preview:** Functionality associated with cluster peering is subject to change. You should never use the technical preview release in secure environments or production scenarios. Features in technical preview may have performance issues, scaling issues, and limited support.

The functionality described here is available only in Consul version 1.13.0 and later.

## Example Usage

```terraform
Expand All @@ -38,6 +32,7 @@ resource "consul_peering_token" "token" {

- `meta` (Map of String) Specifies KV metadata to associate with the peering. This parameter is not required and does not directly impact the cluster peering process.
- `partition` (String)
- `server_external_addresses` (List of String) The addresses for the cluster that generates the peering token. Addresses take the form {host or IP}:port. You can specify one or more load balancers or external IPs that route external traffic to this cluster's Consul servers.

### Read-Only

Expand Down

0 comments on commit ec9cd0a

Please sign in to comment.