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] 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"] } ` +)