Skip to content

Commit

Permalink
datasource exoscale_instance_pool_list: fix panic when IP has labels (#…
Browse files Browse the repository at this point in the history
…283)

- Fix a panic when an InstancePool with labels exist in the zone.
- Update test with an InstancePool with label
- Fix the example

```
=== RUN   TestInstancePool
=== RUN   TestInstancePool/DataSource
=== RUN   TestInstancePool/DataSourceList
=== RUN   TestInstancePool/Resource
--- PASS: TestInstancePool (241.35s)
    --- PASS: TestInstancePool/DataSource (86.53s)
    --- PASS: TestInstancePool/DataSourceList (60.21s)
    --- PASS: TestInstancePool/Resource (94.61s)
PASS
ok      github.com/exoscale/terraform-provider-exoscale/pkg/resources/instance_pool     241.388s

```
  • Loading branch information
jessicatoscani authored Jul 25, 2023
1 parent ccf3a05 commit 2bb0def
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

BUG FIX:

- datasource `exoscale_instance_pool_list`: fix panic when instance pool with labels is found

## 0.50.0 (June 23, 2023)

IMPROVEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/instance_pool_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data "exoscale_instance_pool_list" "my_instance_pool_list" {
output "my_instance_pool_ids" {
value = join("\n", formatlist(
"%s", exoscale_instance_pool_list.my_instance_pool_list.pools.*.id
"%s", data.exoscale_instance_pool_list.my_instance_pool_list.pools.*.id
))
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ data "exoscale_instance_pool_list" "my_instance_pool_list" {

output "my_instance_pool_ids" {
value = join("\n", formatlist(
"%s", exoscale_instance_pool_list.my_instance_pool_list.pools.*.id
"%s", data.exoscale_instance_pool_list.my_instance_pool_list.pools.*.id
))
}
5 changes: 4 additions & 1 deletion pkg/resources/instance_pool/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func dsBuildData(pool *exo.InstancePool) (map[string]interface{}, error) {
data[AttrInstancePrefix] = utils.DefaultString(pool.InstancePrefix, "")
data[AttrIPv6] = utils.DefaultBool(pool.IPv6Enabled, false)
data[AttrKeyPair] = pool.SSHKey
data[AttrLabels] = pool.Labels
data[AttrName] = pool.Name
data[AttrSize] = pool.Size
data[AttrState] = pool.State
Expand All @@ -295,6 +294,10 @@ func dsBuildData(pool *exo.InstancePool) (map[string]interface{}, error) {
data[AttrAffinityGroupIDs] = *pool.AntiAffinityGroupIDs
}

if pool.Labels != nil {
data[AttrLabels] = *pool.Labels
}

if pool.ElasticIPIDs != nil {
data[AttrElasticIPIDs] = *pool.ElasticIPIDs
}
Expand Down
1 change: 1 addition & 0 deletions pkg/resources/instance_pool/datasource_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ resource "exoscale_instance_pool" "test2" {
size = 1
disk_size = local.disk_size
key_pair = exoscale_ssh_keypair.test.name
labels = { test="test"}
}`,
testutils.TestZoneName,
dsListInstanceType,
Expand Down
1 change: 1 addition & 0 deletions templates/data-sources/database_uri.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ resource "exoscale_database" "my_database" {
data "exoscale_database_uri" "my_database" {
name = "my-database"
type = "pg"
zone = "ch-gva-2"
}

output "my_database_uri" {
Expand Down

0 comments on commit 2bb0def

Please sign in to comment.