Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/resources/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ In addition to all arguments above, the following attributes are exported:
- `private_network` - List of private networks connected to your load balancer.
- `status` - The status of the private network connection.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the private network was created.
- `private_ips` - The list of private IPv4 and IPv6 addresses associated with the resource.
- `id` - The ID of the IP address resource.
- `address` - The private IP address.
- `organization_id` - The ID of the Organization ID the Load Balancer is associated with.

~> **Important:** `release_ip` will not be supported. This prevents the destruction of the IP from releasing a Load Balancer.
Expand Down
1,739 changes: 894 additions & 845 deletions internal/services/ipam/testdata/data-source-ipamip-instance-lb.cassette.yaml

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions internal/services/lb/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
ipamAPI "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
lbSDK "github.com/scaleway/scaleway-sdk-go/api/lb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/cdf"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
)
Expand Down Expand Up @@ -199,6 +201,25 @@ func ResourceLb() *schema.Resource {
DiffSuppressFunc: dsf.OrderDiff,
ConflictsWith: []string{"assign_flexible_ip", "assign_flexible_ipv6"},
},
"private_ips": {
Type: schema.TypeList,
Computed: true,
Description: "List of private IPv4 and IPv6 addresses associated with the resource",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the IP address resource",
},
"address": {
Type: schema.TypeString,
Computed: true,
Description: "The private IP address",
},
},
},
},
"region": regional.ComputedSchema(),
"zone": zonal.Schema(),
"organization_id": account.OrganizationIDSchema(),
Expand Down Expand Up @@ -334,6 +355,32 @@ func resourceLbRead(ctx context.Context, d *schema.ResourceData, m interface{})

_ = d.Set("private_network", flattenPrivateNetworkConfigs(privateNetworks))

privateNetworkIDs := make([]string, 0, len(privateNetworks))
for _, pn := range privateNetworks {
privateNetworkIDs = append(privateNetworkIDs, pn.PrivateNetworkID)
}

allPrivateIPs := []map[string]interface{}(nil)
resourceType := ipamAPI.ResourceTypeLBServer

for _, privateNetworkID := range privateNetworkIDs {
opts := &ipam.GetResourcePrivateIPsOptions{
ResourceType: &resourceType,
PrivateNetworkID: &privateNetworkID,
}

privateIPs, err := ipam.GetResourcePrivateIPs(ctx, m, region, opts)
if err != nil {
return diag.FromErr(err)
}

if privateIPs != nil {
allPrivateIPs = append(allPrivateIPs, privateIPs...)
}
}

_ = d.Set("private_ips", allPrivateIPs)

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions internal/services/lb/lb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ func TestAccLB_WithPrivateNetworksIPAMIDs(t *testing.T) {
resource.TestCheckResourceAttrPair(
"scaleway_ipam_ip.ip01", "address",
"data.scaleway_ipam_ip.by_name", "address_cidr"),
resource.TestCheckResourceAttrSet("scaleway_lb.lb01", "private_ips.0.id"),
resource.TestCheckResourceAttrSet("scaleway_lb.lb01", "private_ips.0.address"),
),
},
},
Expand Down
Loading
Loading