diff --git a/go.mod b/go.mod index ca9331eab..546ae477a 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/stackitcloud/stackit-sdk-go/services/edge v0.3.0 github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1 github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0 - github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.23-alpha github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0 github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.6.2 github.com/stackitcloud/stackit-sdk-go/services/logme v0.25.3 diff --git a/go.sum b/go.sum index 2116923b4..294dadf9e 100644 --- a/go.sum +++ b/go.sum @@ -163,8 +163,6 @@ github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1 h1:3JKXfI5hdcXcRVBjU github.com/stackitcloud/stackit-sdk-go/services/git v0.10.1/go.mod h1:3nTaj8IGjNNGYUD2CpuXkXwc5c4giTUmoPggFhjVFxo= github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0 h1:U/x0tc487X9msMS5yZYjrBAAKrCx87Trmt0kh8JiARA= github.com/stackitcloud/stackit-sdk-go/services/iaas v1.3.0/go.mod h1:6+5+RCDfU7eQN3+/SGdOtx7Bq9dEa2FrHz/jflgY1M4= -github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.23-alpha h1:ugpMOMUZGB0yXsWcfe97F7GCdjlexbjFuGD8ZeyMSts= -github.com/stackitcloud/stackit-sdk-go/services/iaasalpha v0.1.23-alpha/go.mod h1:v5VGvTxLcCdJJmblbhqYalt/MFHcElDfYoy15CMhaWs= github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0 h1:Ar2n9GKmrTN80G/Ta1R+fL5aX5nEoxL6ODVJl3emzho= github.com/stackitcloud/stackit-sdk-go/services/kms v1.2.0/go.mod h1:sHMFoYvVrkRZcH13DkLvp48nW+ssRVVVuwqJHDGpa5M= github.com/stackitcloud/stackit-sdk-go/services/loadbalancer v1.6.2 h1:DwwRMzvnKWTbfmLvq2xe+mYhv5fA1AwWdQGznI05sGc= diff --git a/stackit/internal/services/iaas/iaas_acc_test.go b/stackit/internal/services/iaas/iaas_acc_test.go index 74a7dc909..0d54171dd 100644 --- a/stackit/internal/services/iaas/iaas_acc_test.go +++ b/stackit/internal/services/iaas/iaas_acc_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/plancheck" + "github.com/stackitcloud/stackit-sdk-go/services/iaas/wait" "github.com/hashicorp/terraform-plugin-testing/config" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -23,8 +24,6 @@ import ( "github.com/stackitcloud/stackit-sdk-go/core/oapierror" "github.com/stackitcloud/stackit-sdk-go/core/utils" "github.com/stackitcloud/stackit-sdk-go/services/iaas" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" - waitAlpha "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha/wait" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" ) @@ -98,6 +97,18 @@ var ( //go:embed testdata/datasource-machinetype.tf dataSourceMachineTypeConfig string + + //go:embed testdata/resource-routingtable-min.tf + resourceRoutingTableMinConfig string + + //go:embed testdata/resource-routingtable-max.tf + resourceRoutingTableMaxConfig string + + //go:embed testdata/resource-routingtable-route-min.tf + resourceRoutingTableRouteMinConfig string + + //go:embed testdata/resource-routingtable-route-max.tf + resourceRoutingTableRouteMaxConfig string ) const ( @@ -291,7 +302,7 @@ var testConfigNetworkVarsMaxUpdated = func() config.Variables { var testConfigNetworkAreaVarsMin = config.Variables{ "organization_id": config.StringVariable(testutil.OrganizationId), - "name": config.StringVariable(fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha))), + "name": config.StringVariable(fmt.Sprintf("GGK-tf-acc-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha))), } var testConfigNetworkAreaVarsMinUpdated = func() config.Variables { @@ -307,7 +318,7 @@ var testConfigNetworkAreaVarsMinUpdated = func() config.Variables { var testConfigNetworkAreaVarsMax = config.Variables{ "organization_id": config.StringVariable(testutil.OrganizationId), - "name": config.StringVariable(fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha))), + "name": config.StringVariable(fmt.Sprintf("GGK-tf-acc-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha))), "transfer_network": config.StringVariable("10.1.2.0/24"), "network_ranges_prefix": config.StringVariable("10.0.0.0/16"), "default_nameservers": config.StringVariable("1.1.1.1"), @@ -552,6 +563,75 @@ var testConfigMachineTypeVars = config.Variables{ "project_id": config.StringVariable(testutil.ProjectId), } +var testConfigRoutingTableMin = config.Variables{ + "organization_id": config.StringVariable(testutil.OrganizationId), + "name": config.StringVariable(fmt.Sprintf("GGK-acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), +} + +var testConfigRoutingTableMinUpdated = func() config.Variables { + updatedConfig := config.Variables{} + maps.Copy(updatedConfig, testConfigRoutingTableMin) + updatedConfig["name"] = config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))) + return updatedConfig +}() + +var testConfigRoutingTableMax = config.Variables{ + "organization_id": config.StringVariable(testutil.OrganizationId), + "name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), + "description": config.StringVariable("This is the description of the routing table."), + "label": config.StringVariable("routing-table-label-01"), + "system_routes": config.BoolVariable(false), + "dynamic_routes": config.BoolVariable(false), + "region": config.StringVariable(testutil.Region), +} + +var testConfigRoutingTableMaxUpdated = func() config.Variables { + updatedConfig := config.Variables{} + for k, v := range testConfigRoutingTableMax { + updatedConfig[k] = v + } + updatedConfig["name"] = config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))) + updatedConfig["description"] = config.StringVariable("This is the updated description of the routing table.") + updatedConfig["label"] = config.StringVariable("routing-table-updated-label-01") + updatedConfig["dynamic_routes"] = config.BoolVariable(true) + return updatedConfig +}() + +var testConfigRoutingTableRouteMin = config.Variables{ + "organization_id": config.StringVariable(testutil.OrganizationId), + "name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), + "routing_table_name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), + "destination_type": config.StringVariable("cidrv4"), + "destination_value": config.StringVariable("192.168.178.0/24"), + "next_hop_type": config.StringVariable("ipv4"), + "next_hop_value": config.StringVariable("192.168.178.1"), +} + +var testConfigRoutingTableRouteMinUpdated = func() config.Variables { + updatedConfig := config.Variables{} + maps.Copy(updatedConfig, testConfigRoutingTableRouteMin) + // nothing possible to update of the required attributes... + return updatedConfig +}() + +var testConfigRoutingTableRouteMax = config.Variables{ + "organization_id": config.StringVariable(testutil.OrganizationId), + "name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), + "routing_table_name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), + "destination_type": config.StringVariable("cidrv4"), // TODO: use cidrv6 once it's supported as we already test cidrv4 in the min test + "destination_value": config.StringVariable("192.168.178.0/24"), + "next_hop_type": config.StringVariable("ipv4"), // TODO: use ipv6, internet or blackhole once they are supported as we already test ipv4 in the min test + "next_hop_value": config.StringVariable("192.168.178.1"), + "label": config.StringVariable("route-label-01"), +} + +var testConfigRoutingTableRouteMaxUpdated = func() config.Variables { + updatedConfig := config.Variables{} + maps.Copy(updatedConfig, testConfigRoutingTableRouteMax) + updatedConfig["label"] = config.StringVariable("route-updated-label-01") + return updatedConfig +}() + // if no local file is provided the test should create a default file and work with this instead of failing var localFileForIaasImage os.File @@ -4604,132 +4684,876 @@ func TestAccMachineType(t *testing.T) { }) } -func testAccCheckDestroy(s *terraform.State) error { - checkFunctions := []func(s *terraform.State) error{ - testAccCheckIaaSVolumeDestroy, - testAccCheckServerDestroy, - testAccCheckAffinityGroupDestroy, - testAccCheckIaaSSecurityGroupDestroy, - testAccCheckIaaSPublicIpDestroy, - testAccCheckIaaSKeyPairDestroy, - testAccCheckIaaSImageDestroy, - testAccCheckNetworkDestroy, - testAccCheckNetworkInterfaceDestroy, - testAccCheckNetworkAreaRegionDestroy, - testAccCheckNetworkAreaDestroy, - } - var errs []error - - wg := sync.WaitGroup{} - wg.Add(len(checkFunctions)) - - for _, f := range checkFunctions { - go func() { - err := f(s) - if err != nil { - errs = append(errs, err) - } - wg.Done() - }() - } - wg.Wait() - return errors.Join(errs...) -} +func TestAccRoutingTableMin(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, + CheckDestroy: testAccCheckDestroy, + Steps: []resource.TestStep{ + // Creation + { + ConfigVariables: testConfigRoutingTableMin, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Network Area + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_network_area_region.network_area_region", "network_area_id", + ), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.transfer_network", "10.1.2.0/24"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.#", "2"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.prefix", "10.0.0.0/16"), + resource.TestCheckResourceAttrSet("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.network_range_id"), + resource.TestCheckNoResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_nameservers.#"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_prefix_length", "25"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.min_prefix_length", "24"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.max_prefix_length", "29"), // default value -func testAccCheckNetworkDestroy(s *terraform.State) error { - ctx := context.Background() - var client *iaasalpha.APIClient - var err error - if testutil.IaaSCustomEndpoint == "" { - client, err = iaasalpha.NewAPIClient() - } else { - client, err = iaasalpha.NewAPIClient( - stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), - ) - } - if err != nil { - return fmt.Errorf("creating client: %w", err) - } + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), - var errs []error - // networks - for _, rs := range s.RootModule().Resources { - if rs.Type != "stackit_network" { - continue - } - region := strings.Split(rs.Primary.ID, core.Separator)[1] - networkId := strings.Split(rs.Primary.ID, core.Separator)[2] - err := client.DeleteNetworkExecute(ctx, testutil.ProjectId, region, networkId) - if err != nil { - var oapiErr *oapierror.GenericOpenAPIError - if errors.As(err, &oapiErr) { - if oapiErr.StatusCode == http.StatusNotFound { - continue - } - } - errs = append(errs, fmt.Errorf("cannot trigger network deletion %q: %w", networkId, err)) - } - _, err = waitAlpha.DeleteNetworkWaitHandler(ctx, client, testutil.ProjectId, region, networkId).WaitWithContext(ctx) - if err != nil { - errs = append(errs, fmt.Errorf("cannot delete network %q: %w", networkId, err)) - } - } + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), - return errors.Join(errs...) -} + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "0"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region), + resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), + ), + }, + // Data sources + { + ConfigVariables: testConfigRoutingTableMin, + Config: fmt.Sprintf(` + %s + %s + + # single routing table + data "stackit_routing_table" "routing_table" { + organization_id = stackit_routing_table.routing_table.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + routing_table_id = stackit_routing_table.routing_table.routing_table_id + } + + # all routing tables in network area + data "stackit_routing_tables" "routing_tables" { + organization_id = stackit_routing_table.routing_table.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + } + `, + testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig, + ), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "data.stackit_routing_table.routing_table", "routing_table_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.%", "0"), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.Region), + resource.TestCheckNoResourceAttr("data.stackit_routing_table.routing_table", "description"), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", "true"), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", "true"), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"), -func testAccCheckNetworkInterfaceDestroy(s *terraform.State) error { - ctx := context.Background() - var client *iaas.APIClient - var err error - if testutil.IaaSCustomEndpoint == "" { - client, err = iaas.NewAPIClient() - } else { - client, err = iaas.NewAPIClient( - stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), - ) - } - if err != nil { - return fmt.Errorf("creating client: %w", err) - } + // Routing tables + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_tables.routing_tables", "network_area_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "region", testutil.Region), + // there will be always two routing tables because of the main routing table of the network area + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.#", "2"), - var errs []error - // network interfaces - for _, rs := range s.RootModule().Resources { - if rs.Type != "stackit_network_interface" { - continue - } - ids := strings.Split(rs.Primary.ID, core.Separator) - region := ids[1] - networkId := ids[2] - networkInterfaceId := ids[3] - err := client.DeleteNicExecute(ctx, testutil.ProjectId, region, networkId, networkInterfaceId) - if err != nil { - var oapiErr *oapierror.GenericOpenAPIError - if errors.As(err, &oapiErr) { - if oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusBadRequest { - continue - } - } - errs = append(errs, fmt.Errorf("cannot trigger network interface deletion %q: %w", networkInterfaceId, err)) - } - if err != nil { - errs = append(errs, fmt.Errorf("cannot delete network interface %q: %w", networkInterfaceId, err)) - } - } + // default routing table + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.0.default", "true"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.updated_at"), - return errors.Join(errs...) + // second routing table managed via terraform + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "data.stackit_routing_tables.routing_tables", "items.1.routing_table_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.%", "0"), + resource.TestCheckNoResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description"), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", "true"), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", "true"), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"), + ), + }, + // Import + { + ConfigVariables: testConfigRoutingTableMinUpdated, + ResourceName: "stackit_routing_table.routing_table", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + r, ok := s.RootModule().Resources["stackit_routing_table.routing_table"] + if !ok { + return "", fmt.Errorf("couldn't find resource stackit_routing_table.routing_table") + } + region, ok := r.Primary.Attributes["region"] + if !ok { + return "", fmt.Errorf("couldn't find attribute region") + } + networkAreaId, ok := r.Primary.Attributes["network_area_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute network_area_id") + } + routingTableId, ok := r.Primary.Attributes["routing_table_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute routing_table_id") + } + return fmt.Sprintf("%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId), nil + }, + ImportState: true, + ImportStateVerify: true, + }, + // Update + { + ConfigVariables: testConfigRoutingTableMinUpdated, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["name"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "0"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region), + resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), + ), + }, + // Deletion is done by the framework implicitly + }, + }) } -func testAccCheckNetworkAreaRegionDestroy(s *terraform.State) error { - ctx := context.Background() - var client *iaas.APIClient - var err error - if testutil.IaaSCustomEndpoint == "" { - client, err = iaas.NewAPIClient() - } else { - client, err = iaas.NewAPIClient( - stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), +func TestAccRoutingTableMax(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, + CheckDestroy: testAccCheckDestroy, + Steps: []resource.TestStep{ + // Creation + { + ConfigVariables: testConfigRoutingTableMax, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Network Area + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_network_area_region.network_area_region", "network_area_id", + ), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.transfer_network", "10.1.2.0/24"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.#", "2"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.prefix", "10.0.0.0/16"), + resource.TestCheckResourceAttrSet("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.network_range_id"), + resource.TestCheckNoResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_nameservers.#"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_prefix_length", "25"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.min_prefix_length", "24"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.max_prefix_length", "29"), // default value + + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "1"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), + ), + }, + // Data sources + { + ConfigVariables: testConfigRoutingTableMax, + Config: fmt.Sprintf(` + %s + %s + + # single routing table + data "stackit_routing_table" "routing_table" { + organization_id = stackit_routing_table.routing_table.organization_id + network_area_id = stackit_routing_table.routing_table.network_area_id + routing_table_id = stackit_routing_table.routing_table.routing_table_id + } + + # all routing tables in network area + data "stackit_routing_tables" "routing_tables" { + organization_id = stackit_routing_table.routing_table.organization_id + network_area_id = stackit_routing_table.routing_table.network_area_id + } + `, + testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig, + ), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "data.stackit_routing_table.routing_table", "routing_table_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.%", "1"), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), + resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"), + + // Routing tables + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_tables.routing_tables", "network_area_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), + // there will be always two routing tables because of the main routing table of the network area + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.#", "2"), + + // default routing table + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.0.default", "true"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.updated_at"), + + // second routing table managed via terraform + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "data.stackit_routing_tables.routing_tables", "items.1.routing_table_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.%", "1"), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), + resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"), + ), + }, + // Import + { + ConfigVariables: testConfigRoutingTableMaxUpdated, + ResourceName: "stackit_routing_table.routing_table", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + r, ok := s.RootModule().Resources["stackit_routing_table.routing_table"] + if !ok { + return "", fmt.Errorf("couldn't find resource stackit_routing_table.routing_table") + } + region, ok := r.Primary.Attributes["region"] + if !ok { + return "", fmt.Errorf("couldn't find attribute region") + } + networkAreaId, ok := r.Primary.Attributes["network_area_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute network_area_id") + } + routingTableId, ok := r.Primary.Attributes["routing_table_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute routing_table_id") + } + return fmt.Sprintf("%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId), nil + }, + ImportState: true, + ImportStateVerify: true, + }, + // Update + { + ConfigVariables: testConfigRoutingTableMaxUpdated, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["name"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "1"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["label"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["region"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["description"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["system_routes"])), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["dynamic_routes"])), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), + ), + }, + // Deletion is done by the framework implicitly + }, + }) +} + +func TestAccRoutingTableRouteMin(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, + CheckDestroy: testAccCheckDestroy, + Steps: []resource.TestStep{ + // Creation + { + ConfigVariables: testConfigRoutingTableRouteMin, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Network Area + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_network_area_region.network_area_region", "network_area_id", + ), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.transfer_network", "10.1.2.0/24"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.#", "2"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.prefix", "10.0.0.0/16"), + resource.TestCheckResourceAttrSet("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.network_range_id"), + resource.TestCheckNoResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_nameservers.#"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_prefix_length", "25"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.min_prefix_length", "24"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.max_prefix_length", "29"), // default value + + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["routing_table_name"])), + + // Routing table route + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "0"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), + ), + }, + // Data sources + { + ConfigVariables: testConfigRoutingTableRouteMin, + Config: fmt.Sprintf(` + %s + %s + + # single routing table route + data "stackit_routing_table_route" "route" { + organization_id = stackit_routing_table_route.route.organization_id + network_area_id = stackit_routing_table_route.route.network_area_id + routing_table_id = stackit_routing_table_route.route.routing_table_id + route_id = stackit_routing_table_route.route.route_id + } + + # all routing table routes in routing table + data "stackit_routing_table_routes" "routes" { + organization_id = stackit_routing_table_route.route.organization_id + network_area_id = stackit_routing_table_route.route.network_area_id + routing_table_id = stackit_routing_table_route.route.routing_table_id + } + `, + testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig, + ), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table route + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "data.stackit_routing_table_route.route", "network_area_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "routing_table_id", + "data.stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "route_id", + "data.stackit_routing_table_route.route", "route_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.%", "0"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "updated_at"), + + // Routing table routes + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_table_routes.routes", "network_area_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "region", testutil.Region), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.#", "1"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "routing_table_id", + "data.stackit_routing_table_routes.routes", "routing_table_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "route_id", + "data.stackit_routing_table_routes.routes", "routes.0.route_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.%", "0"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.updated_at"), + ), + }, + // Import + { + ConfigVariables: testConfigRoutingTableRouteMinUpdated, + ResourceName: "stackit_routing_table_route.route", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + r, ok := s.RootModule().Resources["stackit_routing_table_route.route"] + if !ok { + return "", fmt.Errorf("couldn't find resource stackit_routing_table_route.route") + } + region, ok := r.Primary.Attributes["region"] + if !ok { + return "", fmt.Errorf("couldn't find attribute region") + } + networkAreaId, ok := r.Primary.Attributes["network_area_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute network_area_id") + } + routingTableId, ok := r.Primary.Attributes["routing_table_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute routing_table_id") + } + routeId, ok := r.Primary.Attributes["route_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute route_id") + } + return fmt.Sprintf("%s,%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId, routeId), nil + }, + ImportState: true, + ImportStateVerify: true, + }, + // Update + { + ConfigVariables: testConfigRoutingTableRouteMinUpdated, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["routing_table_name"])), + + // Routing table route + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["destination_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["destination_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["next_hop_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["next_hop_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "0"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), + ), + }, + // Deletion is done by the framework implicitly + }, + }) +} + +func TestAccRoutingTableRouteMax(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, + CheckDestroy: testAccCheckDestroy, + Steps: []resource.TestStep{ + // Creation + { + ConfigVariables: testConfigRoutingTableRouteMax, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Network Area + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_network_area_region.network_area_region", "network_area_id", + ), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.transfer_network", "10.1.2.0/24"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.#", "2"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.prefix", "10.0.0.0/16"), + resource.TestCheckResourceAttrSet("stackit_network_area_region.network_area_region", "ipv4.network_ranges.0.network_range_id"), + resource.TestCheckNoResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_nameservers.#"), + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.default_prefix_length", "25"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.min_prefix_length", "24"), // default value + resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "ipv4.max_prefix_length", "29"), // default value + + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["routing_table_name"])), + + // Routing table route + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "1"), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), + ), + }, + // Data sources + { + ConfigVariables: testConfigRoutingTableRouteMax, + Config: fmt.Sprintf(` + %s + %s + + # single routing table route + data "stackit_routing_table_route" "route" { + organization_id = stackit_routing_table_route.route.organization_id + network_area_id = stackit_routing_table_route.route.network_area_id + routing_table_id = stackit_routing_table_route.route.routing_table_id + route_id = stackit_routing_table_route.route.route_id + } + + # all routing table routes in routing table + data "stackit_routing_table_routes" "routes" { + organization_id = stackit_routing_table_route.route.organization_id + network_area_id = stackit_routing_table_route.route.network_area_id + routing_table_id = stackit_routing_table_route.route.routing_table_id + } + `, + testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig, + ), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table route + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "data.stackit_routing_table_route.route", "network_area_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "routing_table_id", + "data.stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "route_id", + "data.stackit_routing_table_route.route", "route_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.%", "1"), + resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "updated_at"), + + // Routing table routes + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "data.stackit_routing_table_routes.routes", "network_area_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "region", testutil.Region), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.#", "1"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "routing_table_id", + "data.stackit_routing_table_routes.routes", "routing_table_id", + ), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "route_id", + "data.stackit_routing_table_routes.routes", "routes.0.route_id", + ), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.%", "1"), + resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.created_at"), + resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.updated_at"), + ), + }, + // Import + { + ConfigVariables: testConfigRoutingTableRouteMaxUpdated, + ResourceName: "stackit_routing_table_route.route", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + r, ok := s.RootModule().Resources["stackit_routing_table_route.route"] + if !ok { + return "", fmt.Errorf("couldn't find resource stackit_routing_table_route.route") + } + region, ok := r.Primary.Attributes["region"] + if !ok { + return "", fmt.Errorf("couldn't find attribute region") + } + networkAreaId, ok := r.Primary.Attributes["network_area_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute network_area_id") + } + routingTableId, ok := r.Primary.Attributes["routing_table_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute routing_table_id") + } + routeId, ok := r.Primary.Attributes["route_id"] + if !ok { + return "", fmt.Errorf("couldn't find attribute route_id") + } + return fmt.Sprintf("%s,%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId, routeId), nil + }, + ImportState: true, + ImportStateVerify: true, + }, + // Update + { + ConfigVariables: testConfigRoutingTableRouteMaxUpdated, + Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig), + Check: resource.ComposeAggregateTestCheckFunc( + // Routing table + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_network_area.network_area", "network_area_id", + "stackit_routing_table.routing_table", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), + resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["routing_table_name"])), + + // Routing table route + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["organization_id"])), + resource.TestCheckResourceAttrPair( + "stackit_routing_table_route.route", "network_area_id", + "stackit_network_area.network_area", "network_area_id", + ), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), + resource.TestCheckResourceAttrPair( + "stackit_routing_table.routing_table", "routing_table_id", + "stackit_routing_table_route.route", "routing_table_id", + ), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["destination_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["destination_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["next_hop_type"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["next_hop_value"])), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "1"), + resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["label"])), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), + resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), + ), + }, + // Deletion is done by the framework implicitly + }, + }) +} + +func testAccCheckDestroy(s *terraform.State) error { + checkFunctions := []func(s *terraform.State) error{ + testAccCheckIaaSVolumeDestroy, + testAccCheckServerDestroy, + testAccCheckAffinityGroupDestroy, + testAccCheckIaaSSecurityGroupDestroy, + testAccCheckIaaSPublicIpDestroy, + testAccCheckIaaSKeyPairDestroy, + testAccCheckIaaSImageDestroy, + testAccCheckNetworkDestroy, + testAccCheckNetworkInterfaceDestroy, + testAccCheckNetworkAreaRegionDestroy, + testAccCheckNetworkAreaDestroy, + testAccCheckRoutingTableDestroy, + testAccCheckRoutingTableRouteDestroy, + } + var errs []error + + wg := sync.WaitGroup{} + wg.Add(len(checkFunctions)) + + for _, f := range checkFunctions { + go func() { + err := f(s) + if err != nil { + errs = append(errs, err) + } + wg.Done() + }() + } + wg.Wait() + return errors.Join(errs...) +} + +func testAccCheckNetworkDestroy(s *terraform.State) error { + ctx := context.Background() + var client *iaas.APIClient + var err error + if testutil.IaaSCustomEndpoint == "" { + client, err = iaas.NewAPIClient() + } else { + client, err = iaas.NewAPIClient( + stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), + ) + } + if err != nil { + return fmt.Errorf("creating client: %w", err) + } + + var errs []error + // networks + for _, rs := range s.RootModule().Resources { + if rs.Type != "stackit_network" { + continue + } + region := strings.Split(rs.Primary.ID, core.Separator)[1] + networkId := strings.Split(rs.Primary.ID, core.Separator)[2] + err := client.DeleteNetworkExecute(ctx, testutil.ProjectId, region, networkId) + if err != nil { + var oapiErr *oapierror.GenericOpenAPIError + if errors.As(err, &oapiErr) { + if oapiErr.StatusCode == http.StatusNotFound { + continue + } + } + errs = append(errs, fmt.Errorf("cannot trigger network deletion %q: %w", networkId, err)) + } + _, err = wait.DeleteNetworkWaitHandler(ctx, client, testutil.ProjectId, region, networkId).WaitWithContext(ctx) + if err != nil { + errs = append(errs, fmt.Errorf("cannot delete network %q: %w", networkId, err)) + } + } + + return errors.Join(errs...) +} + +func testAccCheckNetworkInterfaceDestroy(s *terraform.State) error { + ctx := context.Background() + var client *iaas.APIClient + var err error + if testutil.IaaSCustomEndpoint == "" { + client, err = iaas.NewAPIClient() + } else { + client, err = iaas.NewAPIClient( + stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), + ) + } + if err != nil { + return fmt.Errorf("creating client: %w", err) + } + + var errs []error + // network interfaces + for _, rs := range s.RootModule().Resources { + if rs.Type != "stackit_network_interface" { + continue + } + ids := strings.Split(rs.Primary.ID, core.Separator) + region := ids[1] + networkId := ids[2] + networkInterfaceId := ids[3] + err := client.DeleteNicExecute(ctx, testutil.ProjectId, region, networkId, networkInterfaceId) + if err != nil { + var oapiErr *oapierror.GenericOpenAPIError + if errors.As(err, &oapiErr) { + if oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusBadRequest { + continue + } + } + errs = append(errs, fmt.Errorf("cannot trigger network interface deletion %q: %w", networkInterfaceId, err)) + } + if err != nil { + errs = append(errs, fmt.Errorf("cannot delete network interface %q: %w", networkInterfaceId, err)) + } + } + + return errors.Join(errs...) +} + +func testAccCheckNetworkAreaRegionDestroy(s *terraform.State) error { + ctx := context.Background() + var client *iaas.APIClient + var err error + if testutil.IaaSCustomEndpoint == "" { + client, err = iaas.NewAPIClient() + } else { + client, err = iaas.NewAPIClient( + stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), ) } if err != nil { @@ -5162,3 +5986,83 @@ func testAccCheckIaaSImageDestroy(s *terraform.State) error { } return nil } + +func testAccCheckRoutingTableDestroy(s *terraform.State) error { + ctx := context.Background() + var client *iaas.APIClient + var err error + if testutil.IaaSCustomEndpoint == "" { + client, err = iaas.NewAPIClient() + } else { + client, err = iaas.NewAPIClient( + stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), + ) + } + if err != nil { + return fmt.Errorf("creating client: %w", err) + } + + var errs []error + // routing tables + for _, rs := range s.RootModule().Resources { + if rs.Type != "stackit_routing_table" { + continue + } + routingTableId := strings.Split(rs.Primary.ID, core.Separator)[3] + networkAreaId := strings.Split(rs.Primary.ID, core.Separator)[2] + region := strings.Split(rs.Primary.ID, core.Separator)[1] + err := client.DeleteRoutingTableFromAreaExecute(ctx, testutil.OrganizationId, networkAreaId, region, routingTableId) + if err != nil { + var oapiErr *oapierror.GenericOpenAPIError + if errors.As(err, &oapiErr) { + if oapiErr.StatusCode == http.StatusNotFound { + continue + } + } + errs = append(errs, fmt.Errorf("cannot trigger routing table deletion %q: %w", routingTableId, err)) + } + } + + return errors.Join(errs...) +} + +func testAccCheckRoutingTableRouteDestroy(s *terraform.State) error { + ctx := context.Background() + var client *iaas.APIClient + var err error + if testutil.IaaSCustomEndpoint == "" { + client, err = iaas.NewAPIClient() + } else { + client, err = iaas.NewAPIClient( + stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), + ) + } + if err != nil { + return fmt.Errorf("creating client: %w", err) + } + + var errs []error + // routes + for _, rs := range s.RootModule().Resources { + if rs.Type != "stackit_routing_table_route" { + continue + } + routingTableRouteId := strings.Split(rs.Primary.ID, core.Separator)[4] + routingTableId := strings.Split(rs.Primary.ID, core.Separator)[3] + networkAreaId := strings.Split(rs.Primary.ID, core.Separator)[2] + region := strings.Split(rs.Primary.ID, core.Separator)[1] + + err := client.DeleteRouteFromRoutingTableExecute(ctx, testutil.OrganizationId, networkAreaId, region, routingTableId, routingTableRouteId) + if err != nil { + var oapiErr *oapierror.GenericOpenAPIError + if errors.As(err, &oapiErr) { + if oapiErr.StatusCode == http.StatusNotFound { + continue + } + } + errs = append(errs, fmt.Errorf("cannot trigger routing table route deletion %q: %w", routingTableId, err)) + } + } + + return errors.Join(errs...) +} diff --git a/stackit/internal/services/iaasalpha/routingtable/route/datasource.go b/stackit/internal/services/iaas/routingtable/route/datasource.go similarity index 92% rename from stackit/internal/services/iaasalpha/routingtable/route/datasource.go rename to stackit/internal/services/iaas/routingtable/route/datasource.go index bd978c073..5d05f705d 100644 --- a/stackit/internal/services/iaasalpha/routingtable/route/datasource.go +++ b/stackit/internal/services/iaas/routingtable/route/datasource.go @@ -5,16 +5,15 @@ import ( "fmt" "net/http" - shared "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" - "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" + shared "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" + iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) @@ -30,7 +29,7 @@ func NewRoutingTableRouteDataSource() datasource.DataSource { // routingTableRouteDataSource is the data source implementation. type routingTableRouteDataSource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -51,7 +50,7 @@ func (d *routingTableRouteDataSource) Configure(ctx context.Context, req datasou return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } diff --git a/stackit/internal/services/iaasalpha/routingtable/route/resource.go b/stackit/internal/services/iaas/routingtable/route/resource.go similarity index 92% rename from stackit/internal/services/iaasalpha/routingtable/route/resource.go rename to stackit/internal/services/iaas/routingtable/route/resource.go index 4ca101040..6324b1bce 100644 --- a/stackit/internal/services/iaasalpha/routingtable/route/resource.go +++ b/stackit/internal/services/iaas/routingtable/route/resource.go @@ -5,7 +5,9 @@ import ( "fmt" "strings" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" + iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -17,11 +19,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" ) @@ -41,7 +41,7 @@ func NewRoutingTableRouteResource() resource.Resource { // routeResource is the resource implementation. type routeResource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -63,7 +63,7 @@ func (r *routeResource) Configure(ctx context.Context, req resource.ConfigureReq return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } @@ -461,7 +461,7 @@ func (r *routeResource) ImportState(ctx context.Context, req resource.ImportStat tflog.Info(ctx, "Routing table route state imported") } -func mapFieldsFromList(ctx context.Context, routeResp *iaasalpha.RouteListResponse, model *shared.RouteModel, region string) error { +func mapFieldsFromList(ctx context.Context, routeResp *iaas.RouteListResponse, model *shared.RouteModel, region string) error { if routeResp == nil || routeResp.Items == nil { return fmt.Errorf("response input is nil") } else if len(*routeResp.Items) < 1 { @@ -474,7 +474,7 @@ func mapFieldsFromList(ctx context.Context, routeResp *iaasalpha.RouteListRespon return shared.MapRouteModel(ctx, &route, model, region) } -func toCreatePayload(ctx context.Context, model *shared.RouteReadModel) (*iaasalpha.AddRoutesToRoutingTablePayload, error) { +func toCreatePayload(ctx context.Context, model *shared.RouteReadModel) (*iaas.AddRoutesToRoutingTablePayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -493,8 +493,8 @@ func toCreatePayload(ctx context.Context, model *shared.RouteReadModel) (*iaasal return nil, err } - return &iaasalpha.AddRoutesToRoutingTablePayload{ - Items: &[]iaasalpha.Route{ + return &iaas.AddRoutesToRoutingTablePayload{ + Items: &[]iaas.Route{ { Labels: &labels, Nexthop: nextHopPayload, @@ -504,7 +504,7 @@ func toCreatePayload(ctx context.Context, model *shared.RouteReadModel) (*iaasal }, nil } -func toUpdatePayload(ctx context.Context, model *shared.RouteModel, currentLabels types.Map) (*iaasalpha.UpdateRouteOfRoutingTablePayload, error) { +func toUpdatePayload(ctx context.Context, model *shared.RouteModel, currentLabels types.Map) (*iaas.UpdateRouteOfRoutingTablePayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -514,12 +514,12 @@ func toUpdatePayload(ctx context.Context, model *shared.RouteModel, currentLabel return nil, fmt.Errorf("converting to Go map: %w", err) } - return &iaasalpha.UpdateRouteOfRoutingTablePayload{ + return &iaas.UpdateRouteOfRoutingTablePayload{ Labels: &labels, }, nil } -func toNextHopPayload(ctx context.Context, model *shared.RouteReadModel) (*iaasalpha.RouteNexthop, error) { +func toNextHopPayload(ctx context.Context, model *shared.RouteReadModel) (*iaas.RouteNexthop, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -535,18 +535,18 @@ func toNextHopPayload(ctx context.Context, model *shared.RouteReadModel) (*iaasa switch nexthopModel.Type.ValueString() { case "blackhole": - return sdkUtils.Ptr(iaasalpha.NexthopBlackholeAsRouteNexthop(iaasalpha.NewNexthopBlackhole("blackhole"))), nil + return sdkUtils.Ptr(iaas.NexthopBlackholeAsRouteNexthop(iaas.NewNexthopBlackhole("blackhole"))), nil case "internet": - return sdkUtils.Ptr(iaasalpha.NexthopInternetAsRouteNexthop(iaasalpha.NewNexthopInternet("internet"))), nil + return sdkUtils.Ptr(iaas.NexthopInternetAsRouteNexthop(iaas.NewNexthopInternet("internet"))), nil case "ipv4": - return sdkUtils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop(iaasalpha.NewNexthopIPv4("ipv4", nexthopModel.Value.ValueString()))), nil + return sdkUtils.Ptr(iaas.NexthopIPv4AsRouteNexthop(iaas.NewNexthopIPv4("ipv4", nexthopModel.Value.ValueString()))), nil case "ipv6": - return sdkUtils.Ptr(iaasalpha.NexthopIPv6AsRouteNexthop(iaasalpha.NewNexthopIPv6("ipv6", nexthopModel.Value.ValueString()))), nil + return sdkUtils.Ptr(iaas.NexthopIPv6AsRouteNexthop(iaas.NewNexthopIPv6("ipv6", nexthopModel.Value.ValueString()))), nil } return nil, fmt.Errorf("unknown nexthop type: %s", nexthopModel.Type.ValueString()) } -func toDestinationPayload(ctx context.Context, model *shared.RouteReadModel) (*iaasalpha.RouteDestination, error) { +func toDestinationPayload(ctx context.Context, model *shared.RouteReadModel) (*iaas.RouteDestination, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -562,9 +562,9 @@ func toDestinationPayload(ctx context.Context, model *shared.RouteReadModel) (*i switch destinationModel.Type.ValueString() { case "cidrv4": - return sdkUtils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination(iaasalpha.NewDestinationCIDRv4("cidrv4", destinationModel.Value.ValueString()))), nil + return sdkUtils.Ptr(iaas.DestinationCIDRv4AsRouteDestination(iaas.NewDestinationCIDRv4("cidrv4", destinationModel.Value.ValueString()))), nil case "cidrv6": - return sdkUtils.Ptr(iaasalpha.DestinationCIDRv6AsRouteDestination(iaasalpha.NewDestinationCIDRv6("cidrv6", destinationModel.Value.ValueString()))), nil + return sdkUtils.Ptr(iaas.DestinationCIDRv6AsRouteDestination(iaas.NewDestinationCIDRv6("cidrv6", destinationModel.Value.ValueString()))), nil } return nil, fmt.Errorf("unknown destination type: %s", destinationModel.Type.ValueString()) } diff --git a/stackit/internal/services/iaasalpha/routingtable/route/resource_test.go b/stackit/internal/services/iaas/routingtable/route/resource_test.go similarity index 82% rename from stackit/internal/services/iaasalpha/routingtable/route/resource_test.go rename to stackit/internal/services/iaas/routingtable/route/resource_test.go index 9d59f8555..fa0948198 100644 --- a/stackit/internal/services/iaasalpha/routingtable/route/resource_test.go +++ b/stackit/internal/services/iaas/routingtable/route/resource_test.go @@ -6,14 +6,14 @@ import ( "reflect" "testing" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" "github.com/google/go-cmp/cmp" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" ) const ( @@ -29,7 +29,7 @@ var ( func Test_mapFieldsFromList(t *testing.T) { type args struct { - routeResp *iaasalpha.RouteListResponse + routeResp *iaas.RouteListResponse model *shared.RouteModel region string } @@ -51,7 +51,7 @@ func Test_mapFieldsFromList(t *testing.T) { name: "response items is nil", args: args{ model: &shared.RouteModel{}, - routeResp: &iaasalpha.RouteListResponse{ + routeResp: &iaas.RouteListResponse{ Items: nil, }, }, @@ -61,7 +61,7 @@ func Test_mapFieldsFromList(t *testing.T) { name: "model is nil", args: args{ model: nil, - routeResp: &iaasalpha.RouteListResponse{ + routeResp: &iaas.RouteListResponse{ Items: nil, }, }, @@ -71,8 +71,8 @@ func Test_mapFieldsFromList(t *testing.T) { name: "response items is empty", args: args{ model: &shared.RouteModel{}, - routeResp: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{}, + routeResp: &iaas.RouteListResponse{ + Items: &[]iaas.Route{}, }, }, wantErr: true, @@ -81,8 +81,8 @@ func Test_mapFieldsFromList(t *testing.T) { name: "response items contains more than one route", args: args{ model: &shared.RouteModel{}, - routeResp: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{ + routeResp: &iaas.RouteListResponse{ + Items: &[]iaas.Route{ { Id: utils.Ptr(uuid.NewString()), }, @@ -105,15 +105,15 @@ func Test_mapFieldsFromList(t *testing.T) { OrganizationId: types.StringValue(organizationId.String()), NetworkAreaId: types.StringValue(networkAreaId.String()), }, - routeResp: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{ + routeResp: &iaas.RouteListResponse{ + Items: &[]iaas.Route{ { Id: utils.Ptr(routeId.String()), - Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + Destination: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), - Nexthop: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop( - iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"), + Nexthop: utils.Ptr(iaas.NexthopIPv4AsRouteNexthop( + iaas.NewNexthopIPv4("ipv4", "10.20.42.2"), )), Labels: &map[string]interface{}{ "foo": "bar", @@ -175,7 +175,7 @@ func Test_toUpdatePayload(t *testing.T) { tests := []struct { name string args args - want *iaasalpha.UpdateRouteOfRoutingTablePayload + want *iaas.UpdateRouteOfRoutingTablePayload wantErr bool }{ { @@ -201,7 +201,7 @@ func Test_toUpdatePayload(t *testing.T) { "foo3": types.StringValue("bar3"), }), }, - want: &iaasalpha.UpdateRouteOfRoutingTablePayload{ + want: &iaas.UpdateRouteOfRoutingTablePayload{ Labels: &map[string]interface{}{ "foo1": "bar1", "foo2": "bar2", @@ -233,7 +233,7 @@ func Test_toNextHopPayload(t *testing.T) { tests := []struct { name string args args - want *iaasalpha.RouteNexthop + want *iaas.RouteNexthop wantErr bool }{ { @@ -254,8 +254,8 @@ func Test_toNextHopPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop( - iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"), + want: utils.Ptr(iaas.NexthopIPv4AsRouteNexthop( + iaas.NewNexthopIPv4("ipv4", "10.20.42.2"), )), }, { @@ -269,8 +269,8 @@ func Test_toNextHopPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.NexthopIPv6AsRouteNexthop( - iaasalpha.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), + want: utils.Ptr(iaas.NexthopIPv6AsRouteNexthop( + iaas.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), )), }, { @@ -284,8 +284,8 @@ func Test_toNextHopPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.NexthopInternetAsRouteNexthop( - iaasalpha.NewNexthopInternet("internet"), + want: utils.Ptr(iaas.NexthopInternetAsRouteNexthop( + iaas.NewNexthopInternet("internet"), )), }, { @@ -299,8 +299,8 @@ func Test_toNextHopPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.NexthopBlackholeAsRouteNexthop( - iaasalpha.NewNexthopBlackhole("blackhole"), + want: utils.Ptr(iaas.NexthopBlackholeAsRouteNexthop( + iaas.NewNexthopBlackhole("blackhole"), )), }, } @@ -326,7 +326,7 @@ func Test_toDestinationPayload(t *testing.T) { tests := []struct { name string args args - want *iaasalpha.RouteDestination + want *iaas.RouteDestination wantErr bool }{ { @@ -347,8 +347,8 @@ func Test_toDestinationPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + want: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), }, { @@ -362,8 +362,8 @@ func Test_toDestinationPayload(t *testing.T) { }, }, wantErr: false, - want: utils.Ptr(iaasalpha.DestinationCIDRv6AsRouteDestination( - iaasalpha.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), + want: utils.Ptr(iaas.DestinationCIDRv6AsRouteDestination( + iaas.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), )), }, } @@ -389,7 +389,7 @@ func Test_toCreatePayload(t *testing.T) { tests := []struct { name string args args - want *iaasalpha.AddRoutesToRoutingTablePayload + want *iaas.AddRoutesToRoutingTablePayload wantErr bool }{ { @@ -417,18 +417,18 @@ func Test_toCreatePayload(t *testing.T) { }), }, }, - want: &iaasalpha.AddRoutesToRoutingTablePayload{ - Items: &[]iaasalpha.Route{ + want: &iaas.AddRoutesToRoutingTablePayload{ + Items: &[]iaas.Route{ { Labels: &map[string]interface{}{ "foo1": "bar1", "foo2": "bar2", }, - Nexthop: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop( - iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"), + Nexthop: utils.Ptr(iaas.NexthopIPv4AsRouteNexthop( + iaas.NewNexthopIPv4("ipv4", "10.20.42.2"), )), - Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + Destination: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), }, }, diff --git a/stackit/internal/services/iaasalpha/routingtable/routes/datasource.go b/stackit/internal/services/iaas/routingtable/routes/datasource.go similarity index 93% rename from stackit/internal/services/iaasalpha/routingtable/routes/datasource.go rename to stackit/internal/services/iaas/routingtable/routes/datasource.go index dd3e34f08..f22eaefd4 100644 --- a/stackit/internal/services/iaasalpha/routingtable/routes/datasource.go +++ b/stackit/internal/services/iaas/routingtable/routes/datasource.go @@ -11,12 +11,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - shared "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" + shared "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" + iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) @@ -41,7 +41,7 @@ func NewRoutingTableRoutesDataSource() datasource.DataSource { // routingTableDataSource is the data source implementation. type routingTableRoutesDataSource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -62,7 +62,7 @@ func (d *routingTableRoutesDataSource) Configure(ctx context.Context, req dataso return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } @@ -131,7 +131,7 @@ func (d *routingTableRoutesDataSource) Read(ctx context.Context, req datasource. tflog.Info(ctx, "Routing table routes read") } -func mapDataSourceRoutingTableRoutes(ctx context.Context, routes *iaasalpha.RouteListResponse, model *RoutingTableRoutesDataSourceModel, region string) error { +func mapDataSourceRoutingTableRoutes(ctx context.Context, routes *iaas.RouteListResponse, model *RoutingTableRoutesDataSourceModel, region string) error { if routes == nil { return fmt.Errorf("response input is nil") } diff --git a/stackit/internal/services/iaasalpha/routingtable/routes/datasource_test.go b/stackit/internal/services/iaas/routingtable/routes/datasource_test.go similarity index 84% rename from stackit/internal/services/iaasalpha/routingtable/routes/datasource_test.go rename to stackit/internal/services/iaas/routingtable/routes/datasource_test.go index 171abd65d..df752972a 100644 --- a/stackit/internal/services/iaasalpha/routingtable/routes/datasource_test.go +++ b/stackit/internal/services/iaas/routingtable/routes/datasource_test.go @@ -5,14 +5,14 @@ import ( "fmt" "testing" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" "github.com/google/go-cmp/cmp" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" ) const ( @@ -29,7 +29,7 @@ var ( func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { type args struct { - routes *iaasalpha.RouteListResponse + routes *iaas.RouteListResponse model *RoutingTableRoutesDataSourceModel region string } @@ -43,8 +43,8 @@ func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { name: "model is nil", args: args{ model: nil, - routes: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{}, + routes: &iaas.RouteListResponse{ + Items: &[]iaas.Route{}, }, }, wantErr: true, @@ -61,7 +61,7 @@ func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { name: "response items is nil", args: args{ model: nil, - routes: &iaasalpha.RouteListResponse{ + routes: &iaas.RouteListResponse{ Items: nil, }, }, @@ -76,8 +76,8 @@ func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { RoutingTableId: types.StringValue(testRoutingTableId), Region: types.StringValue(testRegion), }, - routes: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{}, + routes: &iaas.RouteListResponse{ + Items: &[]iaas.Route{}, }, region: testRegion, }, @@ -102,15 +102,15 @@ func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { RoutingTableId: types.StringValue(testRoutingTableId), Region: types.StringValue(testRegion), }, - routes: &iaasalpha.RouteListResponse{ - Items: &[]iaasalpha.Route{ + routes: &iaas.RouteListResponse{ + Items: &[]iaas.Route{ { Id: utils.Ptr(testRouteId1), - Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + Destination: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), - Nexthop: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop( - iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"), + Nexthop: utils.Ptr(iaas.NexthopIPv4AsRouteNexthop( + iaas.NewNexthopIPv4("ipv4", "10.20.42.2"), )), Labels: &map[string]interface{}{ "foo": "bar", @@ -120,11 +120,11 @@ func Test_mapDataSourceRoutingTableRoutes(t *testing.T) { }, { Id: utils.Ptr(testRouteId2), - Destination: utils.Ptr(iaasalpha.DestinationCIDRv6AsRouteDestination( - iaasalpha.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), + Destination: utils.Ptr(iaas.DestinationCIDRv6AsRouteDestination( + iaas.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), )), - Nexthop: utils.Ptr(iaasalpha.NexthopIPv6AsRouteNexthop( - iaasalpha.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), + Nexthop: utils.Ptr(iaas.NexthopIPv6AsRouteNexthop( + iaas.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), )), Labels: &map[string]interface{}{ "key": "value", diff --git a/stackit/internal/services/iaasalpha/routingtable/shared/route.go b/stackit/internal/services/iaas/routingtable/shared/route.go similarity index 90% rename from stackit/internal/services/iaasalpha/routingtable/shared/route.go rename to stackit/internal/services/iaas/routingtable/shared/route.go index e05cf78de..06d283af8 100644 --- a/stackit/internal/services/iaasalpha/routingtable/shared/route.go +++ b/stackit/internal/services/iaas/routingtable/shared/route.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" ) @@ -76,7 +76,7 @@ var RouteNextHopTypes = map[string]attr.Type{ "value": types.StringType, } -func MapRouteModel(ctx context.Context, route *iaasalpha.Route, model *RouteModel, region string) error { +func MapRouteModel(ctx context.Context, route *iaas.Route, model *RouteModel, region string) error { if route == nil { return fmt.Errorf("response input is nil") } @@ -104,7 +104,7 @@ func MapRouteModel(ctx context.Context, route *iaasalpha.Route, model *RouteMode return nil } -func MapRouteReadModel(ctx context.Context, route *iaasalpha.Route, model *RouteReadModel) error { +func MapRouteReadModel(ctx context.Context, route *iaas.Route, model *RouteReadModel) error { if route == nil { return fmt.Errorf("response input is nil") } @@ -156,23 +156,23 @@ func MapRouteReadModel(ctx context.Context, route *iaasalpha.Route, model *Route return nil } -func MapRouteNextHop(routeResp *iaasalpha.Route) (types.Object, error) { +func MapRouteNextHop(routeResp *iaas.Route) (types.Object, error) { if routeResp.Nexthop == nil { return types.ObjectNull(RouteNextHopTypes), nil } nextHopMap := map[string]attr.Value{} switch i := routeResp.Nexthop.GetActualInstance().(type) { - case *iaasalpha.NexthopIPv4: + case *iaas.NexthopIPv4: nextHopMap["type"] = types.StringValue(*i.Type) nextHopMap["value"] = types.StringPointerValue(i.Value) - case *iaasalpha.NexthopIPv6: + case *iaas.NexthopIPv6: nextHopMap["type"] = types.StringValue(*i.Type) nextHopMap["value"] = types.StringPointerValue(i.Value) - case *iaasalpha.NexthopBlackhole: + case *iaas.NexthopBlackhole: nextHopMap["type"] = types.StringValue(*i.Type) nextHopMap["value"] = types.StringNull() - case *iaasalpha.NexthopInternet: + case *iaas.NexthopInternet: nextHopMap["type"] = types.StringValue(*i.Type) nextHopMap["value"] = types.StringNull() default: @@ -187,17 +187,17 @@ func MapRouteNextHop(routeResp *iaasalpha.Route) (types.Object, error) { return nextHopTF, nil } -func MapRouteDestination(routeResp *iaasalpha.Route) (types.Object, error) { +func MapRouteDestination(routeResp *iaas.Route) (types.Object, error) { if routeResp.Destination == nil { return types.ObjectNull(RouteDestinationTypes), nil } destinationMap := map[string]attr.Value{} switch i := routeResp.Destination.GetActualInstance().(type) { - case *iaasalpha.DestinationCIDRv4: + case *iaas.DestinationCIDRv4: destinationMap["type"] = types.StringValue(*i.Type) destinationMap["value"] = types.StringPointerValue(i.Value) - case *iaasalpha.DestinationCIDRv6: + case *iaas.DestinationCIDRv6: destinationMap["type"] = types.StringValue(*i.Type) destinationMap["value"] = types.StringPointerValue(i.Value) default: diff --git a/stackit/internal/services/iaasalpha/routingtable/shared/route_test.go b/stackit/internal/services/iaas/routingtable/shared/route_test.go similarity index 79% rename from stackit/internal/services/iaasalpha/routingtable/shared/route_test.go rename to stackit/internal/services/iaas/routingtable/shared/route_test.go index 6997ad228..aafbe1c52 100644 --- a/stackit/internal/services/iaasalpha/routingtable/shared/route_test.go +++ b/stackit/internal/services/iaas/routingtable/shared/route_test.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) const ( @@ -27,7 +27,7 @@ var ( func Test_MapRouteNextHop(t *testing.T) { type args struct { - routeResp *iaasalpha.Route + routeResp *iaas.Route } tests := []struct { name string @@ -38,7 +38,7 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop is nil", args: args{ - routeResp: &iaasalpha.Route{ + routeResp: &iaas.Route{ Nexthop: nil, }, }, @@ -48,8 +48,8 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop is empty", args: args{ - routeResp: &iaasalpha.Route{ - Nexthop: &iaasalpha.RouteNexthop{}, + routeResp: &iaas.Route{ + Nexthop: &iaas.RouteNexthop{}, }, }, wantErr: true, @@ -57,9 +57,9 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop ipv4", args: args{ - routeResp: &iaasalpha.Route{ - Nexthop: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop( - iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"), + routeResp: &iaas.Route{ + Nexthop: utils.Ptr(iaas.NexthopIPv4AsRouteNexthop( + iaas.NewNexthopIPv4("ipv4", "10.20.42.2"), )), }, }, @@ -72,9 +72,9 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop ipv6", args: args{ - routeResp: &iaasalpha.Route{ - Nexthop: utils.Ptr(iaasalpha.NexthopIPv6AsRouteNexthop( - iaasalpha.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), + routeResp: &iaas.Route{ + Nexthop: utils.Ptr(iaas.NexthopIPv6AsRouteNexthop( + iaas.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"), )), }, }, @@ -87,9 +87,9 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop internet", args: args{ - routeResp: &iaasalpha.Route{ - Nexthop: utils.Ptr(iaasalpha.NexthopInternetAsRouteNexthop( - iaasalpha.NewNexthopInternet("internet"), + routeResp: &iaas.Route{ + Nexthop: utils.Ptr(iaas.NexthopInternetAsRouteNexthop( + iaas.NewNexthopInternet("internet"), )), }, }, @@ -102,9 +102,9 @@ func Test_MapRouteNextHop(t *testing.T) { { name: "nexthop blackhole", args: args{ - routeResp: &iaasalpha.Route{ - Nexthop: utils.Ptr(iaasalpha.NexthopBlackholeAsRouteNexthop( - iaasalpha.NewNexthopBlackhole("blackhole"), + routeResp: &iaas.Route{ + Nexthop: utils.Ptr(iaas.NexthopBlackholeAsRouteNexthop( + iaas.NewNexthopBlackhole("blackhole"), )), }, }, @@ -132,7 +132,7 @@ func Test_MapRouteNextHop(t *testing.T) { func Test_MapRouteDestination(t *testing.T) { type args struct { - routeResp *iaasalpha.Route + routeResp *iaas.Route } tests := []struct { name string @@ -144,7 +144,7 @@ func Test_MapRouteDestination(t *testing.T) { { name: "destination is nil", args: args{ - routeResp: &iaasalpha.Route{ + routeResp: &iaas.Route{ Destination: nil, }, }, @@ -154,8 +154,8 @@ func Test_MapRouteDestination(t *testing.T) { { name: "destination is empty", args: args{ - routeResp: &iaasalpha.Route{ - Destination: &iaasalpha.RouteDestination{}, + routeResp: &iaas.Route{ + Destination: &iaas.RouteDestination{}, }, }, wantErr: true, @@ -163,9 +163,9 @@ func Test_MapRouteDestination(t *testing.T) { { name: "destination cidrv4", args: args{ - routeResp: &iaasalpha.Route{ - Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + routeResp: &iaas.Route{ + Destination: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), }, }, @@ -178,9 +178,9 @@ func Test_MapRouteDestination(t *testing.T) { { name: "destination cidrv6", args: args{ - routeResp: &iaasalpha.Route{ - Destination: utils.Ptr(iaasalpha.DestinationCIDRv6AsRouteDestination( - iaasalpha.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), + routeResp: &iaas.Route{ + Destination: utils.Ptr(iaas.DestinationCIDRv6AsRouteDestination( + iaas.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"), )), }, }, @@ -211,7 +211,7 @@ func TestMapRouteModel(t *testing.T) { updatedAt := time.Now().Add(5 * time.Minute) type args struct { - route *iaasalpha.Route + route *iaas.Route model *RouteModel region string } @@ -234,7 +234,7 @@ func TestMapRouteModel(t *testing.T) { name: "model is nil", args: args{ model: nil, - route: &iaasalpha.Route{}, + route: &iaas.Route{}, region: testRegion, }, wantErr: true, @@ -248,17 +248,17 @@ func TestMapRouteModel(t *testing.T) { NetworkAreaId: types.StringValue(testNetworkAreaId.String()), RoutingTableId: types.StringValue(testRoutingTableId.String()), }, - route: &iaasalpha.Route{ + route: &iaas.Route{ Id: utils.Ptr(testRouteId.String()), - Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination( - iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), + Destination: utils.Ptr(iaas.DestinationCIDRv4AsRouteDestination( + iaas.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"), )), Labels: &map[string]interface{}{ "foo1": "bar1", "foo2": "bar2", }, Nexthop: utils.Ptr( - iaasalpha.NexthopIPv4AsRouteNexthop(iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2")), + iaas.NexthopIPv4AsRouteNexthop(iaas.NewNexthopIPv4("ipv4", "10.20.42.2")), ), CreatedAt: &createdAt, UpdatedAt: &updatedAt, diff --git a/stackit/internal/services/iaasalpha/routingtable/shared/shared.go b/stackit/internal/services/iaas/routingtable/shared/shared.go similarity index 98% rename from stackit/internal/services/iaasalpha/routingtable/shared/shared.go rename to stackit/internal/services/iaas/routingtable/shared/shared.go index dc3886ade..51925f735 100644 --- a/stackit/internal/services/iaasalpha/routingtable/shared/shared.go +++ b/stackit/internal/services/iaas/routingtable/shared/shared.go @@ -6,13 +6,13 @@ import ( "maps" "time" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" ) @@ -225,7 +225,7 @@ func RoutingTableResponseAttributes() map[string]schema.Attribute { } } -func MapRoutingTableReadModel(ctx context.Context, routingTable *iaasalpha.RoutingTable, model *RoutingTableReadModel) error { +func MapRoutingTableReadModel(ctx context.Context, routingTable *iaas.RoutingTable, model *RoutingTableReadModel) error { if routingTable == nil { return fmt.Errorf("response input is nil") } diff --git a/stackit/internal/services/iaasalpha/routingtable/table/datasource.go b/stackit/internal/services/iaas/routingtable/table/datasource.go similarity index 92% rename from stackit/internal/services/iaasalpha/routingtable/table/datasource.go rename to stackit/internal/services/iaas/routingtable/table/datasource.go index fbfb7950b..8bdc00fbf 100644 --- a/stackit/internal/services/iaasalpha/routingtable/table/datasource.go +++ b/stackit/internal/services/iaas/routingtable/table/datasource.go @@ -7,17 +7,17 @@ import ( "strings" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" ) @@ -33,7 +33,7 @@ func NewRoutingTableDataSource() datasource.DataSource { // routingTableDataSource is the data source implementation. type routingTableDataSource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -54,7 +54,7 @@ func (d *routingTableDataSource) Configure(ctx context.Context, req datasource.C return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } @@ -123,7 +123,7 @@ func (d *routingTableDataSource) Read(ctx context.Context, req datasource.ReadRe tflog.Info(ctx, "Routing table read") } -func mapDatasourceFields(ctx context.Context, routingTable *iaasalpha.RoutingTable, model *shared.RoutingTableDataSourceModel, region string) error { +func mapDatasourceFields(ctx context.Context, routingTable *iaas.RoutingTable, model *shared.RoutingTableDataSourceModel, region string) error { if routingTable == nil { return fmt.Errorf("response input is nil") } diff --git a/stackit/internal/services/iaasalpha/routingtable/table/datasource_test.go b/stackit/internal/services/iaas/routingtable/table/datasource_test.go similarity index 93% rename from stackit/internal/services/iaasalpha/routingtable/table/datasource_test.go rename to stackit/internal/services/iaas/routingtable/table/datasource_test.go index 4622e1b3e..3979e6f12 100644 --- a/stackit/internal/services/iaasalpha/routingtable/table/datasource_test.go +++ b/stackit/internal/services/iaas/routingtable/table/datasource_test.go @@ -5,14 +5,14 @@ import ( "fmt" "testing" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" "github.com/google/go-cmp/cmp" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" ) const ( @@ -31,7 +31,7 @@ func Test_mapDatasourceFields(t *testing.T) { tests := []struct { description string state shared.RoutingTableDataSourceModel - input *iaasalpha.RoutingTable + input *iaas.RoutingTable expected shared.RoutingTableDataSourceModel isValid bool }{ @@ -41,7 +41,7 @@ func Test_mapDatasourceFields(t *testing.T) { OrganizationId: types.StringValue(organizationId.String()), NetworkAreaId: types.StringValue(networkAreaId.String()), }, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: utils.Ptr(routingTableId.String()), Name: utils.Ptr("default_values"), }, @@ -65,7 +65,7 @@ func Test_mapDatasourceFields(t *testing.T) { NetworkAreaId: types.StringValue(networkAreaId.String()), RoutingTableReadModel: shared.RoutingTableReadModel{}, }, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: utils.Ptr(routingTableId.String()), Name: utils.Ptr("values_ok"), Description: utils.Ptr("Description"), @@ -92,7 +92,7 @@ func Test_mapDatasourceFields(t *testing.T) { { "response_fields_nil_fail", shared.RoutingTableDataSourceModel{}, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: nil, }, shared.RoutingTableDataSourceModel{}, @@ -111,7 +111,7 @@ func Test_mapDatasourceFields(t *testing.T) { OrganizationId: types.StringValue("oid"), NetworkAreaId: types.StringValue("naid"), }, - &iaasalpha.RoutingTable{}, + &iaas.RoutingTable{}, shared.RoutingTableDataSourceModel{}, false, }, diff --git a/stackit/internal/services/iaasalpha/routingtable/table/resource.go b/stackit/internal/services/iaas/routingtable/table/resource.go similarity index 96% rename from stackit/internal/services/iaasalpha/routingtable/table/resource.go rename to stackit/internal/services/iaas/routingtable/table/resource.go index b0b980a61..d0e1328e9 100644 --- a/stackit/internal/services/iaasalpha/routingtable/table/resource.go +++ b/stackit/internal/services/iaas/routingtable/table/resource.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" @@ -21,11 +22,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" ) @@ -60,7 +59,7 @@ func NewRoutingTableResource() resource.Resource { // routingTableResource is the resource implementation. type routingTableResource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -82,7 +81,7 @@ func (r *routingTableResource) Configure(ctx context.Context, req resource.Confi return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &r.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } @@ -451,7 +450,7 @@ func (r *routingTableResource) ImportState(ctx context.Context, req resource.Imp tflog.Info(ctx, "Routing table state imported") } -func mapFields(ctx context.Context, routingTable *iaasalpha.RoutingTable, model *Model, region string) error { +func mapFields(ctx context.Context, routingTable *iaas.RoutingTable, model *Model, region string) error { if routingTable == nil { return fmt.Errorf("response input is nil") } @@ -498,7 +497,7 @@ func mapFields(ctx context.Context, routingTable *iaasalpha.RoutingTable, model return nil } -func toCreatePayload(ctx context.Context, model *Model) (*iaasalpha.AddRoutingTableToAreaPayload, error) { +func toCreatePayload(ctx context.Context, model *Model) (*iaas.AddRoutingTableToAreaPayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -508,7 +507,7 @@ func toCreatePayload(ctx context.Context, model *Model) (*iaasalpha.AddRoutingTa return nil, fmt.Errorf("converting to Go map: %w", err) } - return &iaasalpha.AddRoutingTableToAreaPayload{ + return &iaas.AddRoutingTableToAreaPayload{ Description: conversion.StringValueToPointer(model.Description), Name: conversion.StringValueToPointer(model.Name), Labels: &labels, @@ -517,7 +516,7 @@ func toCreatePayload(ctx context.Context, model *Model) (*iaasalpha.AddRoutingTa }, nil } -func toUpdatePayload(ctx context.Context, model *Model, currentLabels types.Map) (*iaasalpha.UpdateRoutingTableOfAreaPayload, error) { +func toUpdatePayload(ctx context.Context, model *Model, currentLabels types.Map) (*iaas.UpdateRoutingTableOfAreaPayload, error) { if model == nil { return nil, fmt.Errorf("nil model") } @@ -527,7 +526,7 @@ func toUpdatePayload(ctx context.Context, model *Model, currentLabels types.Map) return nil, fmt.Errorf("converting to Go map: %w", err) } - return &iaasalpha.UpdateRoutingTableOfAreaPayload{ + return &iaas.UpdateRoutingTableOfAreaPayload{ Description: conversion.StringValueToPointer(model.Description), Name: conversion.StringValueToPointer(model.Name), Labels: &labels, diff --git a/stackit/internal/services/iaasalpha/routingtable/table/resource_test.go b/stackit/internal/services/iaas/routingtable/table/resource_test.go similarity index 91% rename from stackit/internal/services/iaasalpha/routingtable/table/resource_test.go rename to stackit/internal/services/iaas/routingtable/table/resource_test.go index 52db3c99b..09997410e 100644 --- a/stackit/internal/services/iaasalpha/routingtable/table/resource_test.go +++ b/stackit/internal/services/iaas/routingtable/table/resource_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" ) func TestMapFields(t *testing.T) { @@ -18,7 +18,7 @@ func TestMapFields(t *testing.T) { tests := []struct { description string state Model - input *iaasalpha.RoutingTable + input *iaas.RoutingTable expected Model isValid bool }{ @@ -28,7 +28,7 @@ func TestMapFields(t *testing.T) { OrganizationId: types.StringValue("oid"), NetworkAreaId: types.StringValue("aid"), }, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: utils.Ptr("rtid"), Name: utils.Ptr("default_values"), }, @@ -49,7 +49,7 @@ func TestMapFields(t *testing.T) { OrganizationId: types.StringValue("oid"), NetworkAreaId: types.StringValue("aid"), }, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: utils.Ptr("rtid"), Name: utils.Ptr("values_ok"), Description: utils.Ptr("Description"), @@ -74,7 +74,7 @@ func TestMapFields(t *testing.T) { { "response_fields_nil_fail", Model{}, - &iaasalpha.RoutingTable{ + &iaas.RoutingTable{ Id: nil, }, Model{}, @@ -93,7 +93,7 @@ func TestMapFields(t *testing.T) { OrganizationId: types.StringValue("oid"), NetworkAreaId: types.StringValue("naid"), }, - &iaasalpha.RoutingTable{}, + &iaas.RoutingTable{}, Model{}, false, }, @@ -121,7 +121,7 @@ func TestToCreatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *iaasalpha.AddRoutingTableToAreaPayload + expected *iaas.AddRoutingTableToAreaPayload isValid bool }{ { @@ -135,7 +135,7 @@ func TestToCreatePayload(t *testing.T) { SystemRoutes: types.BoolValue(true), DynamicRoutes: types.BoolValue(true), }, - expected: &iaasalpha.AddRoutingTableToAreaPayload{ + expected: &iaas.AddRoutingTableToAreaPayload{ Description: utils.Ptr("Description"), Name: utils.Ptr("default_ok"), Labels: &map[string]interface{}{ @@ -170,7 +170,7 @@ func TestToUpdatePayload(t *testing.T) { tests := []struct { description string input *Model - expected *iaasalpha.UpdateRoutingTableOfAreaPayload + expected *iaas.UpdateRoutingTableOfAreaPayload isValid bool }{ { @@ -184,7 +184,7 @@ func TestToUpdatePayload(t *testing.T) { }), DynamicRoutes: types.BoolValue(false), }, - &iaasalpha.UpdateRoutingTableOfAreaPayload{ + &iaas.UpdateRoutingTableOfAreaPayload{ Description: utils.Ptr("Description"), Name: utils.Ptr("default_ok"), Labels: &map[string]interface{}{ @@ -206,7 +206,7 @@ func TestToUpdatePayload(t *testing.T) { t.Fatalf("Should not have failed: %v", err) } if tt.isValid { - diff := cmp.Diff(output, tt.expected, cmp.AllowUnexported(iaasalpha.NullableString{})) + diff := cmp.Diff(output, tt.expected, cmp.AllowUnexported(iaas.NullableString{})) if diff != "" { t.Fatalf("Data does not match: %s", diff) } diff --git a/stackit/internal/services/iaasalpha/routingtable/tables/datasource.go b/stackit/internal/services/iaas/routingtable/tables/datasource.go similarity index 94% rename from stackit/internal/services/iaasalpha/routingtable/tables/datasource.go rename to stackit/internal/services/iaas/routingtable/tables/datasource.go index 7ea6cbf25..85d9db034 100644 --- a/stackit/internal/services/iaasalpha/routingtable/tables/datasource.go +++ b/stackit/internal/services/iaas/routingtable/tables/datasource.go @@ -5,7 +5,9 @@ import ( "fmt" "net/http" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" + iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -13,11 +15,9 @@ import ( "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features" - iaasalphaUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate" ) @@ -42,7 +42,7 @@ func NewRoutingTablesDataSource() datasource.DataSource { // routingTableDataSource is the data source implementation. type routingTablesDataSource struct { - client *iaasalpha.APIClient + client *iaas.APIClient providerData core.ProviderData } @@ -63,7 +63,7 @@ func (d *routingTablesDataSource) Configure(ctx context.Context, req datasource. return } - apiClient := iaasalphaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) + apiClient := iaasUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics) if resp.Diagnostics.HasError() { return } @@ -163,7 +163,7 @@ func (d *routingTablesDataSource) Read(ctx context.Context, req datasource.ReadR tflog.Info(ctx, "Routing table read") } -func mapDataSourceRoutingTables(ctx context.Context, routingTables *iaasalpha.RoutingTableListResponse, model *DataSourceModelTables, region string) error { +func mapDataSourceRoutingTables(ctx context.Context, routingTables *iaas.RoutingTableListResponse, model *DataSourceModelTables, region string) error { if routingTables == nil { return fmt.Errorf("response input is nil") } diff --git a/stackit/internal/services/iaasalpha/routingtable/tables/datasource_test.go b/stackit/internal/services/iaas/routingtable/tables/datasource_test.go similarity index 94% rename from stackit/internal/services/iaasalpha/routingtable/tables/datasource_test.go rename to stackit/internal/services/iaas/routingtable/tables/datasource_test.go index 9b6708e25..f89e2628d 100644 --- a/stackit/internal/services/iaasalpha/routingtable/tables/datasource_test.go +++ b/stackit/internal/services/iaas/routingtable/tables/datasource_test.go @@ -6,14 +6,14 @@ import ( "testing" "time" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/shared" + "github.com/stackitcloud/stackit-sdk-go/services/iaas" + "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/shared" "github.com/google/go-cmp/cmp" "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/stackitcloud/stackit-sdk-go/core/utils" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" ) const ( @@ -35,7 +35,7 @@ func TestMapDataFields(t *testing.T) { tests := []struct { description string state DataSourceModelTables - input *iaasalpha.RoutingTableListResponse + input *iaas.RoutingTableListResponse expected DataSourceModelTables isValid bool }{ @@ -46,8 +46,8 @@ func TestMapDataFields(t *testing.T) { NetworkAreaId: types.StringValue(networkAreaId.String()), Region: types.StringValue(testRegion), }, - &iaasalpha.RoutingTableListResponse{ - Items: &[]iaasalpha.RoutingTable{ + &iaas.RoutingTableListResponse{ + Items: &[]iaas.RoutingTable{ { Id: utils.Ptr(routingTableId.String()), Name: utils.Ptr("test"), @@ -88,8 +88,8 @@ func TestMapDataFields(t *testing.T) { NetworkAreaId: types.StringValue(networkAreaId.String()), Region: types.StringValue(testRegion), }, - &iaasalpha.RoutingTableListResponse{ - Items: &[]iaasalpha.RoutingTable{ + &iaas.RoutingTableListResponse{ + Items: &[]iaas.RoutingTable{ { Id: utils.Ptr(routingTableId.String()), Name: utils.Ptr("test"), @@ -147,7 +147,7 @@ func TestMapDataFields(t *testing.T) { { "response_fields_items_nil_fail", DataSourceModelTables{}, - &iaasalpha.RoutingTableListResponse{ + &iaas.RoutingTableListResponse{ Items: nil, }, DataSourceModelTables{}, diff --git a/stackit/internal/services/iaas/testdata/resource-routingtable-max.tf b/stackit/internal/services/iaas/testdata/resource-routingtable-max.tf new file mode 100644 index 000000000..76a8e3492 --- /dev/null +++ b/stackit/internal/services/iaas/testdata/resource-routingtable-max.tf @@ -0,0 +1,46 @@ +variable "organization_id" {} +variable "name" {} +variable "description" {} +variable "region" {} +variable "label" {} +variable "system_routes" {} +variable "dynamic_routes" {} + +resource "stackit_network_area" "network_area" { + organization_id = var.organization_id + name = var.name + labels = { + "preview/routingtables" = "true" + } +} + +resource "stackit_network_area_region" "network_area_region" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + ipv4 = { + network_ranges = [ + { + prefix = "10.0.0.0/16" + }, + { + prefix = "10.2.2.0/24" + } + ] + transfer_network = "10.1.2.0/24" + } +} + +resource "stackit_routing_table" "routing_table" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + name = var.name + description = var.description + region = var.region + labels = { + "acc-test" : var.label + } + system_routes = var.system_routes + dynamic_routes = var.dynamic_routes + + depends_on = [stackit_network_area_region.network_area_region] +} diff --git a/stackit/internal/services/iaas/testdata/resource-routingtable-min.tf b/stackit/internal/services/iaas/testdata/resource-routingtable-min.tf new file mode 100644 index 000000000..b9938e956 --- /dev/null +++ b/stackit/internal/services/iaas/testdata/resource-routingtable-min.tf @@ -0,0 +1,34 @@ +variable "organization_id" {} +variable "name" {} + +resource "stackit_network_area" "network_area" { + organization_id = var.organization_id + name = var.name + labels = { + "preview/routingtables" = "true" + } +} + +resource "stackit_network_area_region" "network_area_region" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + ipv4 = { + network_ranges = [ + { + prefix = "10.0.0.0/16" + }, + { + prefix = "10.2.2.0/24" + } + ] + transfer_network = "10.1.2.0/24" + } +} + +resource "stackit_routing_table" "routing_table" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + name = var.name + + depends_on = [stackit_network_area_region.network_area_region] +} diff --git a/stackit/internal/services/iaas/testdata/resource-routingtable-route-max.tf b/stackit/internal/services/iaas/testdata/resource-routingtable-route-max.tf new file mode 100644 index 000000000..31598c07a --- /dev/null +++ b/stackit/internal/services/iaas/testdata/resource-routingtable-route-max.tf @@ -0,0 +1,57 @@ +variable "organization_id" {} +variable "name" {} +variable "routing_table_name" {} +variable "destination_type" {} +variable "destination_value" {} +variable "next_hop_type" {} +variable "next_hop_value" {} +variable "label" {} + +resource "stackit_network_area" "network_area" { + organization_id = var.organization_id + name = var.name + labels = { + "preview/routingtables" = "true" + } +} + +resource "stackit_network_area_region" "network_area_region" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + ipv4 = { + network_ranges = [ + { + prefix = "10.0.0.0/16" + }, + { + prefix = "10.2.2.0/24" + } + ] + transfer_network = "10.1.2.0/24" + } +} + +resource "stackit_routing_table" "routing_table" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + name = var.routing_table_name + + depends_on = [stackit_network_area_region.network_area_region] +} + +resource "stackit_routing_table_route" "route" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + routing_table_id = stackit_routing_table.routing_table.routing_table_id + destination = { + type = var.destination_type + value = var.destination_value + } + next_hop = { + type = var.next_hop_type + value = var.next_hop_value + } + labels = { + "acc-test" = var.label + } +} diff --git a/stackit/internal/services/iaas/testdata/resource-routingtable-route-min.tf b/stackit/internal/services/iaas/testdata/resource-routingtable-route-min.tf new file mode 100644 index 000000000..a36dc452a --- /dev/null +++ b/stackit/internal/services/iaas/testdata/resource-routingtable-route-min.tf @@ -0,0 +1,53 @@ +variable "organization_id" {} +variable "name" {} +variable "routing_table_name" {} +variable "destination_type" {} +variable "destination_value" {} +variable "next_hop_type" {} +variable "next_hop_value" {} + +resource "stackit_network_area" "network_area" { + organization_id = var.organization_id + name = var.name + labels = { + "preview/routingtables" = "true" + } +} + +resource "stackit_network_area_region" "network_area_region" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + ipv4 = { + network_ranges = [ + { + prefix = "10.0.0.0/16" + }, + { + prefix = "10.2.2.0/24" + } + ] + transfer_network = "10.1.2.0/24" + } +} + +resource "stackit_routing_table" "routing_table" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + name = var.routing_table_name + + depends_on = [stackit_network_area_region.network_area_region] +} + +resource "stackit_routing_table_route" "route" { + organization_id = var.organization_id + network_area_id = stackit_network_area.network_area.network_area_id + routing_table_id = stackit_routing_table.routing_table.routing_table_id + destination = { + type = var.destination_type + value = var.destination_value + } + next_hop = { + type = var.next_hop_type + value = var.next_hop_value + } +} diff --git a/stackit/internal/services/iaasalpha/iaasalpha_acc_test.go b/stackit/internal/services/iaasalpha/iaasalpha_acc_test.go deleted file mode 100644 index a8c21ff4b..000000000 --- a/stackit/internal/services/iaasalpha/iaasalpha_acc_test.go +++ /dev/null @@ -1,841 +0,0 @@ -package iaasalpha_test - -import ( - "context" - _ "embed" - "errors" - "fmt" - "maps" - "net/http" - "strings" - "sync" - "testing" - - "github.com/hashicorp/terraform-plugin-testing/config" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-plugin-testing/terraform" - stackitSdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/core/oapierror" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" - - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil" -) - -// TODO: create network area using terraform resource instead once it's out of experimental stage and GA -const ( - testNetworkAreaId = "25bbf23a-8134-4439-9f5e-1641caf8354e" -) - -var ( - //go:embed testdata/resource-routingtable-min.tf - resourceRoutingTableMinConfig string - - //go:embed testdata/resource-routingtable-max.tf - resourceRoutingTableMaxConfig string - - //go:embed testdata/resource-routingtable-route-min.tf - resourceRoutingTableRouteMinConfig string - - //go:embed testdata/resource-routingtable-route-max.tf - resourceRoutingTableRouteMaxConfig string -) - -var testConfigRoutingTableMin = config.Variables{ - "organization_id": config.StringVariable(testutil.OrganizationId), - "network_area_id": config.StringVariable(testNetworkAreaId), - "name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), -} - -var testConfigRoutingTableMinUpdated = func() config.Variables { - updatedConfig := config.Variables{} - maps.Copy(updatedConfig, testConfigRoutingTableMin) - updatedConfig["name"] = config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))) - return updatedConfig -}() - -var testConfigRoutingTableMax = config.Variables{ - "organization_id": config.StringVariable(testutil.OrganizationId), - "network_area_id": config.StringVariable(testNetworkAreaId), - "name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), - "description": config.StringVariable("This is the description of the routing table."), - "label": config.StringVariable("routing-table-label-01"), - "system_routes": config.BoolVariable(false), - "dynamic_routes": config.BoolVariable(false), - "region": config.StringVariable(testutil.Region), -} - -var testConfigRoutingTableMaxUpdated = func() config.Variables { - updatedConfig := config.Variables{} - for k, v := range testConfigRoutingTableMax { - updatedConfig[k] = v - } - updatedConfig["name"] = config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))) - updatedConfig["description"] = config.StringVariable("This is the updated description of the routing table.") - updatedConfig["label"] = config.StringVariable("routing-table-updated-label-01") - updatedConfig["dynamic_routes"] = config.BoolVariable(true) - return updatedConfig -}() - -var testConfigRoutingTableRouteMin = config.Variables{ - "organization_id": config.StringVariable(testutil.OrganizationId), - "network_area_id": config.StringVariable(testNetworkAreaId), - "routing_table_name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), - "destination_type": config.StringVariable("cidrv4"), - "destination_value": config.StringVariable("192.168.178.0/24"), - "next_hop_type": config.StringVariable("ipv4"), - "next_hop_value": config.StringVariable("192.168.178.1"), -} - -var testConfigRoutingTableRouteMinUpdated = func() config.Variables { - updatedConfig := config.Variables{} - maps.Copy(updatedConfig, testConfigRoutingTableRouteMin) - // nothing possible to update of the required attributes... - return updatedConfig -}() - -var testConfigRoutingTableRouteMax = config.Variables{ - "organization_id": config.StringVariable(testutil.OrganizationId), - "network_area_id": config.StringVariable(testNetworkAreaId), - "routing_table_name": config.StringVariable(fmt.Sprintf("acc-test-%s", acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum))), - "destination_type": config.StringVariable("cidrv4"), // TODO: use cidrv6 once it's supported as we already test cidrv4 in the min test - "destination_value": config.StringVariable("192.168.178.0/24"), - "next_hop_type": config.StringVariable("ipv4"), // TODO: use ipv6, internet or blackhole once they are supported as we already test ipv4 in the min test - "next_hop_value": config.StringVariable("192.168.178.1"), - "label": config.StringVariable("route-label-01"), -} - -var testConfigRoutingTableRouteMaxUpdated = func() config.Variables { - updatedConfig := config.Variables{} - maps.Copy(updatedConfig, testConfigRoutingTableRouteMax) - updatedConfig["label"] = config.StringVariable("route-updated-label-01") - return updatedConfig -}() - -// execute routingtable and routingtable route min and max tests with t.Run() to prevent parallel runs (needed for tests of stackit_routing_tables datasource) -func TestAccRoutingTable(t *testing.T) { - t.Run("TestAccRoutingTableMin", func(t *testing.T) { - t.Logf("TestAccRoutingTableMin name: %s", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])) - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, - CheckDestroy: testAccCheckDestroy, - Steps: []resource.TestStep{ - // Creation - { - ConfigVariables: testConfigRoutingTableMin, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "0"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region), - resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), - ), - }, - // Data sources - { - ConfigVariables: testConfigRoutingTableMin, - Config: fmt.Sprintf(` - %s - %s - - # single routing table - data "stackit_routing_table" "routing_table" { - organization_id = stackit_routing_table.routing_table.organization_id - network_area_id = stackit_routing_table.routing_table.network_area_id - routing_table_id = stackit_routing_table.routing_table.routing_table_id - } - - # all routing tables in network area - data "stackit_routing_tables" "routing_tables" { - organization_id = stackit_routing_table.routing_table.organization_id - network_area_id = stackit_routing_table.routing_table.network_area_id - } - `, - testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig, - ), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["network_area_id"])), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "data.stackit_routing_table.routing_table", "routing_table_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.%", "0"), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.Region), - resource.TestCheckNoResourceAttr("data.stackit_routing_table.routing_table", "description"), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", "true"), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", "true"), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"), - - // Routing tables - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["network_area_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "region", testutil.Region), - // there will be always two routing tables because of the main routing table of the network area - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.#", "2"), - - // default routing table - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.0.default", "true"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.updated_at"), - - // second routing table managed via terraform - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "data.stackit_routing_tables.routing_tables", "items.1.routing_table_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.name", testutil.ConvertConfigVariable(testConfigRoutingTableMin["name"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.%", "0"), - resource.TestCheckNoResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description"), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", "true"), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", "true"), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"), - ), - }, - // Import - { - ConfigVariables: testConfigRoutingTableMinUpdated, - ResourceName: "stackit_routing_table.routing_table", - ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_routing_table.routing_table"] - if !ok { - return "", fmt.Errorf("couldn't find resource stackit_routing_table.routing_table") - } - region, ok := r.Primary.Attributes["region"] - if !ok { - return "", fmt.Errorf("couldn't find attribute region") - } - networkAreaId, ok := r.Primary.Attributes["network_area_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute network_area_id") - } - routingTableId, ok := r.Primary.Attributes["routing_table_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute routing_table_id") - } - return fmt.Sprintf("%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId), nil - }, - ImportState: true, - ImportStateVerify: true, - }, - // Update - { - ConfigVariables: testConfigRoutingTableMinUpdated, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["name"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "0"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.Region), - resource.TestCheckNoResourceAttr("stackit_routing_table.routing_table", "description"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", "true"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", "true"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), - ), - }, - // Deletion is done by the framework implicitly - }, - }) - }) - - t.Run("TestAccRoutingTableMax", func(t *testing.T) { - t.Logf("TestAccRoutingTableMax name: %s", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])) - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, - CheckDestroy: testAccCheckDestroy, - Steps: []resource.TestStep{ - // Creation - { - ConfigVariables: testConfigRoutingTableMax, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "1"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), - ), - }, - // Data sources - { - ConfigVariables: testConfigRoutingTableMax, - Config: fmt.Sprintf(` - %s - %s - - # single routing table - data "stackit_routing_table" "routing_table" { - organization_id = stackit_routing_table.routing_table.organization_id - network_area_id = stackit_routing_table.routing_table.network_area_id - routing_table_id = stackit_routing_table.routing_table.routing_table_id - } - - # all routing tables in network area - data "stackit_routing_tables" "routing_tables" { - organization_id = stackit_routing_table.routing_table.organization_id - network_area_id = stackit_routing_table.routing_table.network_area_id - } - `, - testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig, - ), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["network_area_id"])), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "data.stackit_routing_table.routing_table", "routing_table_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.%", "1"), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), - resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "default", "false"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table.routing_table", "updated_at"), - - // Routing tables - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["network_area_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMax["region"])), - // there will be always two routing tables because of the main routing table of the network area - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.#", "2"), - - // default routing table - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.0.default", "true"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.0.updated_at"), - - // second routing table managed via terraform - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "data.stackit_routing_tables.routing_tables", "items.1.routing_table_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.name", testutil.ConvertConfigVariable(testConfigRoutingTableMax["name"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.%", "1"), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMax["label"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.description", testutil.ConvertConfigVariable(testConfigRoutingTableMax["description"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["system_routes"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMax["dynamic_routes"])), - resource.TestCheckResourceAttr("data.stackit_routing_tables.routing_tables", "items.1.default", "false"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_tables.routing_tables", "items.1.updated_at"), - ), - }, - // Import - { - ConfigVariables: testConfigRoutingTableMaxUpdated, - ResourceName: "stackit_routing_table.routing_table", - ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_routing_table.routing_table"] - if !ok { - return "", fmt.Errorf("couldn't find resource stackit_routing_table.routing_table") - } - region, ok := r.Primary.Attributes["region"] - if !ok { - return "", fmt.Errorf("couldn't find attribute region") - } - networkAreaId, ok := r.Primary.Attributes["network_area_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute network_area_id") - } - routingTableId, ok := r.Primary.Attributes["routing_table_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute routing_table_id") - } - return fmt.Sprintf("%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId), nil - }, - ImportState: true, - ImportStateVerify: true, - }, - // Update - { - ConfigVariables: testConfigRoutingTableMaxUpdated, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["name"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.%", "1"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["label"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "region", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["region"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "description", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["description"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "system_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["system_routes"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "dynamic_routes", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["dynamic_routes"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "updated_at"), - ), - }, - // Deletion is done by the framework implicitly - }, - }) - }) - - t.Run("TestAccRoutingTableRouteMin", func(t *testing.T) { - t.Logf("TestAccRoutingTableRouteMin") - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, - CheckDestroy: testAccCheckDestroy, - Steps: []resource.TestStep{ - // Creation - { - ConfigVariables: testConfigRoutingTableRouteMin, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["routing_table_name"])), - - // Routing table route - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "0"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), - ), - }, - // Data sources - { - ConfigVariables: testConfigRoutingTableRouteMin, - Config: fmt.Sprintf(` - %s - %s - - # single routing table route - data "stackit_routing_table_route" "route" { - organization_id = stackit_routing_table_route.route.organization_id - network_area_id = stackit_routing_table_route.route.network_area_id - routing_table_id = stackit_routing_table_route.route.routing_table_id - route_id = stackit_routing_table_route.route.route_id - } - - # all routing table routes in routing table - data "stackit_routing_table_routes" "routes" { - organization_id = stackit_routing_table_route.route.organization_id - network_area_id = stackit_routing_table_route.route.network_area_id - routing_table_id = stackit_routing_table_route.route.routing_table_id - } - `, - testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig, - ), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table route - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["network_area_id"])), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "routing_table_id", - "data.stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "route_id", - "data.stackit_routing_table_route.route", "route_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.%", "0"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "updated_at"), - - // Routing table routes - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["network_area_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "region", testutil.Region), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.#", "1"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "routing_table_id", - "data.stackit_routing_table_routes.routes", "routing_table_id", - ), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "route_id", - "data.stackit_routing_table_routes.routes", "routes.0.route_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["destination_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMin["next_hop_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.%", "0"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.updated_at"), - ), - }, - // Import - { - ConfigVariables: testConfigRoutingTableRouteMinUpdated, - ResourceName: "stackit_routing_table_route.route", - ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_routing_table_route.route"] - if !ok { - return "", fmt.Errorf("couldn't find resource stackit_routing_table_route.route") - } - region, ok := r.Primary.Attributes["region"] - if !ok { - return "", fmt.Errorf("couldn't find attribute region") - } - networkAreaId, ok := r.Primary.Attributes["network_area_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute network_area_id") - } - routingTableId, ok := r.Primary.Attributes["routing_table_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute routing_table_id") - } - routeId, ok := r.Primary.Attributes["route_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute route_id") - } - return fmt.Sprintf("%s,%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId, routeId), nil - }, - ImportState: true, - ImportStateVerify: true, - }, - // Update - { - ConfigVariables: testConfigRoutingTableRouteMinUpdated, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMinConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["routing_table_name"])), - - // Routing table route - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["destination_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["destination_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["next_hop_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMinUpdated["next_hop_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "0"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), - ), - }, - // Deletion is done by the framework implicitly - }, - }) - }) - - t.Run("TestAccRoutingTableRouteMax", func(t *testing.T) { - t.Logf("TestAccRoutingTableRouteMax") - resource.Test(t, resource.TestCase{ - ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories, - CheckDestroy: testAccCheckDestroy, - Steps: []resource.TestStep{ - // Creation - { - ConfigVariables: testConfigRoutingTableRouteMax, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["routing_table_name"])), - - // Routing table route - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "1"), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), - ), - }, - // Data sources - { - ConfigVariables: testConfigRoutingTableRouteMax, - Config: fmt.Sprintf(` - %s - %s - - # single routing table route - data "stackit_routing_table_route" "route" { - organization_id = stackit_routing_table_route.route.organization_id - network_area_id = stackit_routing_table_route.route.network_area_id - routing_table_id = stackit_routing_table_route.route.routing_table_id - route_id = stackit_routing_table_route.route.route_id - } - - # all routing table routes in routing table - data "stackit_routing_table_routes" "routes" { - organization_id = stackit_routing_table_route.route.organization_id - network_area_id = stackit_routing_table_route.route.network_area_id - routing_table_id = stackit_routing_table_route.route.routing_table_id - } - `, - testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig, - ), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table route - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["network_area_id"])), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "routing_table_id", - "data.stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "route_id", - "data.stackit_routing_table_route.route", "route_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.%", "1"), - resource.TestCheckResourceAttr("data.stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_route.route", "updated_at"), - - // Routing table routes - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["organization_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["network_area_id"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "region", testutil.Region), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.#", "1"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "routing_table_id", - "data.stackit_routing_table_routes.routes", "routing_table_id", - ), - resource.TestCheckResourceAttrPair( - "stackit_routing_table_route.route", "route_id", - "data.stackit_routing_table_routes.routes", "routes.0.route_id", - ), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["destination_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_type"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["next_hop_value"])), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.%", "1"), - resource.TestCheckResourceAttr("data.stackit_routing_table_routes.routes", "routes.0.labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMax["label"])), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.created_at"), - resource.TestCheckResourceAttrSet("data.stackit_routing_table_routes.routes", "routes.0.updated_at"), - ), - }, - // Import - { - ConfigVariables: testConfigRoutingTableRouteMaxUpdated, - ResourceName: "stackit_routing_table_route.route", - ImportStateIdFunc: func(s *terraform.State) (string, error) { - r, ok := s.RootModule().Resources["stackit_routing_table_route.route"] - if !ok { - return "", fmt.Errorf("couldn't find resource stackit_routing_table_route.route") - } - region, ok := r.Primary.Attributes["region"] - if !ok { - return "", fmt.Errorf("couldn't find attribute region") - } - networkAreaId, ok := r.Primary.Attributes["network_area_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute network_area_id") - } - routingTableId, ok := r.Primary.Attributes["routing_table_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute routing_table_id") - } - routeId, ok := r.Primary.Attributes["route_id"] - if !ok { - return "", fmt.Errorf("couldn't find attribute route_id") - } - return fmt.Sprintf("%s,%s,%s,%s,%s", testutil.OrganizationId, region, networkAreaId, routingTableId, routeId), nil - }, - ImportState: true, - ImportStateVerify: true, - }, - // Update - { - ConfigVariables: testConfigRoutingTableRouteMaxUpdated, - Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableRouteMaxConfig), - Check: resource.ComposeAggregateTestCheckFunc( - // Routing table - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table.routing_table", "routing_table_id"), - resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "name", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["routing_table_name"])), - - // Routing table route - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["organization_id"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "network_area_id", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["network_area_id"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "routing_table_id"), - resource.TestCheckResourceAttrPair( - "stackit_routing_table.routing_table", "routing_table_id", - "stackit_routing_table_route.route", "routing_table_id", - ), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "region", testutil.Region), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["destination_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "destination.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["destination_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.type", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["next_hop_type"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "next_hop.value", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["next_hop_value"])), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.%", "1"), - resource.TestCheckResourceAttr("stackit_routing_table_route.route", "labels.acc-test", testutil.ConvertConfigVariable(testConfigRoutingTableRouteMaxUpdated["label"])), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "created_at"), - resource.TestCheckResourceAttrSet("stackit_routing_table_route.route", "updated_at"), - ), - }, - // Deletion is done by the framework implicitly - }, - }) - }) -} - -func testAccCheckDestroy(s *terraform.State) error { - checkFunctions := []func(s *terraform.State) error{ - testAccCheckRoutingTableDestroy, - testAccCheckRoutingTableRouteDestroy, - } - var errs []error - - wg := sync.WaitGroup{} - wg.Add(len(checkFunctions)) - - for _, f := range checkFunctions { - go func() { - err := f(s) - if err != nil { - errs = append(errs, err) - } - wg.Done() - }() - } - wg.Wait() - return errors.Join(errs...) -} - -func testAccCheckRoutingTableDestroy(s *terraform.State) error { - ctx := context.Background() - var client *iaasalpha.APIClient - var err error - if testutil.IaaSCustomEndpoint == "" { - client, err = iaasalpha.NewAPIClient() - } else { - client, err = iaasalpha.NewAPIClient( - stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), - ) - } - if err != nil { - return fmt.Errorf("creating client: %w", err) - } - - var errs []error - // routing tables - for _, rs := range s.RootModule().Resources { - if rs.Type != "stackit_routing_table" { - continue - } - routingTableId := strings.Split(rs.Primary.ID, core.Separator)[3] - region := strings.Split(rs.Primary.ID, core.Separator)[1] - err := client.DeleteRoutingTableFromAreaExecute(ctx, testutil.OrganizationId, testNetworkAreaId, region, routingTableId) - if err != nil { - var oapiErr *oapierror.GenericOpenAPIError - if errors.As(err, &oapiErr) { - if oapiErr.StatusCode == http.StatusNotFound { - continue - } - } - errs = append(errs, fmt.Errorf("cannot trigger routing table deletion %q: %w", routingTableId, err)) - } - } - - return errors.Join(errs...) -} - -func testAccCheckRoutingTableRouteDestroy(s *terraform.State) error { - ctx := context.Background() - var client *iaasalpha.APIClient - var err error - if testutil.IaaSCustomEndpoint == "" { - client, err = iaasalpha.NewAPIClient() - } else { - client, err = iaasalpha.NewAPIClient( - stackitSdkConfig.WithEndpoint(testutil.IaaSCustomEndpoint), - ) - } - if err != nil { - return fmt.Errorf("creating client: %w", err) - } - - var errs []error - // routes - for _, rs := range s.RootModule().Resources { - if rs.Type != "stackit_routing_table_route" { - continue - } - routingTableRouteId := strings.Split(rs.Primary.ID, core.Separator)[4] - routingTableId := strings.Split(rs.Primary.ID, core.Separator)[3] - region := strings.Split(rs.Primary.ID, core.Separator)[1] - err := client.DeleteRouteFromRoutingTableExecute(ctx, testutil.OrganizationId, testNetworkAreaId, region, routingTableId, routingTableRouteId) - if err != nil { - var oapiErr *oapierror.GenericOpenAPIError - if errors.As(err, &oapiErr) { - if oapiErr.StatusCode == http.StatusNotFound { - continue - } - } - errs = append(errs, fmt.Errorf("cannot trigger routing table route deletion %q: %w", routingTableId, err)) - } - } - - return errors.Join(errs...) -} diff --git a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-max.tf b/stackit/internal/services/iaasalpha/testdata/resource-routingtable-max.tf deleted file mode 100644 index f5e221144..000000000 --- a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-max.tf +++ /dev/null @@ -1,21 +0,0 @@ -variable "organization_id" {} -variable "network_area_id" {} -variable "name" {} -variable "description" {} -variable "region" {} -variable "label" {} -variable "system_routes" {} -variable "dynamic_routes" {} - -resource "stackit_routing_table" "routing_table" { - organization_id = var.organization_id - network_area_id = var.network_area_id - name = var.name - description = var.description - region = var.region - labels = { - "acc-test" : var.label - } - system_routes = var.system_routes - dynamic_routes = var.dynamic_routes -} diff --git a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-min.tf b/stackit/internal/services/iaasalpha/testdata/resource-routingtable-min.tf deleted file mode 100644 index 26921d7d3..000000000 --- a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-min.tf +++ /dev/null @@ -1,9 +0,0 @@ -variable "organization_id" {} -variable "network_area_id" {} -variable "name" {} - -resource "stackit_routing_table" "routing_table" { - organization_id = var.organization_id - network_area_id = var.network_area_id - name = var.name -} diff --git a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-max.tf b/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-max.tf deleted file mode 100644 index da2833c01..000000000 --- a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-max.tf +++ /dev/null @@ -1,31 +0,0 @@ -variable "organization_id" {} -variable "network_area_id" {} -variable "routing_table_name" {} -variable "destination_type" {} -variable "destination_value" {} -variable "next_hop_type" {} -variable "next_hop_value" {} -variable "label" {} - -resource "stackit_routing_table" "routing_table" { - organization_id = var.organization_id - network_area_id = var.network_area_id - name = var.routing_table_name -} - -resource "stackit_routing_table_route" "route" { - organization_id = var.organization_id - network_area_id = var.network_area_id - routing_table_id = stackit_routing_table.routing_table.routing_table_id - destination = { - type = var.destination_type - value = var.destination_value - } - next_hop = { - type = var.next_hop_type - value = var.next_hop_value - } - labels = { - "acc-test" = var.label - } -} diff --git a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-min.tf b/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-min.tf deleted file mode 100644 index 65336be84..000000000 --- a/stackit/internal/services/iaasalpha/testdata/resource-routingtable-route-min.tf +++ /dev/null @@ -1,27 +0,0 @@ -variable "organization_id" {} -variable "network_area_id" {} -variable "routing_table_name" {} -variable "destination_type" {} -variable "destination_value" {} -variable "next_hop_type" {} -variable "next_hop_value" {} - -resource "stackit_routing_table" "routing_table" { - organization_id = var.organization_id - network_area_id = var.network_area_id - name = var.routing_table_name -} - -resource "stackit_routing_table_route" "route" { - organization_id = var.organization_id - network_area_id = var.network_area_id - routing_table_id = stackit_routing_table.routing_table.routing_table_id - destination = { - type = var.destination_type - value = var.destination_value - } - next_hop = { - type = var.next_hop_type - value = var.next_hop_value - } -} diff --git a/stackit/internal/services/iaasalpha/utils/util.go b/stackit/internal/services/iaasalpha/utils/util.go deleted file mode 100644 index 40216b924..000000000 --- a/stackit/internal/services/iaasalpha/utils/util.go +++ /dev/null @@ -1,29 +0,0 @@ -package utils - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" -) - -func ConfigureClient(ctx context.Context, providerData *core.ProviderData, diags *diag.Diagnostics) *iaasalpha.APIClient { - apiClientConfigOptions := []config.ConfigurationOption{ - config.WithCustomAuth(providerData.RoundTripper), - utils.UserAgentConfigOption(providerData.Version), - } - if providerData.IaaSCustomEndpoint != "" { - apiClientConfigOptions = append(apiClientConfigOptions, config.WithEndpoint(providerData.IaaSCustomEndpoint)) - } - apiClient, err := iaasalpha.NewAPIClient(apiClientConfigOptions...) - if err != nil { - core.LogAndAddError(ctx, diags, "Error configuring API client", fmt.Sprintf("Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration", err)) - return nil - } - - return apiClient -} diff --git a/stackit/internal/services/iaasalpha/utils/util_test.go b/stackit/internal/services/iaasalpha/utils/util_test.go deleted file mode 100644 index d4ba46713..000000000 --- a/stackit/internal/services/iaasalpha/utils/util_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package utils - -import ( - "context" - "os" - "reflect" - "testing" - - "github.com/hashicorp/terraform-plugin-framework/diag" - sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients" - "github.com/stackitcloud/stackit-sdk-go/core/config" - "github.com/stackitcloud/stackit-sdk-go/services/iaasalpha" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core" - "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils" -) - -const ( - testVersion = "1.2.3" - testCustomEndpoint = "https://iaas-custom-endpoint.api.stackit.cloud" -) - -func TestConfigureClient(t *testing.T) { - /* mock authentication by setting service account token env variable */ - os.Clearenv() - err := os.Setenv(sdkClients.ServiceAccountToken, "mock-val") - if err != nil { - t.Errorf("error setting env variable: %v", err) - } - - type args struct { - providerData *core.ProviderData - } - tests := []struct { - name string - args args - wantErr bool - expected *iaasalpha.APIClient - }{ - { - name: "default endpoint", - args: args{ - providerData: &core.ProviderData{ - Version: testVersion, - }, - }, - expected: func() *iaasalpha.APIClient { - apiClient, err := iaasalpha.NewAPIClient( - utils.UserAgentConfigOption(testVersion), - ) - if err != nil { - t.Errorf("error configuring client: %v", err) - } - return apiClient - }(), - wantErr: false, - }, - { - name: "custom endpoint", - args: args{ - providerData: &core.ProviderData{ - Version: testVersion, - IaaSCustomEndpoint: testCustomEndpoint, - }, - }, - expected: func() *iaasalpha.APIClient { - apiClient, err := iaasalpha.NewAPIClient( - utils.UserAgentConfigOption(testVersion), - config.WithEndpoint(testCustomEndpoint), - ) - if err != nil { - t.Errorf("error configuring client: %v", err) - } - return apiClient - }(), - wantErr: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - ctx := context.Background() - diags := diag.Diagnostics{} - - actual := ConfigureClient(ctx, tt.args.providerData, &diags) - if diags.HasError() != tt.wantErr { - t.Errorf("ConfigureClient() error = %v, want %v", diags.HasError(), tt.wantErr) - } - - if !reflect.DeepEqual(actual, tt.expected) { - t.Errorf("ConfigureClient() = %v, want %v", actual, tt.expected) - } - }) - } -} diff --git a/stackit/provider.go b/stackit/provider.go index 4879dfe09..9575aed44 100644 --- a/stackit/provider.go +++ b/stackit/provider.go @@ -46,16 +46,16 @@ import ( iaasPublicIp "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/publicip" iaasPublicIpAssociate "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/publicipassociate" iaasPublicIpRanges "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/publicipranges" + iaasRoutingTableRoute "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/route" + iaasRoutingTableRoutes "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/routes" + iaasRoutingTable "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/table" + iaasRoutingTables "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/routingtable/tables" iaasSecurityGroup "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/securitygroup" iaasSecurityGroupRule "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/securitygrouprule" iaasServer "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/server" iaasServiceAccountAttach "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/serviceaccountattach" iaasVolume "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/volume" iaasVolumeAttach "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/volumeattach" - iaasalphaRoutingTableRoute "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/route" - iaasalphaRoutingTableRoutes "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/routes" - iaasalphaRoutingTable "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/table" - iaasalphaRoutingTables "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaasalpha/routingtable/tables" kmsKey "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/kms/key" kmsKeyRing "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/kms/keyring" kmsWrappingKey "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/kms/wrapping-key" @@ -538,10 +538,10 @@ func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource iaasKeyPair.NewKeyPairDataSource, iaasServer.NewServerDataSource, iaasSecurityGroup.NewSecurityGroupDataSource, - iaasalphaRoutingTable.NewRoutingTableDataSource, - iaasalphaRoutingTableRoute.NewRoutingTableRouteDataSource, - iaasalphaRoutingTables.NewRoutingTablesDataSource, - iaasalphaRoutingTableRoutes.NewRoutingTableRoutesDataSource, + iaasRoutingTable.NewRoutingTableDataSource, + iaasRoutingTableRoute.NewRoutingTableRouteDataSource, + iaasRoutingTables.NewRoutingTablesDataSource, + iaasRoutingTableRoutes.NewRoutingTableRoutesDataSource, iaasSecurityGroupRule.NewSecurityGroupRuleDataSource, kmsKey.NewKeyDataSource, kmsKeyRing.NewKeyRingDataSource, @@ -620,8 +620,8 @@ func (p *Provider) Resources(_ context.Context) []func() resource.Resource { iaasServer.NewServerResource, iaasSecurityGroup.NewSecurityGroupResource, iaasSecurityGroupRule.NewSecurityGroupRuleResource, - iaasalphaRoutingTable.NewRoutingTableResource, - iaasalphaRoutingTableRoute.NewRoutingTableRouteResource, + iaasRoutingTable.NewRoutingTableResource, + iaasRoutingTableRoute.NewRoutingTableRouteResource, kmsKey.NewKeyResource, kmsKeyRing.NewKeyRingResource, kmsWrappingKey.NewWrappingKeyResource,