Skip to content

Commit

Permalink
Fix code and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remilapeyre committed Dec 14, 2023
1 parent c035371 commit c6d856f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
16 changes: 9 additions & 7 deletions consul/resource_consul_peering_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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"]
}
`
)

0 comments on commit c6d856f

Please sign in to comment.