Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ipv4CIDRBlock attribute for LAN resource & data source #739

Merged
merged 1 commit into from
Jan 21, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 6.7.0 -- upcoming release
### Fixes
- Fix [#735](https://github.com/ionos-cloud/terraform-provider-ionoscloud/issues/735) by reading all values for `api_subnet_allow_list`, not only non-nill values.
### Features
- Add new read-only attribute: `ipv4_cidr_block` to `ionoscloud_lan` resource and data source.

## 6.6.9
### Features
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/lan.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ The following attributes are returned by the datasource:
* `ip`
* `pcc` - The unique id of a `ionoscloud_private_crossconnect` resource, in order.
* `public` - Indicates if the LAN faces the public Internet (true) or not (false).
* `ipv4_cidr_block` - For public LANs this property is null, for private LANs it contains the private IPv4 CIDR range.
* `ipv6_cidr_block` - Contains the LAN's /64 IPv6 CIDR block if this LAN is IPv6 enabled.
1 change: 1 addition & 0 deletions docs/resources/lan.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "ionoscloud_lan" "example" {
* `name` - (Optional)[string] The name of the LAN.
* `public` - (Optional)[Boolean] Indicates if the LAN faces the public Internet (true) or not (false).
* `pcc` - (Optional)[String] The unique id of a `ionoscloud_private_crossconnect` resource, in order. It needs to be ensured that IP addresses of the NICs of all LANs connected to a given Cross Connect is not duplicated and belongs to the same subnet range
* `ipv4_cidr_block` - (Computed)[String] For public LANs this property is null, for private LANs it contains the private IPv4 CIDR range. This property is a read only property.
* `ipv6_cidr_block` - (Computed, Optional) Contains the LAN's /64 IPv6 CIDR block if this LAN is IPv6 enabled. 'AUTO' will result in enabling this LAN for IPv6 and automatically assign a /64 IPv6 CIDR block to this LAN. If you specify your own IPv6 CIDR block then you must provide a unique /64 block, which is inside the IPv6 CIDR block of the virtual datacenter and unique inside all LANs from this virtual datacenter.
* `ip_failover` - (Computed) IP failover configurations for lan
* `ip`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/ionos-cloud/sdk-go-object-storage v1.1.0
github.com/ionos-cloud/sdk-go-object-storage-management v1.0.0
github.com/ionos-cloud/sdk-go-vm-autoscaling v1.0.1
github.com/ionos-cloud/sdk-go/v6 v6.3.0
github.com/ionos-cloud/sdk-go/v6 v6.3.2
github.com/mitchellh/go-homedir v1.1.0
golang.org/x/crypto v0.26.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ github.com/ionos-cloud/sdk-go-dns v1.2.1 h1:Sy7Jg5trzObad9VPvEh7BgeJrIhaxdGlBEvG
github.com/ionos-cloud/sdk-go-dns v1.2.1/go.mod h1:l9gYdwtUshlBOiIi4nHn3RCX81XlV3VoNvLJrO2VfHg=
github.com/ionos-cloud/sdk-go-kafka v1.0.0 h1:S0Tfy/KlYW7UJW6DoU43fF0/iNPc1YKC+AC56G9wfA4=
github.com/ionos-cloud/sdk-go-kafka v1.0.0/go.mod h1:yIq1FjRtdcbwmybb42puagpLjmD2wbWAew8UMHO5wqU=
github.com/ionos-cloud/sdk-go-nfs v1.0.0 h1:CyiemTDPg2jAjtTT4JHzvOpjq6lqe7YbXx2iq2gx98s=
github.com/ionos-cloud/sdk-go-nfs v1.0.0/go.mod h1:ffyMIPVknZ7dpi/+RomWXNNYV7ZjtK8KYSsGjVlbqgA=
github.com/ionos-cloud/sdk-go-nfs v1.1.1 h1:tMMUPGKRQm2z5FTIMFoE/DJ8Xw3522T0jVutCGmsyMw=
github.com/ionos-cloud/sdk-go-nfs v1.1.1/go.mod h1:jgNAKLmjzBP6RzPnjydleZzVlAL8KnYKPcBjWgLVxJk=
github.com/ionos-cloud/sdk-go-object-storage v1.1.0 h1:4JTsxrbzFltF9liAHZ2I9f53rpkrXm8642UwQoQ+pMc=
Expand All @@ -152,8 +150,8 @@ github.com/ionos-cloud/sdk-go-object-storage-management v1.0.0 h1:pHRKSNT+cCcr5g
github.com/ionos-cloud/sdk-go-object-storage-management v1.0.0/go.mod h1:BnEapZcQp6FEirEin6pY9NICXD1mCrI4sJ+wOSKpyCY=
github.com/ionos-cloud/sdk-go-vm-autoscaling v1.0.1 h1:KABL25MC7DrIHn9lQzKSPkwXhqvRkPYtFd+1HEogmAE=
github.com/ionos-cloud/sdk-go-vm-autoscaling v1.0.1/go.mod h1:Q5d1R6silarsX5jWLPBHd/1PSC5zZNf2ONvXB+fygC0=
github.com/ionos-cloud/sdk-go/v6 v6.3.0 h1:/lTieTH9Mo/CWm3cTlFLnK10jgxjUGkAqRffGqvPteY=
github.com/ionos-cloud/sdk-go/v6 v6.3.0/go.mod h1:SXrO9OGyWjd2rZhAhEpdYN6VUAODzzqRdqA9BCviQtI=
github.com/ionos-cloud/sdk-go/v6 v6.3.2 h1:2mUmrZZz6cPyT9IRX0T8fBLc/7XU/eTxP2Y5tS7/09k=
github.com/ionos-cloud/sdk-go/v6 v6.3.2/go.mod h1:SXrO9OGyWjd2rZhAhEpdYN6VUAODzzqRdqA9BCviQtI=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
Expand Down Expand Up @@ -237,8 +235,6 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
5 changes: 5 additions & 0 deletions ionoscloud/data_source_lan.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func dataSourceLan() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"ipv4_cidr_block": {
Type: schema.TypeString,
Computed: true,
Description: "For public LANs this property is null, for private LANs it contains the private IPv4 CIDR range.",
},
"ipv6_cidr_block": {
Type: schema.TypeString,
Computed: true,
Expand Down
20 changes: 15 additions & 5 deletions ionoscloud/resource_lan.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func resourceLan() *schema.Resource {
StateContext: resourceLanImport,
},
Schema: map[string]*schema.Schema{

"public": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -65,6 +64,11 @@ func resourceLan() *schema.Resource {
},
},
},
"ipv4_cidr_block": {
Type: schema.TypeString,
Computed: true,
Description: "For public LANs this property is null, for private LANs it contains the private IPv4 CIDR range. This property is a read only property.",
},
"ipv6_cidr_block": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -92,9 +96,8 @@ func resourceLanCreate(ctx context.Context, d *schema.ResourceData, meta interfa
},
}

name := d.Get("name").(string)
log.Printf("[DEBUG] NAME %s", d.Get("name"))
if d.Get("name") != nil {
name := d.Get("name").(string)
request.Properties.Name = &name
}

Expand Down Expand Up @@ -138,14 +141,14 @@ func resourceLanCreate(ctx context.Context, d *schema.ResourceData, meta interfa
for {
log.Printf("[INFO] Waiting for LAN %s to be available...", *rsp.Id)

clusterReady, rsErr := lanAvailable(ctx, client, d)
lanReady, rsErr := lanAvailable(ctx, client, d)

if rsErr != nil {
diags := diag.FromErr(fmt.Errorf("error while checking readiness status of LAN %s: %w", *rsp.Id, rsErr))
return diags
}

if clusterReady {
if lanReady {
log.Printf("[INFO] LAN ready: %s", d.Id())
break
}
Expand Down Expand Up @@ -326,6 +329,13 @@ func setLanData(d *schema.ResourceData, lan *ionoscloud.Lan) error {
return err
}
}

if lan.Properties.Ipv4CidrBlock != nil {
if err := d.Set("ipv4_cidr_block", *lan.Properties.Ipv4CidrBlock); err != nil {
return utils.GenerateSetError("lan", "ipv4_cidr_block", err)
}
}

if lan.Properties.Ipv6CidrBlock != nil {
if err := d.Set("ipv6_cidr_block", *lan.Properties.Ipv6CidrBlock); err != nil {
return utils.GenerateSetError("lan", "ipv6_cidr_block", err)
Expand Down
47 changes: 38 additions & 9 deletions ionoscloud/resource_lan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

func TestAccLanBasic(t *testing.T) {
var lan ionoscloud.Lan
var privateLAN ionoscloud.Lan

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -37,12 +38,12 @@ func TestAccLanBasic(t *testing.T) {
{
Config: testAccDataSourceLanMatchId,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "name", constant.LanResource+"."+constant.LanTestResource, "name"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "ip_failover.nic_uuid", constant.LanResource+"."+constant.LanTestResource, "ip_failover.nic_uuid"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "ip_failover.ip", constant.LanResource+"."+constant.LanTestResource, "ip_failover.ip"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "pcc", constant.LanResource+"."+constant.LanTestResource, "pcc"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "public", constant.LanResource+"."+constant.LanTestResource, "public"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "ipv6_cidr_block", constant.LanResource+"."+constant.LanTestResource, "ipv6_cidr_block"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "name", constant.LanResource+"."+constant.LanTestResource, "name"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "ip_failover.nic_uuid", constant.LanResource+"."+constant.LanTestResource, "ip_failover.nic_uuid"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "ip_failover.ip", constant.LanResource+"."+constant.LanTestResource, "ip_failover.ip"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "pcc", constant.LanResource+"."+constant.LanTestResource, "pcc"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "public", constant.LanResource+"."+constant.LanTestResource, "public"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "ipv6_cidr_block", constant.LanResource+"."+constant.LanTestResource, "ipv6_cidr_block"),
),
},
{
Expand Down Expand Up @@ -70,7 +71,28 @@ func TestAccLanBasic(t *testing.T) {
resource.TestCheckResourceAttr(constant.LanResource+"."+constant.LanTestResource, "name", constant.UpdatedResources),
resource.TestCheckResourceAttr(constant.LanResource+"."+constant.LanTestResource, "public", "false"),
resource.TestCheckResourceAttrPair(constant.LanResource+"."+constant.LanTestResource, "pcc", constant.PCCResource+"."+constant.PCCTestResource, "id"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceById, "ipv6_cidr_block", constant.LanResource+"."+constant.LanTestResource, "ipv6_cidr_block"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.LanDataSourceByID, "ipv6_cidr_block", constant.LanResource+"."+constant.LanTestResource, "ipv6_cidr_block"),
),
},
{
Config: privateLANConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckLanExists(constant.LanResource+"."+constant.PrivateLANTestResource, &privateLAN),
resource.TestCheckResourceAttr(constant.LanResource+"."+constant.PrivateLANTestResource, "name", constant.PrivateLANTestResource),
resource.TestCheckResourceAttr(constant.LanResource+"."+constant.PrivateLANTestResource, "public", "false"),
resource.TestCheckResourceAttrSet(constant.LanResource+"."+constant.PrivateLANTestResource, "ipv4_cidr_block"),
),
},
{
Config: dataSourcePrivateLANMatchName,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "name", constant.LanResource+"."+constant.PrivateLANTestResource, "name"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "ip_failover.nic_uuid", constant.LanResource+"."+constant.PrivateLANTestResource, "ip_failover.nic_uuid"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "ip_failover.ip", constant.LanResource+"."+constant.PrivateLANTestResource, "ip_failover.ip"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "pcc", constant.LanResource+"."+constant.PrivateLANTestResource, "pcc"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "public", constant.LanResource+"."+constant.PrivateLANTestResource, "public"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "ipv4_cidr_block", constant.LanResource+"."+constant.PrivateLANTestResource, "ipv4_cidr_block"),
resource.TestCheckResourceAttrPair(constant.DataSource+"."+constant.LanResource+"."+constant.PrivateLANDataSourceByName, "ipv6_cidr_block", constant.LanResource+"."+constant.PrivateLANTestResource, "ipv6_cidr_block"),
),
},
},
Expand Down Expand Up @@ -148,14 +170,14 @@ resource ` + constant.LanResource + ` ` + constant.LanTestResource + ` {
pcc = ` + constant.PCCResource + `.` + constant.PCCTestResource + `.id
ipv6_cidr_block = cidrsubnet(` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.ipv6_cidr_block` + `,8,2)
}
data ` + constant.LanResource + ` ` + constant.LanDataSourceById + ` {
data ` + constant.LanResource + ` ` + constant.LanDataSourceByID + ` {
datacenter_id = ` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.id
id = ` + constant.LanResource + `.` + constant.LanTestResource + `.id
}
`

const testAccDataSourceLanMatchId = testAccCheckLanConfigBasic + `
data ` + constant.LanResource + ` ` + constant.LanDataSourceById + ` {
data ` + constant.LanResource + ` ` + constant.LanDataSourceByID + ` {
datacenter_id = ` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.id
id = ` + constant.LanResource + `.` + constant.LanTestResource + `.id
}
Expand All @@ -168,6 +190,13 @@ data ` + constant.LanResource + ` ` + constant.LanDataSourceByName + ` {
}
`

const dataSourcePrivateLANMatchName = privateLANConfig + `
data ` + constant.LanResource + ` ` + constant.PrivateLANDataSourceByName + ` {
datacenter_id = ` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.id
name = "` + constant.PrivateLANTestResource + `"
}
`

const testAccDataSourceLanMultipleResultsError = testAccCheckLanConfigBasic + `
resource ` + constant.LanResource + ` ` + constant.LanTestResource + `_multiple_results {
datacenter_id = ` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.id
Expand Down
7 changes: 7 additions & 0 deletions ionoscloud/test_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ resource ` + constant.LanResource + ` ` + constant.LanTestResource + ` {
public = true
name = "` + constant.LanTestResource + `"
}`

privateLANConfig = testAccCheckDatacenterConfigBasic + `
resource ` + constant.LanResource + ` ` + constant.PrivateLANTestResource + ` {
datacenter_id = ` + constant.DatacenterResource + `.` + constant.DatacenterTestResource + `.id
public = false
name = "` + constant.PrivateLANTestResource + `"
}`
)

// Private Crossconnect Constants
Expand Down
10 changes: 6 additions & 4 deletions utils/constant/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ const (

// Lan Constants
const (
LanResource = "ionoscloud_lan"
LanTestResource = "test_lan"
LanDataSourceById = "test_lan_id"
LanDataSourceByName = "test_lan_name"
LanResource = "ionoscloud_lan"
LanTestResource = "test_lan"
PrivateLANTestResource = "private_lan"
LanDataSourceByID = "test_lan_id"
LanDataSourceByName = "test_lan_name"
PrivateLANDataSourceByName = "private_lan_name"
)

// Group Constants
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/ionos-cloud/sdk-go/v6/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/ionos-cloud/sdk-go/v6/configuration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading