From 48b51dddcb3c930d9387dfb8f7168e7b8b0829d5 Mon Sep 17 00:00:00 2001 From: Hannes Baum Date: Thu, 9 Jul 2026 10:45:26 +0200 Subject: [PATCH] feat: integrate vpc in network Integrate the vpc data into the network resource. Signed-off-by: Hannes Baum --- docs/data-sources/network.md | 1 + docs/resources/network.md | 14 ++++++++++++++ examples/resources/stackit_network/resource.tf | 13 +++++++++++++ .../internal/services/iaas/network/datasource.go | 9 +++++++++ stackit/internal/services/iaas/network/resource.go | 12 ++++++++++++ 5 files changed, 49 insertions(+) diff --git a/docs/data-sources/network.md b/docs/data-sources/network.md index 8b736b6e1..ac3387dbd 100644 --- a/docs/data-sources/network.md +++ b/docs/data-sources/network.md @@ -30,6 +30,7 @@ data "stackit_network" "example" { ### Optional - `region` (String) The resource region. If not defined, the provider region is used. +- `vpc_id` (String) The ID of the VPC the network is associated with. ### Read-Only diff --git a/docs/resources/network.md b/docs/resources/network.md index a31c14ea7..c36deeefc 100644 --- a/docs/resources/network.md +++ b/docs/resources/network.md @@ -44,6 +44,19 @@ resource "stackit_network" "example_non_routed_network" { } routed = false } + +resource "stackit_network" "example_vpc_network" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + name = "example-vpc-network" + ipv4_nameservers = ["1.2.3.4", "5.6.7.8"] + ipv4_gateway = "10.1.2.3" + ipv4_prefix = "10.1.2.0/24" + labels = { + "key" = "value" + } + routed = false + vpc_id = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" +} ``` @@ -71,6 +84,7 @@ resource "stackit_network" "example_non_routed_network" { - `region` (String) The resource region. If not defined, the provider region is used. - `routed` (Boolean) If set to `true`, the network is routed and therefore accessible from other networks. - `routing_table_id` (String) The ID of the routing table associated with the network. +- `vpc_id` (String) The ID of the VPC the network is associated with. ### Read-Only diff --git a/examples/resources/stackit_network/resource.tf b/examples/resources/stackit_network/resource.tf index c06f00641..be69ba4e4 100644 --- a/examples/resources/stackit_network/resource.tf +++ b/examples/resources/stackit_network/resource.tf @@ -23,3 +23,16 @@ resource "stackit_network" "example_non_routed_network" { } routed = false } + +resource "stackit_network" "example_vpc_network" { + project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + name = "example-vpc-network" + ipv4_nameservers = ["1.2.3.4", "5.6.7.8"] + ipv4_gateway = "10.1.2.3" + ipv4_prefix = "10.1.2.0/24" + labels = { + "key" = "value" + } + routed = false + vpc_id = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" +} diff --git a/stackit/internal/services/iaas/network/datasource.go b/stackit/internal/services/iaas/network/datasource.go index d5766dc5b..c6ca0e840 100644 --- a/stackit/internal/services/iaas/network/datasource.go +++ b/stackit/internal/services/iaas/network/datasource.go @@ -48,6 +48,7 @@ type DataSourceModel struct { Region types.String `tfsdk:"region"` RoutingTableID types.String `tfsdk:"routing_table_id"` DHCP types.Bool `tfsdk:"dhcp"` + VPCID types.String `tfsdk:"vpc_id"` } // NewNetworkDataSource is a helper function to simplify the provider implementation. @@ -190,6 +191,14 @@ func (d *networkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest Description: "Shows if DHCP is enabled for the network.", Computed: true, }, + "vpc_id": schema.StringAttribute{ + Description: "The ID of the VPC the network is associated with.", + Optional: true, + Validators: []validator.String{ + validate.UUID(), + validate.NoSeparator(), + }, + }, }, } } diff --git a/stackit/internal/services/iaas/network/resource.go b/stackit/internal/services/iaas/network/resource.go index c5faebbdf..06ccff746 100644 --- a/stackit/internal/services/iaas/network/resource.go +++ b/stackit/internal/services/iaas/network/resource.go @@ -74,6 +74,7 @@ type Model struct { Region types.String `tfsdk:"region"` RoutingTableID types.String `tfsdk:"routing_table_id"` DHCP types.Bool `tfsdk:"dhcp"` + VPCID types.String `tfsdk:"vpc_id"` } // NewNetworkResource is a helper function to simplify the provider implementation. @@ -404,6 +405,17 @@ func (r *networkResource) Schema(_ context.Context, _ resource.SchemaRequest, re boolplanmodifier.UseStateForUnknown(), }, }, + "vpc_id": schema.StringAttribute{ + Description: "The ID of the VPC the network is associated with.", + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + Validators: []validator.String{ + validate.UUID(), + validate.NoSeparator(), + }, + }, }, } }