Skip to content

Commit b1fb9ab

Browse files
GokceGKjoaopalet
andauthored
Extend network resource fields (#576)
* deprecate nameservers filed * onboard routed field * onboard new ipv4 fields * onboard new ipv6 fields * update examples * update examples * update examples * remove nameserver(deprecated) mapping * make fields computed * Revert "remove nameserver(deprecated) mapping" This reverts commit e4bf1dc. * remove routed from update payload (not yet supported) * Update docs/resources/network.md Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * fix the field descriptions * remove ipv6 from examples * use nameservers as rollback value to support deprecated field * extend acceptance tests * add condition that nameserver and ipv4_nameserver cannot be provided at the same time * extend acc test * improve conditions in create payload * adapt modify plan to support update and delete operations * fix acceptance test * deprecate prefixes and create ipv4_prefixes field * fix unit tests * fix update issues * fix linter issues * extend modifyPlan condition * add validateConfig function * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * update descriptions * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * implement no_gateway field and condition check * implement no_ipv6_gateway field and condition check * update examples * update examples and descriptions * fix linter issues * Update stackit/internal/services/iaas/network/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * adapt descriptions * apply acceptance comments * adapt conditions in create and update * add plan modifiers * add requiresReplace --------- Co-authored-by: João Palet <joao.palet@outlook.com>
1 parent 3ac1d50 commit b1fb9ab

7 files changed

Lines changed: 852 additions & 55 deletions

File tree

docs/data-sources/network.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,19 @@ data "stackit_network" "example" {
3030
### Read-Only
3131

3232
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`network_id`".
33+
- `ipv4_gateway` (String) The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
34+
- `ipv4_nameservers` (List of String) The IPv4 nameservers of the network.
35+
- `ipv4_prefix` (String) The IPv4 prefix of the network (CIDR).
3336
- `ipv4_prefix_length` (Number) The IPv4 prefix length of the network.
37+
- `ipv4_prefixes` (List of String) The IPv4 prefixes of the network.
38+
- `ipv6_gateway` (String) The IPv6 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
39+
- `ipv6_nameservers` (List of String) The IPv6 nameservers of the network.
40+
- `ipv6_prefix` (String) The IPv6 prefix of the network (CIDR).
41+
- `ipv6_prefix_length` (Number) The IPv6 prefix length of the network.
42+
- `ipv6_prefixes` (List of String) The IPv6 prefixes of the network.
3443
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
3544
- `name` (String) The name of the network.
36-
- `nameservers` (List of String) The nameservers of the network.
37-
- `prefixes` (List of String) The prefixes of the network.
45+
- `nameservers` (List of String, Deprecated) The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.
46+
- `prefixes` (List of String, Deprecated) The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.
3847
- `public_ip` (String) The public IP of the network.
48+
- `routed` (Boolean) Shows if the network is routed and therefore accessible from other networks.

docs/resources/network.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,31 @@ Network resource schema. Must have a `region` specified in the provider configur
1313
## Example Usage
1414

1515
```terraform
16-
resource "stackit_network" "example" {
16+
resource "stackit_network" "example_with_name" {
17+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18+
name = "example-with-name"
19+
}
20+
21+
resource "stackit_network" "example_routed_network" {
22+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
23+
name = "example-routed-network"
24+
labels = {
25+
"key" = "value"
26+
}
27+
routed = true
28+
}
29+
30+
resource "stackit_network" "example_non_routed_network" {
1731
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
18-
name = "example-network"
19-
nameservers = ["1.2.3.4", "5.6.7.8"]
32+
name = "example-non-routed-network"
33+
ipv4_nameservers = ["1.2.3.4", "5.6.7.8"]
2034
ipv4_prefix_length = 24
35+
ipv4_gateway = "10.1.2.3"
36+
ipv4_prefix = "10.1.2.0/24"
2137
labels = {
2238
"key" = "value"
2339
}
40+
routed = false
2441
}
2542
```
2643

@@ -34,13 +51,25 @@ resource "stackit_network" "example" {
3451

3552
### Optional
3653

54+
- `ipv4_gateway` (String) The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
55+
- `ipv4_nameservers` (List of String) The IPv4 nameservers of the network.
56+
- `ipv4_prefix` (String) The IPv4 prefix of the network (CIDR).
3757
- `ipv4_prefix_length` (Number) The IPv4 prefix length of the network.
58+
- `ipv6_gateway` (String) The IPv6 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.
59+
- `ipv6_nameservers` (List of String) The IPv6 nameservers of the network.
60+
- `ipv6_prefix` (String) The IPv6 prefix of the network (CIDR).
61+
- `ipv6_prefix_length` (Number) The IPv6 prefix length of the network.
3862
- `labels` (Map of String) Labels are key-value string pairs which can be attached to a resource container
39-
- `nameservers` (List of String) The nameservers of the network.
63+
- `nameservers` (List of String, Deprecated) The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.
64+
- `no_ipv4_gateway` (Boolean) If set to `true`, the network doesn't have a gateway.
65+
- `no_ipv6_gateway` (Boolean) If set to `true`, the network doesn't have a gateway.
66+
- `routed` (Boolean) If set to `true`, the network is routed and therefore accessible from other networks.
4067

4168
### Read-Only
4269

4370
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`,`network_id`".
71+
- `ipv4_prefixes` (List of String) The IPv4 prefixes of the network.
72+
- `ipv6_prefixes` (List of String) The IPv6 prefixes of the network.
4473
- `network_id` (String) The network ID.
45-
- `prefixes` (List of String) The prefixes of the network.
74+
- `prefixes` (List of String, Deprecated) The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.
4675
- `public_ip` (String) The public IP of the network.
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
resource "stackit_network" "example" {
1+
resource "stackit_network" "example_with_name" {
2+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3+
name = "example-with-name"
4+
}
5+
6+
resource "stackit_network" "example_routed_network" {
7+
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
8+
name = "example-routed-network"
9+
labels = {
10+
"key" = "value"
11+
}
12+
routed = true
13+
}
14+
15+
resource "stackit_network" "example_non_routed_network" {
216
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
3-
name = "example-network"
4-
nameservers = ["1.2.3.4", "5.6.7.8"]
17+
name = "example-non-routed-network"
18+
ipv4_nameservers = ["1.2.3.4", "5.6.7.8"]
519
ipv4_prefix_length = 24
20+
ipv4_gateway = "10.1.2.3"
21+
ipv4_prefix = "10.1.2.0/24"
622
labels = {
723
"key" = "value"
824
}
9-
}
25+
routed = false
26+
}

stackit/internal/services/iaas/iaas_acc_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ var networkResource = map[string]string{
2929
"ipv4_prefix_length": "24",
3030
"nameserver0": "1.2.3.4",
3131
"nameserver1": "5.6.7.8",
32+
"ipv4_gateway": "10.1.2.1",
33+
"ipv4_prefix": "10.1.2.1/24",
34+
"routed": "false",
3235
}
3336

3437
var networkAreaResource = map[string]string{
@@ -113,13 +116,19 @@ func networkResourceConfig(name, nameservers string) string {
113116
project_id = "%s"
114117
name = "%s"
115118
ipv4_prefix_length = "%s"
116-
nameservers = %s
119+
ipv4_nameservers = %s
120+
ipv4_gateway = "%s"
121+
ipv4_prefix = "%s"
122+
routed = "%s"
117123
}
118124
`,
119125
networkResource["project_id"],
120126
name,
121127
networkResource["ipv4_prefix_length"],
122128
nameservers,
129+
networkResource["ipv4_gateway"],
130+
networkResource["ipv4_prefix"],
131+
networkResource["routed"],
123132
)
124133
}
125134

@@ -616,6 +625,9 @@ func TestAccServer(t *testing.T) {
616625
resource.TestCheckResourceAttr("stackit_network.network", "name", networkResource["name"]),
617626
resource.TestCheckResourceAttr("stackit_network.network", "nameservers.#", "1"),
618627
resource.TestCheckResourceAttr("stackit_network.network", "nameservers.0", networkResource["nameserver0"]),
628+
resource.TestCheckResourceAttr("stackit_network.network", "ipv4_gateway", networkResource["ipv4_gateway"]),
629+
resource.TestCheckResourceAttr("stackit_network.network", "ipv4_prefix", networkResource["ipv4_prefix"]),
630+
resource.TestCheckResourceAttr("stackit_network.network", "routed", networkResource["routed"]),
619631

620632
// Server
621633
resource.TestCheckResourceAttr("stackit_server.server", "project_id", serverResource["project_id"]),
@@ -718,6 +730,9 @@ func TestAccServer(t *testing.T) {
718730
),
719731
resource.TestCheckResourceAttr("data.stackit_network.network", "name", networkResource["name"]),
720732
resource.TestCheckResourceAttr("data.stackit_network.network", "nameservers.0", networkResource["nameserver0"]),
733+
resource.TestCheckResourceAttr("data.stackit_network.network", "ipv4_gateway", networkResource["ipv4_gateway"]),
734+
resource.TestCheckResourceAttr("data.stackit_network.network", "ipv4_prefix", networkResource["ipv4_prefix"]),
735+
resource.TestCheckResourceAttr("data.stackit_network.network", "routed", networkResource["routed"]),
721736

722737
// Server
723738
resource.TestCheckResourceAttr("data.stackit_server.server", "project_id", serverResource["project_id"]),
@@ -879,6 +894,8 @@ func TestAccServer(t *testing.T) {
879894
resource.TestCheckResourceAttr("stackit_network.network", "nameservers.#", "2"),
880895
resource.TestCheckResourceAttr("stackit_network.network", "nameservers.0", networkResource["nameserver0"]),
881896
resource.TestCheckResourceAttr("stackit_network.network", "nameservers.1", networkResource["nameserver1"]),
897+
resource.TestCheckResourceAttr("stackit_network.network", "ipv4_gateway", networkResource["ipv4_gateway"]),
898+
resource.TestCheckResourceAttr("stackit_network.network", "ipv4_prefix", networkResource["ipv4_prefix"]),
882899

883900
// Server
884901
resource.TestCheckResourceAttr("stackit_server.server", "project_id", serverResource["project_id"]),

stackit/internal/services/iaas/network/datasource.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,58 @@ func (d *networkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
107107
},
108108
},
109109
"nameservers": schema.ListAttribute{
110-
Description: "The nameservers of the network.",
110+
Description: "The nameservers of the network. This field is deprecated and will be removed soon, use `ipv4_nameservers` to configure the nameservers for IPv4.",
111+
DeprecationMessage: "Use `ipv4_nameservers` to configure the nameservers for IPv4.",
112+
Computed: true,
113+
ElementType: types.StringType,
114+
},
115+
"ipv4_gateway": schema.StringAttribute{
116+
Description: "The IPv4 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.",
117+
Computed: true,
118+
},
119+
"ipv4_nameservers": schema.ListAttribute{
120+
Description: "The IPv4 nameservers of the network.",
111121
Computed: true,
112122
ElementType: types.StringType,
113123
},
124+
"ipv4_prefix": schema.StringAttribute{
125+
Description: "The IPv4 prefix of the network (CIDR).",
126+
Computed: true,
127+
},
114128
"ipv4_prefix_length": schema.Int64Attribute{
115129
Description: "The IPv4 prefix length of the network.",
116130
Computed: true,
117131
},
118132
"prefixes": schema.ListAttribute{
119-
Description: "The prefixes of the network.",
133+
Description: "The prefixes of the network. This field is deprecated and will be removed soon, use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
134+
DeprecationMessage: "Use `ipv4_prefixes` to read the prefixes of the IPv4 networks.",
135+
Computed: true,
136+
ElementType: types.StringType,
137+
},
138+
"ipv4_prefixes": schema.ListAttribute{
139+
Description: "The IPv4 prefixes of the network.",
140+
Computed: true,
141+
ElementType: types.StringType,
142+
},
143+
"ipv6_gateway": schema.StringAttribute{
144+
Description: "The IPv6 gateway of a network. If not specified, the first IP of the network will be assigned as the gateway.",
145+
Computed: true,
146+
},
147+
"ipv6_nameservers": schema.ListAttribute{
148+
Description: "The IPv6 nameservers of the network.",
149+
Computed: true,
150+
ElementType: types.StringType,
151+
},
152+
"ipv6_prefix": schema.StringAttribute{
153+
Description: "The IPv6 prefix of the network (CIDR).",
154+
Computed: true,
155+
},
156+
"ipv6_prefix_length": schema.Int64Attribute{
157+
Description: "The IPv6 prefix length of the network.",
158+
Computed: true,
159+
},
160+
"ipv6_prefixes": schema.ListAttribute{
161+
Description: "The IPv6 prefixes of the network.",
120162
Computed: true,
121163
ElementType: types.StringType,
122164
},
@@ -129,6 +171,10 @@ func (d *networkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest
129171
ElementType: types.StringType,
130172
Computed: true,
131173
},
174+
"routed": schema.BoolAttribute{
175+
Description: "Shows if the network is routed and therefore accessible from other networks.",
176+
Computed: true,
177+
},
132178
},
133179
}
134180
}

0 commit comments

Comments
 (0)