From ddb64ca24a09422618cab8cc296c96a827470aa4 Mon Sep 17 00:00:00 2001 From: Thomas Nicollet Date: Wed, 29 Nov 2023 15:30:41 +0100 Subject: [PATCH 1/4] Removed the technical preview warning that has been disabled on official doc since 1.14.x --- consul/resource_consul_peering_token.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/consul/resource_consul_peering_token.go b/consul/resource_consul_peering_token.go index 75f46598..998a5eaf 100644 --- a/consul/resource_consul_peering_token.go +++ b/consul/resource_consul_peering_token.go @@ -18,8 +18,6 @@ func resourceSourceConsulPeeringToken() *schema.Resource { 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. `, From 8ad79f66309c5836e5c553bf8f6634d0119e0afa Mon Sep 17 00:00:00 2001 From: Thomas Nicollet Date: Wed, 29 Nov 2023 15:38:07 +0100 Subject: [PATCH 2/4] Added server_external_addresses to the field of consul_peering_token --- consul/resource_consul_peering_token.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/consul/resource_consul_peering_token.go b/consul/resource_consul_peering_token.go index 998a5eaf..1035bcd5 100644 --- a/consul/resource_consul_peering_token.go +++ b/consul/resource_consul_peering_token.go @@ -47,6 +47,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, @@ -67,9 +74,10 @@ func resourceConsulPeeringTokenCreate(d *schema.ResourceData, meta interface{}) } req := api.PeeringGenerateTokenRequest{ - PeerName: name, - Partition: d.Get("partition").(string), - Meta: m, + PeerName: name, + Partition: d.Get("partition").(string), + Meta: m, + ServerExternalAddresses: d.Get("server_external_addresses").([]string), } resp, _, err := client.Peerings().GenerateToken(context.Background(), req, wOpts) From c0353712566c613d80f5d96cefdc1b2daf13dd9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Thu, 14 Dec 2023 12:47:57 +0100 Subject: [PATCH 3/4] Update documentation template --- consul/resource_consul_peering_token.go | 2 -- docs/resources/peering_token.md | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/consul/resource_consul_peering_token.go b/consul/resource_consul_peering_token.go index 1035bcd5..7d72d4c8 100644 --- a/consul/resource_consul_peering_token.go +++ b/consul/resource_consul_peering_token.go @@ -17,8 +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. - -The functionality described here is available only in Consul version 1.13.0 and later. `, Create: resourceConsulPeeringTokenCreate, diff --git a/docs/resources/peering_token.md b/docs/resources/peering_token.md index a80a4674..2f28c31c 100644 --- a/docs/resources/peering_token.md +++ b/docs/resources/peering_token.md @@ -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) @@ -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 @@ -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 From c6d856f82dc6d3b11abe50f511281604c4f42bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Thu, 14 Dec 2023 13:00:40 +0100 Subject: [PATCH 4/4] Fix code and add tests --- consul/resource_consul_peering_token.go | 16 +++++++++------- consul/resource_consul_peering_token_test.go | 14 +++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/consul/resource_consul_peering_token.go b/consul/resource_consul_peering_token.go index 7d72d4c8..f9619042 100644 --- a/consul/resource_consul_peering_token.go +++ b/consul/resource_consul_peering_token.go @@ -66,16 +66,18 @@ func resourceConsulPeeringTokenCreate(d *schema.ResourceData, meta interface{}) client, _, wOpts := getClient(d, meta) name := d.Get("peer_name").(string) - m := map[string]string{} + req := api.PeeringGenerateTokenRequest{ + PeerName: name, + Partition: d.Get("partition").(string), + Meta: map[string]string{}, + } + for k, v := range d.Get("meta").(map[string]interface{}) { - m[k] = v.(string) + req.Meta[k] = v.(string) } - req := api.PeeringGenerateTokenRequest{ - PeerName: name, - Partition: d.Get("partition").(string), - Meta: m, - ServerExternalAddresses: d.Get("server_external_addresses").([]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) diff --git a/consul/resource_consul_peering_token_test.go b/consul/resource_consul_peering_token_test.go index 74fbb8e8..fdb60635 100644 --- a/consul/resource_consul_peering_token_test.go +++ b/consul/resource_consul_peering_token_test.go @@ -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"] } ` +)