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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions stackit/internal/services/iaas/iaas_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ var testConfigRoutingTableMaxUpdated = func() config.Variables {
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["system_routes"] = config.BoolVariable(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also adjust the Acc tests to ensure there's a update triggered and no replace:

ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_kms_keyring.keyring", plancheck.ResourceActionNoop),
},
},

ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_kms_keyring.keyring", plancheck.ResourceActionReplace),
},
},

This can be done using the plancheck package, the KMS acc test is a great example for it 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint. Have added the planchecks for the routing table tests.

updatedConfig["dynamic_routes"] = config.BoolVariable(true)
return updatedConfig
}()
Expand Down Expand Up @@ -4693,6 +4694,11 @@ func TestAccRoutingTableMin(t *testing.T) {
{
ConfigVariables: testConfigRoutingTableMin,
Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionCreate),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Network Area
resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])),
Expand Down Expand Up @@ -4750,6 +4756,11 @@ func TestAccRoutingTableMin(t *testing.T) {
`,
testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig,
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionNoop),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Routing table
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMin["organization_id"])),
Expand Down Expand Up @@ -4831,6 +4842,11 @@ func TestAccRoutingTableMin(t *testing.T) {
{
ConfigVariables: testConfigRoutingTableMinUpdated,
Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMinConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionUpdate),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Routing table
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMinUpdated["organization_id"])),
Expand Down Expand Up @@ -4863,6 +4879,11 @@ func TestAccRoutingTableMax(t *testing.T) {
{
ConfigVariables: testConfigRoutingTableMax,
Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionCreate),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Network Area
resource.TestCheckResourceAttr("stackit_network_area_region.network_area_region", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])),
Expand Down Expand Up @@ -4919,6 +4940,11 @@ func TestAccRoutingTableMax(t *testing.T) {
`,
testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig,
),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionNoop),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Routing table
resource.TestCheckResourceAttr("data.stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMax["organization_id"])),
Expand Down Expand Up @@ -5002,6 +5028,11 @@ func TestAccRoutingTableMax(t *testing.T) {
{
ConfigVariables: testConfigRoutingTableMaxUpdated,
Config: fmt.Sprintf("%s\n%s", testutil.IaaSProviderConfigWithExperiments(), resourceRoutingTableMaxConfig),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionUpdate),
},
},
Check: resource.ComposeAggregateTestCheckFunc(
// Routing table
resource.TestCheckResourceAttr("stackit_routing_table.routing_table", "organization_id", testutil.ConvertConfigVariable(testConfigRoutingTableMaxUpdated["organization_id"])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"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"
Expand Down Expand Up @@ -202,9 +201,6 @@ func (r *routingTableResource) Schema(_ context.Context, _ resource.SchemaReques
Optional: true,
Computed: true,
Default: booldefault.StaticBool(true),
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.RequiresReplace(),
},
},
"dynamic_routes": schema.BoolAttribute{
Description: "This controls whether dynamic routes are propagated to this routing table",
Expand Down Expand Up @@ -531,5 +527,6 @@ func toUpdatePayload(ctx context.Context, model *Model, currentLabels types.Map)
Name: conversion.StringValueToPointer(model.Name),
Labels: &labels,
DynamicRoutes: conversion.BoolValueToPointer(model.DynamicRoutes),
SystemRoutes: conversion.BoolValueToPointer(model.SystemRoutes),
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func TestToUpdatePayload(t *testing.T) {
"key2": types.StringValue("value2"),
}),
DynamicRoutes: types.BoolValue(false),
SystemRoutes: types.BoolValue(false),
},
&iaas.UpdateRoutingTableOfAreaPayload{
Description: utils.Ptr("Description"),
Expand All @@ -192,6 +193,7 @@ func TestToUpdatePayload(t *testing.T) {
"key2": "value2",
},
DynamicRoutes: utils.Ptr(false),
SystemRoutes: utils.Ptr(false),
},
true,
},
Expand Down
Loading