feat(iaas): add experimental support for routing tables and routes (#896)

* Merged PR 788126: feat(iaas): Onboard routing tables

feat(iaas): Onboard routing tables

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Merged PR 793350: fix(routingtable): region attribute is missing in scheme

fix(routingtable): region attribute is missing in scheme

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

* Merged PR 797968: feat(iaas): onboarding of routing table routes

relates to STACKITTPR-241

* use iaasalpha sdk from github

* resolve todos

* remove routes from routing table model

* restructure packages

* acc tests routing tables

* add acc tests for routes

* chore(iaas): mark routing table resources as experimental

* chore(deps): use iaasalpha sdk v0.1.19-alpha

* Review feedback

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>

---------

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
Co-authored-by: Alexander Dahmen (EXT) <Alexander.Dahmen_ext@external.mail.schwarz>
Co-authored-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Ruben Hönle 2025-07-02 10:30:50 +02:00 committed by GitHub
parent d2c51afbe5
commit 9ff9b8f610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
65 changed files with 5160 additions and 53 deletions

View file

@ -0,0 +1,213 @@
package shared
import (
"context"
"fmt"
"strings"
"time"
"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/terraform-provider-stackit/stackit/internal/core"
iaasUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/utils"
)
type RouteReadModel struct {
RouteId types.String `tfsdk:"route_id"`
Destination types.Object `tfsdk:"destination"`
NextHop types.Object `tfsdk:"next_hop"`
Labels types.Map `tfsdk:"labels"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
}
func RouteReadModelTypes() map[string]attr.Type {
return map[string]attr.Type{
"route_id": types.StringType,
"destination": types.ObjectType{AttrTypes: RouteDestinationTypes},
"next_hop": types.ObjectType{AttrTypes: RouteNextHopTypes},
"labels": types.MapType{ElemType: types.StringType},
"created_at": types.StringType,
"updated_at": types.StringType,
}
}
type RouteModel struct {
RouteReadModel
Id types.String `tfsdk:"id"` // needed by TF
OrganizationId types.String `tfsdk:"organization_id"`
RoutingTableId types.String `tfsdk:"routing_table_id"`
NetworkAreaId types.String `tfsdk:"network_area_id"`
Region types.String `tfsdk:"region"`
}
func RouteModelTypes() map[string]attr.Type {
modelTypes := RouteReadModelTypes()
modelTypes["id"] = types.StringType
modelTypes["organization_id"] = types.StringType
modelTypes["routing_table_id"] = types.StringType
modelTypes["network_area_id"] = types.StringType
modelTypes["region"] = types.StringType
return modelTypes
}
// RouteDestination is the struct corresponding to RouteReadModel.Destination
type RouteDestination struct {
Type types.String `tfsdk:"type"`
Value types.String `tfsdk:"value"`
}
// RouteDestinationTypes Types corresponding to routeDestination
var RouteDestinationTypes = map[string]attr.Type{
"type": types.StringType,
"value": types.StringType,
}
// RouteNextHop is the struct corresponding to RouteReadModel.NextHop
type RouteNextHop struct {
Type types.String `tfsdk:"type"`
Value types.String `tfsdk:"value"`
}
// RouteNextHopTypes Types corresponding to routeNextHop
var RouteNextHopTypes = map[string]attr.Type{
"type": types.StringType,
"value": types.StringType,
}
func MapRouteModel(ctx context.Context, route *iaasalpha.Route, model *RouteModel, region string) error {
if route == nil {
return fmt.Errorf("response input is nil")
}
if model == nil {
return fmt.Errorf("model input is nil")
}
err := MapRouteReadModel(ctx, route, &model.RouteReadModel)
if err != nil {
return err
}
idParts := []string{
model.OrganizationId.ValueString(),
region,
model.NetworkAreaId.ValueString(),
model.RoutingTableId.ValueString(),
model.RouteId.ValueString(),
}
model.Id = types.StringValue(
strings.Join(idParts, core.Separator),
)
model.Region = types.StringValue(region)
return nil
}
func MapRouteReadModel(ctx context.Context, route *iaasalpha.Route, model *RouteReadModel) error {
if route == nil {
return fmt.Errorf("response input is nil")
}
if model == nil {
return fmt.Errorf("model input is nil")
}
var routeId string
if model.RouteId.ValueString() != "" {
routeId = model.RouteId.ValueString()
} else if route.Id != nil {
routeId = *route.Id
} else {
return fmt.Errorf("routing table route id not present")
}
labels, err := iaasUtils.MapLabels(ctx, route.Labels, model.Labels)
if err != nil {
return err
}
// created at and updated at
createdAtTF, updatedAtTF := types.StringNull(), types.StringNull()
if route.CreatedAt != nil {
createdAtValue := *route.CreatedAt
createdAtTF = types.StringValue(createdAtValue.Format(time.RFC3339))
}
if route.UpdatedAt != nil {
updatedAtValue := *route.UpdatedAt
updatedAtTF = types.StringValue(updatedAtValue.Format(time.RFC3339))
}
// destination
model.Destination, err = MapRouteDestination(route)
if err != nil {
return fmt.Errorf("error mapping route destination: %w", err)
}
// next hop
model.NextHop, err = MapRouteNextHop(route)
if err != nil {
return fmt.Errorf("error mapping route next hop: %w", err)
}
model.RouteId = types.StringValue(routeId)
model.CreatedAt = createdAtTF
model.UpdatedAt = updatedAtTF
model.Labels = labels
return nil
}
func MapRouteNextHop(routeResp *iaasalpha.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:
nextHopMap["type"] = types.StringValue(*i.Type)
nextHopMap["value"] = types.StringPointerValue(i.Value)
case *iaasalpha.NexthopIPv6:
nextHopMap["type"] = types.StringValue(*i.Type)
nextHopMap["value"] = types.StringPointerValue(i.Value)
case *iaasalpha.NexthopBlackhole:
nextHopMap["type"] = types.StringValue(*i.Type)
nextHopMap["value"] = types.StringNull()
case *iaasalpha.NexthopInternet:
nextHopMap["type"] = types.StringValue(*i.Type)
nextHopMap["value"] = types.StringNull()
default:
return types.ObjectNull(RouteNextHopTypes), fmt.Errorf("unexpected Nexthop type: %T", i)
}
nextHopTF, diags := types.ObjectValue(RouteNextHopTypes, nextHopMap)
if diags.HasError() {
return types.ObjectNull(RouteNextHopTypes), core.DiagsToError(diags)
}
return nextHopTF, nil
}
func MapRouteDestination(routeResp *iaasalpha.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:
destinationMap["type"] = types.StringValue(*i.Type)
destinationMap["value"] = types.StringPointerValue(i.Value)
case *iaasalpha.DestinationCIDRv6:
destinationMap["type"] = types.StringValue(*i.Type)
destinationMap["value"] = types.StringPointerValue(i.Value)
default:
return types.ObjectNull(RouteDestinationTypes), fmt.Errorf("unexpected Destionation type: %T", i)
}
destinationTF, diags := types.ObjectValue(RouteDestinationTypes, destinationMap)
if diags.HasError() {
return types.ObjectNull(RouteDestinationTypes), core.DiagsToError(diags)
}
return destinationTF, nil
}

View file

@ -0,0 +1,310 @@
package shared
import (
"context"
"fmt"
"testing"
"time"
"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 (
testRegion = "eu02"
)
var (
testRouteId = uuid.New()
testOrganizationId = uuid.New()
testNetworkAreaId = uuid.New()
testRoutingTableId = uuid.New()
)
func Test_MapRouteNextHop(t *testing.T) {
type args struct {
routeResp *iaasalpha.Route
}
tests := []struct {
name string
args args
wantErr bool
expected types.Object
}{
{
name: "nexthop is nil",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: nil,
},
},
wantErr: false,
expected: types.ObjectNull(RouteNextHopTypes),
},
{
name: "nexthop is empty",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: &iaasalpha.RouteNexthop{},
},
},
wantErr: true,
},
{
name: "nexthop ipv4",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: utils.Ptr(iaasalpha.NexthopIPv4AsRouteNexthop(
iaasalpha.NewNexthopIPv4("ipv4", "10.20.42.2"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteNextHopTypes, map[string]attr.Value{
"type": types.StringValue("ipv4"),
"value": types.StringValue("10.20.42.2"),
}),
},
{
name: "nexthop ipv6",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: utils.Ptr(iaasalpha.NexthopIPv6AsRouteNexthop(
iaasalpha.NewNexthopIPv6("ipv6", "172b:f881:46fe:d89a:9332:90f7:3485:236d"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteNextHopTypes, map[string]attr.Value{
"type": types.StringValue("ipv6"),
"value": types.StringValue("172b:f881:46fe:d89a:9332:90f7:3485:236d"),
}),
},
{
name: "nexthop internet",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: utils.Ptr(iaasalpha.NexthopInternetAsRouteNexthop(
iaasalpha.NewNexthopInternet("internet"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteNextHopTypes, map[string]attr.Value{
"type": types.StringValue("internet"),
"value": types.StringNull(),
}),
},
{
name: "nexthop blackhole",
args: args{
routeResp: &iaasalpha.Route{
Nexthop: utils.Ptr(iaasalpha.NexthopBlackholeAsRouteNexthop(
iaasalpha.NewNexthopBlackhole("blackhole"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteNextHopTypes, map[string]attr.Value{
"type": types.StringValue("blackhole"),
"value": types.StringNull(),
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual, err := MapRouteNextHop(tt.args.routeResp)
if (err != nil) != tt.wantErr {
t.Errorf("mapNextHop() error = %v, wantErr %v", err, tt.wantErr)
}
diff := cmp.Diff(actual, tt.expected)
if !tt.wantErr && diff != "" {
t.Errorf("mapNextHop() result does not match: %s", diff)
}
})
}
}
func Test_MapRouteDestination(t *testing.T) {
type args struct {
routeResp *iaasalpha.Route
}
tests := []struct {
name string
args args
wantErr bool
expected types.Object
}{
{
name: "destination is nil",
args: args{
routeResp: &iaasalpha.Route{
Destination: nil,
},
},
wantErr: false,
expected: types.ObjectNull(RouteDestinationTypes),
},
{
name: "destination is empty",
args: args{
routeResp: &iaasalpha.Route{
Destination: &iaasalpha.RouteDestination{},
},
},
wantErr: true,
},
{
name: "destination cidrv4",
args: args{
routeResp: &iaasalpha.Route{
Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination(
iaasalpha.NewDestinationCIDRv4("cidrv4", "58.251.236.138/32"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteDestinationTypes, map[string]attr.Value{
"type": types.StringValue("cidrv4"),
"value": types.StringValue("58.251.236.138/32"),
}),
},
{
name: "destination cidrv6",
args: args{
routeResp: &iaasalpha.Route{
Destination: utils.Ptr(iaasalpha.DestinationCIDRv6AsRouteDestination(
iaasalpha.NewDestinationCIDRv6("cidrv6", "2001:0db8:3c4d:1a2b::/64"),
)),
},
},
wantErr: false,
expected: types.ObjectValueMust(RouteDestinationTypes, map[string]attr.Value{
"type": types.StringValue("cidrv6"),
"value": types.StringValue("2001:0db8:3c4d:1a2b::/64"),
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual, err := MapRouteDestination(tt.args.routeResp)
if (err != nil) != tt.wantErr {
t.Errorf("mapDestination() error = %v, wantErr %v", err, tt.wantErr)
}
diff := cmp.Diff(actual, tt.expected)
if !tt.wantErr && diff != "" {
t.Errorf("mapDestination() result does not match: %s", diff)
}
})
}
}
func TestMapRouteModel(t *testing.T) {
createdAt := time.Now()
updatedAt := time.Now().Add(5 * time.Minute)
type args struct {
route *iaasalpha.Route
model *RouteModel
region string
}
tests := []struct {
name string
args args
wantErr bool
expectedModel *RouteModel
}{
{
name: "route is nil",
args: args{
model: &RouteModel{},
route: nil,
region: testRegion,
},
wantErr: true,
},
{
name: "model is nil",
args: args{
model: nil,
route: &iaasalpha.Route{},
region: testRegion,
},
wantErr: true,
},
{
name: "max",
args: args{
model: &RouteModel{
// state
OrganizationId: types.StringValue(testOrganizationId.String()),
NetworkAreaId: types.StringValue(testNetworkAreaId.String()),
RoutingTableId: types.StringValue(testRoutingTableId.String()),
},
route: &iaasalpha.Route{
Id: utils.Ptr(testRouteId.String()),
Destination: utils.Ptr(iaasalpha.DestinationCIDRv4AsRouteDestination(
iaasalpha.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")),
),
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
},
region: testRegion,
},
wantErr: false,
expectedModel: &RouteModel{
Id: types.StringValue(fmt.Sprintf("%s,%s,%s,%s,%s",
testOrganizationId.String(), testRegion, testNetworkAreaId.String(), testRoutingTableId.String(), testRouteId.String()),
),
OrganizationId: types.StringValue(testOrganizationId.String()),
NetworkAreaId: types.StringValue(testNetworkAreaId.String()),
RoutingTableId: types.StringValue(testRoutingTableId.String()),
RouteReadModel: RouteReadModel{
RouteId: types.StringValue(testRouteId.String()),
Destination: types.ObjectValueMust(RouteDestinationTypes, map[string]attr.Value{
"type": types.StringValue("cidrv4"),
"value": types.StringValue("58.251.236.138/32"),
}),
Labels: types.MapValueMust(types.StringType, map[string]attr.Value{
"foo1": types.StringValue("bar1"),
"foo2": types.StringValue("bar2"),
}),
NextHop: types.ObjectValueMust(RouteNextHopTypes, map[string]attr.Value{
"type": types.StringValue("ipv4"),
"value": types.StringValue("10.20.42.2"),
}),
CreatedAt: types.StringValue(createdAt.Format(time.RFC3339)),
UpdatedAt: types.StringValue(updatedAt.Format(time.RFC3339)),
},
Region: types.StringValue(testRegion),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
if err := MapRouteModel(ctx, tt.args.route, tt.args.model, tt.args.region); (err != nil) != tt.wantErr {
t.Errorf("MapRouteModel() error = %v, wantErr %v", err, tt.wantErr)
}
diff := cmp.Diff(tt.args.model, tt.expectedModel)
if !tt.wantErr && diff != "" {
t.Errorf("MapRouteModel() model does not match: %s", diff)
}
})
}
}

View file

@ -0,0 +1,263 @@
package shared
import (
"context"
"fmt"
"maps"
"time"
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"
)
type RoutingTableReadModel struct {
RoutingTableId types.String `tfsdk:"routing_table_id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Labels types.Map `tfsdk:"labels"`
CreatedAt types.String `tfsdk:"created_at"`
UpdatedAt types.String `tfsdk:"updated_at"`
Default types.Bool `tfsdk:"default"`
SystemRoutes types.Bool `tfsdk:"system_routes"`
}
func RoutingTableReadModelTypes() map[string]attr.Type {
return map[string]attr.Type{
"routing_table_id": types.StringType,
"name": types.StringType,
"description": types.StringType,
"labels": types.MapType{ElemType: types.StringType},
"created_at": types.StringType,
"updated_at": types.StringType,
"default": types.BoolType,
"system_routes": types.BoolType,
}
}
type RoutingTableDataSourceModel struct {
RoutingTableReadModel
Id types.String `tfsdk:"id"` // needed by TF
OrganizationId types.String `tfsdk:"organization_id"`
NetworkAreaId types.String `tfsdk:"network_area_id"`
Region types.String `tfsdk:"region"`
}
func GetDatasourceGetAttributes() map[string]schema.Attribute {
// combine the schemas
getAttributes := RoutingTableResponseAttributes()
maps.Copy(getAttributes, datasourceGetAttributes())
getAttributes["id"] = schema.StringAttribute{
Description: "Terraform's internal datasource ID. It is structured as \"`organization_id`,`region`,`network_area_id`,`routing_table_id`\".",
Computed: true,
}
return getAttributes
}
func GetRouteDataSourceAttributes() map[string]schema.Attribute {
getAttributes := datasourceGetAttributes()
maps.Copy(getAttributes, RouteResponseAttributes())
getAttributes["route_id"] = schema.StringAttribute{
Description: "Route ID.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
}
getAttributes["id"] = schema.StringAttribute{
Description: "Terraform's internal datasource ID. It is structured as \"`organization_id`,`region`,`network_area_id`,`routing_table_id`,`route_id`\".",
Computed: true,
}
return getAttributes
}
func GetRoutesDataSourceAttributes() map[string]schema.Attribute {
getAttributes := datasourceGetAttributes()
getAttributes["id"] = schema.StringAttribute{
Description: "Terraform's internal datasource ID. It is structured as \"`organization_id`,`region`,`network_area_id`,`routing_table_id`,`route_id`\".",
Computed: true,
}
getAttributes["routes"] = schema.ListNestedAttribute{
Description: "List of routes.",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: RouteResponseAttributes(),
},
}
getAttributes["region"] = schema.StringAttribute{
Description: "The datasource region. If not defined, the provider region is used.",
Optional: true,
}
return getAttributes
}
func datasourceGetAttributes() map[string]schema.Attribute {
return map[string]schema.Attribute{
"organization_id": schema.StringAttribute{
Description: "STACKIT organization ID to which the routing table is associated.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
},
"routing_table_id": schema.StringAttribute{
Description: "The routing tables ID.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
},
"network_area_id": schema.StringAttribute{
Description: "The network area ID to which the routing table is associated.",
Required: true,
Validators: []validator.String{
validate.UUID(),
validate.NoSeparator(),
},
},
"region": schema.StringAttribute{
Description: "The resource region. If not defined, the provider region is used.",
Optional: true,
},
}
}
func RouteResponseAttributes() map[string]schema.Attribute {
return map[string]schema.Attribute{
"route_id": schema.StringAttribute{
Description: "Route ID.",
Computed: true,
},
"destination": schema.SingleNestedAttribute{
Description: "Destination of the route.",
Computed: true,
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Description: fmt.Sprintf("CIDRV type. %s %s", utils.FormatPossibleValues("cidrv4", "cidrv6"), "Only `cidrv4` is supported during experimental stage."),
Computed: true,
},
"value": schema.StringAttribute{
Description: "An CIDR string.",
Computed: true,
},
},
},
"next_hop": schema.SingleNestedAttribute{
Description: "Next hop destination.",
Computed: true,
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Description: fmt.Sprintf("%s %s.", utils.FormatPossibleValues("blackhole", "internet", "ipv4", "ipv6"), "Only `cidrv4` is supported during experimental stage."),
Computed: true,
},
"value": schema.StringAttribute{
Description: "Either IPv4 or IPv6 (not set for blackhole and internet). Only IPv4 supported during experimental stage.",
Computed: true,
},
},
},
"labels": schema.MapAttribute{
Description: "Labels are key-value string pairs which can be attached to a resource container",
ElementType: types.StringType,
Computed: true,
},
"created_at": schema.StringAttribute{
Description: "Date-time when the route was created",
Computed: true,
},
"updated_at": schema.StringAttribute{
Description: "Date-time when the route was updated",
Computed: true,
},
}
}
func RoutingTableResponseAttributes() map[string]schema.Attribute {
return map[string]schema.Attribute{
"routing_table_id": schema.StringAttribute{
Description: "The routing tables ID.",
Computed: true,
},
"name": schema.StringAttribute{
Description: "The name of the routing table.",
Computed: true,
},
"description": schema.StringAttribute{
Description: "Description of the routing table.",
Computed: true,
},
"labels": schema.MapAttribute{
Description: "Labels are key-value string pairs which can be attached to a resource container",
ElementType: types.StringType,
Computed: true,
},
"default": schema.BoolAttribute{
Description: "When true this is the default routing table for this network area. It can't be deleted and is used if the user does not specify it otherwise.",
Computed: true,
},
"system_routes": schema.BoolAttribute{
Computed: true,
},
"created_at": schema.StringAttribute{
Description: "Date-time when the routing table was created",
Computed: true,
},
"updated_at": schema.StringAttribute{
Description: "Date-time when the routing table was updated",
Computed: true,
},
}
}
func MapRoutingTableReadModel(ctx context.Context, routingTable *iaasalpha.RoutingTable, model *RoutingTableReadModel) error {
if routingTable == nil {
return fmt.Errorf("response input is nil")
}
if model == nil {
return fmt.Errorf("model input is nil")
}
var routingTableId string
if model.RoutingTableId.ValueString() != "" {
routingTableId = model.RoutingTableId.ValueString()
} else if routingTable.Id != nil {
routingTableId = *routingTable.Id
} else {
return fmt.Errorf("routing table id not present")
}
labels, err := iaasUtils.MapLabels(ctx, routingTable.Labels, model.Labels)
if err != nil {
return err
}
// created at and updated at
createdAtTF, updatedAtTF := types.StringNull(), types.StringNull()
if routingTable.CreatedAt != nil {
createdAtValue := *routingTable.CreatedAt
createdAtTF = types.StringValue(createdAtValue.Format(time.RFC3339))
}
if routingTable.UpdatedAt != nil {
updatedAtValue := *routingTable.UpdatedAt
updatedAtTF = types.StringValue(updatedAtValue.Format(time.RFC3339))
}
model.RoutingTableId = types.StringValue(routingTableId)
model.Name = types.StringPointerValue(routingTable.Name)
model.Description = types.StringPointerValue(routingTable.Description)
model.Default = types.BoolPointerValue(routingTable.Default)
model.SystemRoutes = types.BoolPointerValue(routingTable.SystemRoutes)
model.Labels = labels
model.CreatedAt = createdAtTF
model.UpdatedAt = updatedAtTF
return nil
}