diff --git a/examples/data-sources/meraki_networks_appliance_static_routes/data-source.tf b/examples/data-sources/meraki_networks_appliance_static_routes/data-source.tf new file mode 100644 index 0000000..2c6d188 --- /dev/null +++ b/examples/data-sources/meraki_networks_appliance_static_routes/data-source.tf @@ -0,0 +1,18 @@ + +data "meraki_networks_appliance_static_routes" "example" { + provider = meraki + network_id = "string" +} + +output "meraki_networks_appliance_static_routes_example" { + value = data.meraki_networks_appliance_static_routes.example.items +} + +data "meraki_networks_appliance_static_routes" "example" { + provider = meraki + network_id = "string" +} + +output "meraki_networks_appliance_static_routes_example" { + value = data.meraki_networks_appliance_static_routes.example.item +} diff --git a/examples/resources/meraki_networks_appliance_static_routes/import.sh b/examples/resources/meraki_networks_appliance_static_routes/import.sh new file mode 100644 index 0000000..31b5441 --- /dev/null +++ b/examples/resources/meraki_networks_appliance_static_routes/import.sh @@ -0,0 +1 @@ +terraform import meraki_networks_appliance_static_routes.example "network_id,static_route_id" \ No newline at end of file diff --git a/examples/resources/meraki_networks_appliance_static_routes/resource.tf b/examples/resources/meraki_networks_appliance_static_routes/resource.tf new file mode 100644 index 0000000..3ec13d0 --- /dev/null +++ b/examples/resources/meraki_networks_appliance_static_routes/resource.tf @@ -0,0 +1,12 @@ + +resource "meraki_networks_appliance_static_routes" "example" { + provider = meraki + gateway_ip = "1.2.3.5" + name = "My route" + network_id = "string" + subnet = "192.168.1.0/24" +} + +output "meraki_networks_appliance_static_routes_example" { + value = meraki_networks_appliance_static_routes.example +} \ No newline at end of file diff --git a/examples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf b/examples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf index fc949cd..c180edb 100644 --- a/examples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf +++ b/examples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf @@ -9,13 +9,13 @@ resource "meraki_networks_appliance_traffic_shaping_rules" "example" { type = "host" value = "google.com" #if type is ('host', 'port', 'ipRange' or 'localNet') - }, - { - type = "host" - value_obj ={ - id= "string" - name= "string" - }# if type is ('application' or 'applicationCategory') + }, + { + type = "host" + value_obj = { + id = "string" + name = "string" + } # if type is ('application' or 'applicationCategory') }] dscp_tag_value = 1 per_client_bandwidth_limits = { diff --git a/examples/samples/data_sources/meraki_organizations_appliance_vpn_third_party_vpnpeers/data-source.tf b/examples/samples/data_sources/meraki_organizations_appliance_vpn_third_party_vpnpeers/data-source.tf index ec1201e..8fa88b2 100644 --- a/examples/samples/data_sources/meraki_organizations_appliance_vpn_third_party_vpnpeers/data-source.tf +++ b/examples/samples/data_sources/meraki_organizations_appliance_vpn_third_party_vpnpeers/data-source.tf @@ -9,7 +9,7 @@ terraform { provider "meraki" { - meraki_debug = "true" + meraki_debug = "true" meraki_base_url = "http://localhost:3001" } diff --git a/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf b/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf index 2a6771f..e50818f 100644 --- a/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf +++ b/examples/samples/data_sources/meraki_organizations_policy_objects_groups/data-source.tf @@ -11,7 +11,7 @@ data "meraki_organizations_policy_objects_groups" "example" { # ending_before = "string" # organization_id = "string" - per_page = 1 + per_page = 1 # starting_after = "string" } diff --git a/examples/samples/resources/example/main.tf b/examples/samples/resources/example/main.tf index 9e2a7af..de52590 100644 --- a/examples/samples/resources/example/main.tf +++ b/examples/samples/resources/example/main.tf @@ -19,7 +19,7 @@ resource "meraki_networks_wireless_ssids_firewall_l3_firewall_rules" "test-Terra dest_port = "any" policy = "allow" protocol = "any" - ip_ver = "ipv4" + ip_ver = "ipv4" }, { # comment = "" @@ -27,7 +27,7 @@ resource "meraki_networks_wireless_ssids_firewall_l3_firewall_rules" "test-Terra dest_port = "any" policy = "deny" protocol = "any" - ip_ver = "ipv4" + ip_ver = "ipv4" }, { # comment = "" @@ -35,7 +35,7 @@ resource "meraki_networks_wireless_ssids_firewall_l3_firewall_rules" "test-Terra dest_port = "any" policy = "deny" protocol = "any" - ip_ver = "ipv4" + ip_ver = "ipv4" }, { # comment = "" @@ -43,7 +43,7 @@ resource "meraki_networks_wireless_ssids_firewall_l3_firewall_rules" "test-Terra dest_port = "any" policy = "deny" protocol = "any" - ip_ver = "ipv4" + ip_ver = "ipv4" } ] } diff --git a/examples/samples/resources/meraki_networks_appliance_static_routes/import.sh b/examples/samples/resources/meraki_networks_appliance_static_routes/import.sh new file mode 100644 index 0000000..31b5441 --- /dev/null +++ b/examples/samples/resources/meraki_networks_appliance_static_routes/import.sh @@ -0,0 +1 @@ +terraform import meraki_networks_appliance_static_routes.example "network_id,static_route_id" \ No newline at end of file diff --git a/examples/samples/resources/meraki_networks_appliance_static_routes/resource.tf b/examples/samples/resources/meraki_networks_appliance_static_routes/resource.tf new file mode 100644 index 0000000..3ec13d0 --- /dev/null +++ b/examples/samples/resources/meraki_networks_appliance_static_routes/resource.tf @@ -0,0 +1,12 @@ + +resource "meraki_networks_appliance_static_routes" "example" { + provider = meraki + gateway_ip = "1.2.3.5" + name = "My route" + network_id = "string" + subnet = "192.168.1.0/24" +} + +output "meraki_networks_appliance_static_routes_example" { + value = meraki_networks_appliance_static_routes.example +} \ No newline at end of file diff --git a/examples/samples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf b/examples/samples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf index a1274a6..8826cbf 100644 --- a/examples/samples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf +++ b/examples/samples/resources/meraki_networks_appliance_traffic_shaping_rules/resource.tf @@ -17,7 +17,7 @@ provider "meraki" { resource "meraki_networks_appliance_traffic_shaping_rules" "example" { default_rules_enabled = true network_id = "L_828099381482775486" - + rules = [{ definitions = [ { @@ -40,7 +40,7 @@ resource "meraki_networks_appliance_traffic_shaping_rules" "example" { settings = "custom" } priority = "high" - }, { + }, { definitions = [ { type = "host" diff --git a/examples/samples/resources/meraki_organizations_admins/resource.tf b/examples/samples/resources/meraki_organizations_admins/resource.tf index 06ae03b..b19fb57 100644 --- a/examples/samples/resources/meraki_organizations_admins/resource.tf +++ b/examples/samples/resources/meraki_organizations_admins/resource.tf @@ -5,11 +5,11 @@ terraform { source = "hashicorp.com/edu/meraki" } } - } +} provider "meraki" { - meraki_debug = "true" + meraki_debug = "true" meraki_base_url = "http://localhost:3001" } diff --git a/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf b/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf index 3f11e15..15ac287 100644 --- a/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf +++ b/examples/samples/resources/meraki_organizations_policy_objects_groups/resource.tf @@ -5,7 +5,7 @@ terraform { source = "hashicorp.com/edu/meraki" } } - } +} provider "meraki" { meraki_debug = "true" diff --git a/internal/provider/data_source_meraki_networks_appliance_static_routes.go b/internal/provider/data_source_meraki_networks_appliance_static_routes.go new file mode 100644 index 0000000..b505a0c --- /dev/null +++ b/internal/provider/data_source_meraki_networks_appliance_static_routes.go @@ -0,0 +1,447 @@ +package provider + +// DATA SOURCE NORMAL +import ( + "context" + "log" + + merakigosdk "github.com/meraki/dashboard-api-go/v3/sdk" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var ( + _ datasource.DataSource = &NetworksApplianceStaticRoutesDataSource{} + _ datasource.DataSourceWithConfigure = &NetworksApplianceStaticRoutesDataSource{} +) + +func NewNetworksApplianceStaticRoutesDataSource() datasource.DataSource { + return &NetworksApplianceStaticRoutesDataSource{} +} + +type NetworksApplianceStaticRoutesDataSource struct { + client *merakigosdk.Client +} + +func (d *NetworksApplianceStaticRoutesDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + client := req.ProviderData.(MerakiProviderData).Client + d.client = client +} + +// Metadata returns the data source type name. +func (d *NetworksApplianceStaticRoutesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_networks_appliance_static_routes" +} + +func (d *NetworksApplianceStaticRoutesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "network_id": schema.StringAttribute{ + MarkdownDescription: `networkId path parameter. Network ID`, + Optional: true, + }, + "static_route_id": schema.StringAttribute{ + MarkdownDescription: `staticRouteId path parameter. Static route ID`, + Optional: true, + }, + "item": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "enabled": schema.BoolAttribute{ + Computed: true, + }, + "fixed_ip_assignments": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "attribute_22_33_44_55_66_77": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "ip": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + "gateway_ip": schema.StringAttribute{ + Computed: true, + }, + "gateway_vlan_id": schema.Int64Attribute{ + Computed: true, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + "ip_version": schema.Int64Attribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + "network_id": schema.StringAttribute{ + Computed: true, + }, + "reserved_ip_ranges": schema.SetNestedAttribute{ + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + + "comment": schema.StringAttribute{ + Computed: true, + }, + "end": schema.StringAttribute{ + Computed: true, + }, + "start": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "subnet": schema.StringAttribute{ + Computed: true, + }, + }, + }, + + "items": schema.ListNestedAttribute{ + MarkdownDescription: `Array of ResponseApplianceGetNetworkApplianceStaticRoutes`, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + + "enabled": schema.BoolAttribute{ + Computed: true, + }, + "fixed_ip_assignments": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "attribute_22_33_44_55_66_77": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "ip": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + "gateway_ip": schema.StringAttribute{ + Computed: true, + }, + "gateway_vlan_id": schema.Int64Attribute{ + Computed: true, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + "ip_version": schema.Int64Attribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + "network_id": schema.StringAttribute{ + Computed: true, + }, + "reserved_ip_ranges": schema.SetNestedAttribute{ + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + + "comment": schema.StringAttribute{ + Computed: true, + }, + "end": schema.StringAttribute{ + Computed: true, + }, + "start": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + "subnet": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *NetworksApplianceStaticRoutesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var networksApplianceStaticRoutes NetworksApplianceStaticRoutes + diags := req.Config.Get(ctx, &networksApplianceStaticRoutes) + if resp.Diagnostics.HasError() { + return + } + + method1 := []bool{!networksApplianceStaticRoutes.NetworkID.IsNull()} + log.Printf("[DEBUG] Selecting method. Method 1 %v", method1) + method2 := []bool{!networksApplianceStaticRoutes.NetworkID.IsNull(), !networksApplianceStaticRoutes.StaticRouteID.IsNull()} + log.Printf("[DEBUG] Selecting method. Method 2 %v", method2) + + selectedMethod := pickMethod([][]bool{method1, method2}) + if selectedMethod == 1 { + log.Printf("[DEBUG] Selected method: GetNetworkApplianceStaticRoutes") + vvNetworkID := networksApplianceStaticRoutes.NetworkID.ValueString() + + // has_unknown_response: None + + response1, restyResp1, err := d.client.Appliance.GetNetworkApplianceStaticRoutes(vvNetworkID) + + if err != nil || response1 == nil { + if restyResp1 != nil { + log.Printf("[DEBUG] Retrieved error response %s", restyResp1.String()) + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoutes", + err.Error(), + ) + return + } + + networksApplianceStaticRoutes = ResponseApplianceGetNetworkApplianceStaticRoutesItemsToBody(networksApplianceStaticRoutes, response1) + diags = resp.State.Set(ctx, &networksApplianceStaticRoutes) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + } + if selectedMethod == 2 { + log.Printf("[DEBUG] Selected method: GetNetworkApplianceStaticRoute") + vvNetworkID := networksApplianceStaticRoutes.NetworkID.ValueString() + vvStaticRouteID := networksApplianceStaticRoutes.StaticRouteID.ValueString() + + // has_unknown_response: None + + response2, restyResp2, err := d.client.Appliance.GetNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID) + + if err != nil || response2 == nil { + if restyResp2 != nil { + log.Printf("[DEBUG] Retrieved error response %s", restyResp2.String()) + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + + networksApplianceStaticRoutes = ResponseApplianceGetNetworkApplianceStaticRouteItemToBody(networksApplianceStaticRoutes, response2) + diags = resp.State.Set(ctx, &networksApplianceStaticRoutes) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + } +} + +// structs +type NetworksApplianceStaticRoutes struct { + NetworkID types.String `tfsdk:"network_id"` + StaticRouteID types.String `tfsdk:"static_route_id"` + Items *[]ResponseItemApplianceGetNetworkApplianceStaticRoutes `tfsdk:"items"` + Item *ResponseApplianceGetNetworkApplianceStaticRoute `tfsdk:"item"` +} + +type ResponseItemApplianceGetNetworkApplianceStaticRoutes struct { + Enabled types.Bool `tfsdk:"enabled"` + FixedIPAssignments *ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments `tfsdk:"fixed_ip_assignments"` + GatewayIP types.String `tfsdk:"gateway_ip"` + GatewayVLANID types.Int64 `tfsdk:"gateway_vlan_id"` + ID types.String `tfsdk:"id"` + IPVersion types.Int64 `tfsdk:"ip_version"` + Name types.String `tfsdk:"name"` + NetworkID types.String `tfsdk:"network_id"` + ReservedIPRanges *[]ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges `tfsdk:"reserved_ip_ranges"` + Subnet types.String `tfsdk:"subnet"` +} + +type ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments struct { + Status223344556677 *ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments223344556677 `tfsdk:"attribute_22_33_44_55_66_77"` +} + +type ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments223344556677 struct { + IP types.String `tfsdk:"ip"` + Name types.String `tfsdk:"name"` +} + +type ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges struct { + Comment types.String `tfsdk:"comment"` + End types.String `tfsdk:"end"` + Start types.String `tfsdk:"start"` +} + +type ResponseApplianceGetNetworkApplianceStaticRoute struct { + Enabled types.Bool `tfsdk:"enabled"` + FixedIPAssignments *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments `tfsdk:"fixed_ip_assignments"` + GatewayIP types.String `tfsdk:"gateway_ip"` + GatewayVLANID types.Int64 `tfsdk:"gateway_vlan_id"` + ID types.String `tfsdk:"id"` + IPVersion types.Int64 `tfsdk:"ip_version"` + Name types.String `tfsdk:"name"` + NetworkID types.String `tfsdk:"network_id"` + ReservedIPRanges *[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges `tfsdk:"reserved_ip_ranges"` + Subnet types.String `tfsdk:"subnet"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments struct { + Status223344556677 *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677 `tfsdk:"attribute_22_33_44_55_66_77"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677 struct { + IP types.String `tfsdk:"ip"` + Name types.String `tfsdk:"name"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges struct { + Comment types.String `tfsdk:"comment"` + End types.String `tfsdk:"end"` + Start types.String `tfsdk:"start"` +} + +// ToBody +func ResponseApplianceGetNetworkApplianceStaticRoutesItemsToBody(state NetworksApplianceStaticRoutes, response *merakigosdk.ResponseApplianceGetNetworkApplianceStaticRoutes) NetworksApplianceStaticRoutes { + var items []ResponseItemApplianceGetNetworkApplianceStaticRoutes + for _, item := range *response { + itemState := ResponseItemApplianceGetNetworkApplianceStaticRoutes{ + Enabled: func() types.Bool { + if item.Enabled != nil { + return types.BoolValue(*item.Enabled) + } + return types.Bool{} + }(), + FixedIPAssignments: func() *ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments { + if item.FixedIPAssignments != nil { + return &ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments{ + Status223344556677: func() *ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments223344556677 { + if item.FixedIPAssignments.Status223344556677 != nil { + return &ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments223344556677{ + IP: types.StringValue(item.FixedIPAssignments.Status223344556677.IP), + Name: types.StringValue(item.FixedIPAssignments.Status223344556677.Name), + } + } + return &ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments223344556677{} + }(), + } + } + return &ResponseItemApplianceGetNetworkApplianceStaticRoutesFixedIpAssignments{} + }(), + GatewayIP: types.StringValue(item.GatewayIP), + GatewayVLANID: func() types.Int64 { + if item.GatewayVLANID != nil { + return types.Int64Value(int64(*item.GatewayVLANID)) + } + return types.Int64{} + }(), + ID: types.StringValue(item.ID), + IPVersion: func() types.Int64 { + if item.IPVersion != nil { + return types.Int64Value(int64(*item.IPVersion)) + } + return types.Int64{} + }(), + Name: types.StringValue(item.Name), + NetworkID: types.StringValue(item.NetworkID), + ReservedIPRanges: func() *[]ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges { + if item.ReservedIPRanges != nil { + result := make([]ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges, len(*item.ReservedIPRanges)) + for i, reservedIPRanges := range *item.ReservedIPRanges { + result[i] = ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges{ + Comment: types.StringValue(reservedIPRanges.Comment), + End: types.StringValue(reservedIPRanges.End), + Start: types.StringValue(reservedIPRanges.Start), + } + } + return &result + } + return &[]ResponseItemApplianceGetNetworkApplianceStaticRoutesReservedIpRanges{} + }(), + Subnet: types.StringValue(item.Subnet), + } + items = append(items, itemState) + } + state.Items = &items + return state +} + +func ResponseApplianceGetNetworkApplianceStaticRouteItemToBody(state NetworksApplianceStaticRoutes, response *merakigosdk.ResponseApplianceGetNetworkApplianceStaticRoute) NetworksApplianceStaticRoutes { + itemState := ResponseApplianceGetNetworkApplianceStaticRoute{ + Enabled: func() types.Bool { + if response.Enabled != nil { + return types.BoolValue(*response.Enabled) + } + return types.Bool{} + }(), + FixedIPAssignments: func() *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments { + if response.FixedIPAssignments != nil { + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments{ + Status223344556677: func() *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677 { + if response.FixedIPAssignments.Status223344556677 != nil { + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677{ + IP: types.StringValue(response.FixedIPAssignments.Status223344556677.IP), + Name: types.StringValue(response.FixedIPAssignments.Status223344556677.Name), + } + } + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677{} + }(), + } + } + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments{} + }(), + GatewayIP: types.StringValue(response.GatewayIP), + GatewayVLANID: func() types.Int64 { + if response.GatewayVLANID != nil { + return types.Int64Value(int64(*response.GatewayVLANID)) + } + return types.Int64{} + }(), + ID: types.StringValue(response.ID), + IPVersion: func() types.Int64 { + if response.IPVersion != nil { + return types.Int64Value(int64(*response.IPVersion)) + } + return types.Int64{} + }(), + Name: types.StringValue(response.Name), + NetworkID: types.StringValue(response.NetworkID), + ReservedIPRanges: func() *[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges { + if response.ReservedIPRanges != nil { + result := make([]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges, len(*response.ReservedIPRanges)) + for i, reservedIPRanges := range *response.ReservedIPRanges { + result[i] = ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges{ + Comment: types.StringValue(reservedIPRanges.Comment), + End: types.StringValue(reservedIPRanges.End), + Start: types.StringValue(reservedIPRanges.Start), + } + } + return &result + } + return &[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRanges{} + }(), + Subnet: types.StringValue(response.Subnet), + } + state.Item = &itemState + return state +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 3ee49af..39bd4ae 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -181,6 +181,7 @@ func New(version string) func() provider.Provider { func (p *MerakiProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ + NewNetworksApplianceStaticRoutesResource, NewOrganizationsResource, NewOrganizationsAdminsResource, NewDevicesResource, @@ -392,6 +393,7 @@ func (p *MerakiProvider) Resources(ctx context.Context) []func() resource.Resour func (p *MerakiProvider) DataSources(ctx context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ + NewNetworksApplianceStaticRoutesDataSource, NewOrganizationsDataSource, NewOrganizationsAdminsDataSource, NewAdministeredIDentitiesMeDataSource, diff --git a/internal/provider/resource_meraki_networks_appliance_static_routes.go b/internal/provider/resource_meraki_networks_appliance_static_routes.go new file mode 100644 index 0000000..5317602 --- /dev/null +++ b/internal/provider/resource_meraki_networks_appliance_static_routes.go @@ -0,0 +1,626 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 +package provider + +// RESOURCE NORMAL +import ( + "context" + + merakigosdk "github.com/meraki/dashboard-api-go/v3/sdk" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +var ( + _ resource.Resource = &NetworksApplianceStaticRoutesResource{} + _ resource.ResourceWithConfigure = &NetworksApplianceStaticRoutesResource{} +) + +func NewNetworksApplianceStaticRoutesResource() resource.Resource { + return &NetworksApplianceStaticRoutesResource{} +} + +type NetworksApplianceStaticRoutesResource struct { + client *merakigosdk.Client +} + +func (r *NetworksApplianceStaticRoutesResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + client := req.ProviderData.(MerakiProviderData).Client + r.client = client +} + +// Metadata returns the data source type name. +func (r *NetworksApplianceStaticRoutesResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_networks_appliance_static_routes" +} + +func (r *NetworksApplianceStaticRoutesResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "enabled": schema.BoolAttribute{ + MarkdownDescription: `The enabled state of the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.UseStateForUnknown(), + }, + }, + "fixed_ip_assignments": schema.SingleNestedAttribute{ + MarkdownDescription: `The DHCP fixed IP assignments on the static route. This should be an object that contains mappings from MAC addresses to objects that themselves each contain "ip" and "name" string fields. See the sample request/response for more details.`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.Object{ + objectplanmodifier.UseStateForUnknown(), + }, + Attributes: map[string]schema.Attribute{ + + "attribute_22_33_44_55_66_77": schema.SingleNestedAttribute{ + Computed: true, + Attributes: map[string]schema.Attribute{ + + "ip": schema.StringAttribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + Computed: true, + }, + }, + }, + }, + }, + "gateway_ip": schema.StringAttribute{ + MarkdownDescription: `The gateway IP (next hop) of the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "gateway_vlan_id": schema.Int64Attribute{ + MarkdownDescription: `The gateway IP (next hop) VLAN ID of the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + // Differents_types: ` parameter: schema.TypeString, item: schema.TypeInt`, + }, + "gateway_vlan_id_rs": schema.StringAttribute{ + MarkdownDescription: `The gateway IP (next hop) VLAN ID of the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + // Differents_types: ` parameter: schema.TypeString, item: schema.TypeInt`, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + "ip_version": schema.Int64Attribute{ + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: `The name of the new static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "network_id": schema.StringAttribute{ + MarkdownDescription: `networkId path parameter. Network ID`, + Required: true, + }, + "reserved_ip_ranges": schema.SetNestedAttribute{ + MarkdownDescription: `The DHCP reserved IP ranges on the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + + "comment": schema.StringAttribute{ + MarkdownDescription: `A text comment for the reserved range`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "end": schema.StringAttribute{ + MarkdownDescription: `The last IP in the reserved range`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "start": schema.StringAttribute{ + MarkdownDescription: `The first IP in the reserved range`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + }, + }, + "static_route_id": schema.StringAttribute{ + MarkdownDescription: `staticRouteId path parameter. Static route ID`, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "subnet": schema.StringAttribute{ + MarkdownDescription: `The subnet of the static route`, + Computed: true, + Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + }, + } +} + +//path params to set ['staticRouteId'] + +func (r *NetworksApplianceStaticRoutesResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Retrieve values from plan + var data NetworksApplianceStaticRoutesRs + + var item types.Object + resp.Diagnostics.Append(req.Plan.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + //Has Paths + vvNetworkID := data.NetworkID.ValueString() + vvName := data.Name.ValueString() + //Items + responseVerifyItem, restyResp1, err := r.client.Appliance.GetNetworkApplianceStaticRoutes(vvNetworkID) + //Have Create + if err != nil || restyResp1 == nil { + if restyResp1.StatusCode() != 404 { + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoutes", + err.Error(), + ) + return + } + } + if responseVerifyItem != nil { + responseStruct := structToMap(responseVerifyItem) + result := getDictResult(responseStruct, "Name", vvName, simpleCmp) + if result != nil { + result2 := result.(map[string]interface{}) + vvStaticRouteID := result2["ID"].(string) + r.client.Appliance.UpdateNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID, data.toSdkApiRequestUpdate(ctx)) + responseVerifyItem2, _, _ := r.client.Appliance.GetNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID) + if responseVerifyItem2 != nil { + data = ResponseApplianceGetNetworkApplianceStaticRouteItemToBodyRs(data, responseVerifyItem2, false) + // Path params update assigned + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + return + } + } + } + dataRequest := data.toSdkApiRequestCreate(ctx) + restyResp2, err := r.client.Appliance.CreateNetworkApplianceStaticRoute(vvNetworkID, dataRequest) + + if err != nil || restyResp2 == nil { + if restyResp1 != nil { + resp.Diagnostics.AddError( + "Failure when executing CreateNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + resp.Diagnostics.AddError( + "Failure when executing CreateNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + //Items + responseGet, restyResp1, err := r.client.Appliance.GetNetworkApplianceStaticRoutes(vvNetworkID) + // Has item and has items + + if err != nil || responseGet == nil { + if restyResp1 != nil { + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoutes", + err.Error(), + ) + return + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoutes", + err.Error(), + ) + return + } + responseStruct := structToMap(responseGet) + result := getDictResult(responseStruct, "Name", vvName, simpleCmp) + if result != nil { + result2 := result.(map[string]interface{}) + vvStaticRouteID := result2["ID"].(string) + responseVerifyItem2, restyRespGet, err := r.client.Appliance.GetNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID) + if responseVerifyItem2 != nil && err == nil { + data3 := ResponseApplianceGetNetworkApplianceStaticRouteItemToBodyRs(data, responseVerifyItem2, false) + resp.Diagnostics.Append(resp.State.Set(ctx, &data3)...) + return + } else { + if restyRespGet != nil { + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + } else { + resp.Diagnostics.AddError( + "Error in result.", + "Error in result.", + ) + return + } +} + +func (r *NetworksApplianceStaticRoutesResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var data NetworksApplianceStaticRoutesRs + + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &data, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + + if resp.Diagnostics.HasError() { + return + } + //Has Paths + // Has Item2 + + vvNetworkID := data.NetworkID.ValueString() + vvStaticRouteID := data.StaticRouteID.ValueString() + responseGet, restyRespGet, err := r.client.Appliance.GetNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID) + if err != nil || restyRespGet == nil { + if restyRespGet != nil { + if restyRespGet.StatusCode() == 404 { + resp.Diagnostics.AddWarning( + "Resource not found", + "Deleting resource", + ) + resp.State.RemoveResource(ctx) + return + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + resp.Diagnostics.AddError( + "Failure when executing GetNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + //entro aqui 2 + data = ResponseApplianceGetNetworkApplianceStaticRouteItemToBodyRs(data, responseGet, true) + diags := resp.State.Set(ctx, &data) + //update path params assigned + resp.Diagnostics.Append(diags...) +} + +func (r *NetworksApplianceStaticRoutesResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var data NetworksApplianceStaticRoutesRs + merge(ctx, req, resp, &data) + + if resp.Diagnostics.HasError() { + return + } + //Has Paths + //Update + + //Path Params + vvNetworkID := data.NetworkID.ValueString() + vvStaticRouteID := data.StaticRouteID.ValueString() + dataRequest := data.toSdkApiRequestUpdate(ctx) + restyResp2, err := r.client.Appliance.UpdateNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID, dataRequest) + if err != nil || restyResp2 == nil { + if restyResp2 != nil { + resp.Diagnostics.AddError( + "Failure when executing UpdateNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + resp.Diagnostics.AddError( + "Failure when executing UpdateNetworkApplianceStaticRoute", + err.Error(), + ) + return + } + resp.Diagnostics.Append(req.Plan.Set(ctx, &data)...) + diags := resp.State.Set(ctx, &data) + resp.Diagnostics.Append(diags...) +} + +func (r *NetworksApplianceStaticRoutesResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state NetworksApplianceStaticRoutesRs + var item types.Object + + resp.Diagnostics.Append(req.State.Get(ctx, &item)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(item.As(ctx, &state, basetypes.ObjectAsOptions{ + UnhandledNullAsEmpty: true, + UnhandledUnknownAsEmpty: true, + })...) + if resp.Diagnostics.HasError() { + return + } + + vvNetworkID := state.NetworkID.ValueString() + vvStaticRouteID := state.StaticRouteID.ValueString() + _, err := r.client.Appliance.DeleteNetworkApplianceStaticRoute(vvNetworkID, vvStaticRouteID) + if err != nil { + resp.Diagnostics.AddError( + "Failure when executing DeleteNetworkApplianceStaticRoute", err.Error()) + return + } + + resp.State.RemoveResource(ctx) + +} + +// TF Structs Schema +type NetworksApplianceStaticRoutesRs struct { + NetworkID types.String `tfsdk:"network_id"` + StaticRouteID types.String `tfsdk:"static_route_id"` + Enabled types.Bool `tfsdk:"enabled"` + FixedIPAssignments *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignmentsRs `tfsdk:"fixed_ip_assignments"` + GatewayIP types.String `tfsdk:"gateway_ip"` + GatewayVLANID types.Int64 `tfsdk:"gateway_vlan_id"` + GatewayVLANIDRs types.String `tfsdk:"gateway_vlan_id_rs"` + ID types.String `tfsdk:"id"` + IPVersion types.Int64 `tfsdk:"ip_version"` + Name types.String `tfsdk:"name"` + ReservedIPRanges *[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs `tfsdk:"reserved_ip_ranges"` + Subnet types.String `tfsdk:"subnet"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignmentsRs struct { + Status223344556677 *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677Rs `tfsdk:"attribute_22_33_44_55_66_77"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677Rs struct { + IP types.String `tfsdk:"ip"` + Name types.String `tfsdk:"name"` +} + +type ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs struct { + Comment types.String `tfsdk:"comment"` + End types.String `tfsdk:"end"` + Start types.String `tfsdk:"start"` +} + +// FromBody +func (r *NetworksApplianceStaticRoutesRs) toSdkApiRequestCreate(ctx context.Context) *merakigosdk.RequestApplianceCreateNetworkApplianceStaticRoute { + emptyString := "" + gatewayIP := new(string) + if !r.GatewayIP.IsUnknown() && !r.GatewayIP.IsNull() { + *gatewayIP = r.GatewayIP.ValueString() + } else { + gatewayIP = &emptyString + } + gatewayVLANID := new(string) + if !r.GatewayVLANID.IsUnknown() && !r.GatewayVLANID.IsNull() { + *gatewayVLANID = r.GatewayVLANIDRs.ValueString() + } else { + gatewayVLANID = &emptyString + } + name := new(string) + if !r.Name.IsUnknown() && !r.Name.IsNull() { + *name = r.Name.ValueString() + } else { + name = &emptyString + } + subnet := new(string) + if !r.Subnet.IsUnknown() && !r.Subnet.IsNull() { + *subnet = r.Subnet.ValueString() + } else { + subnet = &emptyString + } + out := merakigosdk.RequestApplianceCreateNetworkApplianceStaticRoute{ + GatewayIP: *gatewayIP, + GatewayVLANID: *gatewayVLANID, + Name: *name, + Subnet: *subnet, + } + return &out +} +func (r *NetworksApplianceStaticRoutesRs) toSdkApiRequestUpdate(ctx context.Context) *merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRoute { + emptyString := "" + enabled := new(bool) + if !r.Enabled.IsUnknown() && !r.Enabled.IsNull() { + *enabled = r.Enabled.ValueBool() + } else { + enabled = nil + } + // var requestApplianceUpdateNetworkApplianceStaticRouteFixedIPAssignments *merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRouteFixedIPAssignments + // if r.FixedIPAssignments != nil { + // requestApplianceUpdateNetworkApplianceStaticRouteFixedIPAssignments = &merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRouteFixedIPAssignments{} + // } + gatewayIP := new(string) + if !r.GatewayIP.IsUnknown() && !r.GatewayIP.IsNull() { + *gatewayIP = r.GatewayIP.ValueString() + } else { + gatewayIP = &emptyString + } + gatewayVLANID := new(string) + if !r.GatewayVLANIDRs.IsUnknown() && !r.GatewayVLANIDRs.IsNull() { + *gatewayVLANID = r.GatewayVLANIDRs.ValueString() + } else { + gatewayVLANID = &emptyString + } + name := new(string) + if !r.Name.IsUnknown() && !r.Name.IsNull() { + *name = r.Name.ValueString() + } else { + name = &emptyString + } + var requestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges []merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges + if r.ReservedIPRanges != nil { + for _, rItem1 := range *r.ReservedIPRanges { + comment := rItem1.Comment.ValueString() + end := rItem1.End.ValueString() + start := rItem1.Start.ValueString() + requestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges = append(requestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges, merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges{ + Comment: comment, + End: end, + Start: start, + }) + } + } + subnet := new(string) + if !r.Subnet.IsUnknown() && !r.Subnet.IsNull() { + *subnet = r.Subnet.ValueString() + } else { + subnet = &emptyString + } + out := merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRoute{ + Enabled: enabled, + // FixedIPAssignments: requestApplianceUpdateNetworkApplianceStaticRouteFixedIPAssignments, + GatewayIP: *gatewayIP, + GatewayVLANID: *gatewayVLANID, + Name: *name, + ReservedIPRanges: func() *[]merakigosdk.RequestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges { + if len(requestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges) > 0 { + return &requestApplianceUpdateNetworkApplianceStaticRouteReservedIPRanges + } + return nil + }(), + Subnet: *subnet, + } + return &out +} + +// From gosdk to TF Structs Schema +func ResponseApplianceGetNetworkApplianceStaticRouteItemToBodyRs(state NetworksApplianceStaticRoutesRs, response *merakigosdk.ResponseApplianceGetNetworkApplianceStaticRoute, is_read bool) NetworksApplianceStaticRoutesRs { + itemState := NetworksApplianceStaticRoutesRs{ + Enabled: func() types.Bool { + if response.Enabled != nil { + return types.BoolValue(*response.Enabled) + } + return types.Bool{} + }(), + FixedIPAssignments: func() *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignmentsRs { + if response.FixedIPAssignments != nil { + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignmentsRs{ + Status223344556677: func() *ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677Rs { + if response.FixedIPAssignments.Status223344556677 != nil { + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677Rs{ + IP: types.StringValue(response.FixedIPAssignments.Status223344556677.IP), + Name: types.StringValue(response.FixedIPAssignments.Status223344556677.Name), + } + } + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignments223344556677Rs{} + }(), + } + } + return &ResponseApplianceGetNetworkApplianceStaticRouteFixedIpAssignmentsRs{} + }(), + GatewayIP: types.StringValue(response.GatewayIP), + GatewayVLANID: func() types.Int64 { + if response.GatewayVLANID != nil { + return types.Int64Value(int64(*response.GatewayVLANID)) + } + return types.Int64{} + }(), + ID: types.StringValue(response.ID), + IPVersion: func() types.Int64 { + if response.IPVersion != nil { + return types.Int64Value(int64(*response.IPVersion)) + } + return types.Int64{} + }(), + Name: types.StringValue(response.Name), + NetworkID: types.StringValue(response.NetworkID), + ReservedIPRanges: func() *[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs { + if response.ReservedIPRanges != nil { + result := make([]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs, len(*response.ReservedIPRanges)) + for i, reservedIPRanges := range *response.ReservedIPRanges { + result[i] = ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs{ + Comment: types.StringValue(reservedIPRanges.Comment), + End: types.StringValue(reservedIPRanges.End), + Start: types.StringValue(reservedIPRanges.Start), + } + } + return &result + } + return &[]ResponseApplianceGetNetworkApplianceStaticRouteReservedIpRangesRs{} + }(), + Subnet: types.StringValue(response.Subnet), + } + if is_read { + return mergeInterfacesOnlyPath(state, itemState).(NetworksApplianceStaticRoutesRs) + } + return mergeInterfaces(state, itemState, true).(NetworksApplianceStaticRoutesRs) +}