From b72d75ff2feaf74c07b57558b9c69673ce8dc2a5 Mon Sep 17 00:00:00 2001 From: Sean Conroy <141843633+seconroy@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:16:58 +0000 Subject: [PATCH] Adds transport cellular controller and transport cellular profile features (#338) --- CHANGELOG.md | 2 + .../transport_cellular_controller_feature.md | 44 ++ .../transport_cellular_profile_feature.md | 49 +++ docs/guides/changelog.md | 2 + .../transport_cellular_controller_feature.md | 68 +++ .../transport_cellular_profile_feature.md | 75 ++++ .../data-source.tf | 4 + .../data-source.tf | 4 + .../import.sh | 3 + .../resource.tf | 10 + .../import.sh | 3 + .../resource.tf | 12 + .../transport_cellular_controller.yaml | 45 ++ .../transport_cellular_profile.yaml | 62 +++ gen/generator.go | 8 +- ...n_transport_cellular_controller_feature.go | 162 +++++++ ...nsport_cellular_controller_feature_test.go | 87 ++++ ...dwan_transport_cellular_profile_feature.go | 182 ++++++++ ...transport_cellular_profile_feature_test.go | 90 ++++ ...n_transport_cellular_controller_feature.go | 327 ++++++++++++++ ...dwan_transport_cellular_profile_feature.go | 403 ++++++++++++++++++ internal/provider/provider.go | 4 + ...n_transport_cellular_controller_feature.go | 305 +++++++++++++ ...nsport_cellular_controller_feature_test.go | 85 ++++ ...dwan_transport_cellular_profile_feature.go | 328 ++++++++++++++ ...transport_cellular_profile_feature_test.go | 88 ++++ templates/guides/changelog.md.tmpl | 2 + 27 files changed, 2451 insertions(+), 3 deletions(-) create mode 100644 docs/data-sources/transport_cellular_controller_feature.md create mode 100644 docs/data-sources/transport_cellular_profile_feature.md create mode 100644 docs/resources/transport_cellular_controller_feature.md create mode 100644 docs/resources/transport_cellular_profile_feature.md create mode 100644 examples/data-sources/sdwan_transport_cellular_controller_feature/data-source.tf create mode 100644 examples/data-sources/sdwan_transport_cellular_profile_feature/data-source.tf create mode 100644 examples/resources/sdwan_transport_cellular_controller_feature/import.sh create mode 100644 examples/resources/sdwan_transport_cellular_controller_feature/resource.tf create mode 100644 examples/resources/sdwan_transport_cellular_profile_feature/import.sh create mode 100644 examples/resources/sdwan_transport_cellular_profile_feature/resource.tf create mode 100644 gen/definitions/profile_parcels/transport_cellular_controller.yaml create mode 100644 gen/definitions/profile_parcels/transport_cellular_profile.yaml create mode 100644 internal/provider/data_source_sdwan_transport_cellular_controller_feature.go create mode 100644 internal/provider/data_source_sdwan_transport_cellular_controller_feature_test.go create mode 100644 internal/provider/data_source_sdwan_transport_cellular_profile_feature.go create mode 100644 internal/provider/data_source_sdwan_transport_cellular_profile_feature_test.go create mode 100644 internal/provider/model_sdwan_transport_cellular_controller_feature.go create mode 100644 internal/provider/model_sdwan_transport_cellular_profile_feature.go create mode 100644 internal/provider/resource_sdwan_transport_cellular_controller_feature.go create mode 100644 internal/provider/resource_sdwan_transport_cellular_controller_feature_test.go create mode 100644 internal/provider/resource_sdwan_transport_cellular_profile_feature.go create mode 100644 internal/provider/resource_sdwan_transport_cellular_profile_feature_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index c8aa1e36..e0dc8855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.5.1 (unreleased) - BREAKING CHANGE: Adds `gateway` attribute to `sdwan_transport_wan_vpn_feature` resource +- Add `sdwan_transport_cellular_controller_feature` resource and data source +- Add `sdwan_transport_cellular_profile_feature` resource and data source ## 0.5.0 diff --git a/docs/data-sources/transport_cellular_controller_feature.md b/docs/data-sources/transport_cellular_controller_feature.md new file mode 100644 index 00000000..c5abe43a --- /dev/null +++ b/docs/data-sources/transport_cellular_controller_feature.md @@ -0,0 +1,44 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_cellular_controller_feature Data Source - terraform-provider-sdwan" +subcategory: "Features" +description: |- + This data source can read the Transport Cellular Controller Feature. +--- + +# sdwan_transport_cellular_controller_feature (Data Source) + +This data source can read the Transport Cellular Controller Feature. + +## Example Usage + +```terraform +data "sdwan_transport_cellular_controller_feature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Feature + +### Read-Only + +- `cellular_id` (String) Cellular ID +- `cellular_id_variable` (String) Variable name +- `description` (String) The description of the Feature +- `firmware_auto_sim` (Boolean) Enable/Disable Firmware Auto Sim +- `firmware_auto_sim_variable` (String) Variable name +- `name` (String) The name of the Feature +- `primary_sim_slot` (Number) Set primary SIM slot +- `primary_sim_slot_variable` (String) Variable name +- `sim_failover_retries` (Number) Set SIM failover retries +- `sim_failover_retries_variable` (String) Variable name +- `sim_failover_timeout` (Number) Set SIM failover timeout in minutes +- `sim_failover_timeout_variable` (String) Variable name +- `version` (Number) The version of the Feature diff --git a/docs/data-sources/transport_cellular_profile_feature.md b/docs/data-sources/transport_cellular_profile_feature.md new file mode 100644 index 00000000..26c1417c --- /dev/null +++ b/docs/data-sources/transport_cellular_profile_feature.md @@ -0,0 +1,49 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_cellular_profile_feature Data Source - terraform-provider-sdwan" +subcategory: "Features" +description: |- + This data source can read the Transport Cellular Profile Feature. +--- + +# sdwan_transport_cellular_profile_feature (Data Source) + +This data source can read the Transport Cellular Profile Feature. + +## Example Usage + +```terraform +data "sdwan_transport_cellular_profile_feature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Feature + +### Read-Only + +- `access_point_name` (String) Set access point name +- `access_point_name_variable` (String) Variable name +- `authentication_type` (String) Set authentication type +- `authentication_type_variable` (String) Variable name +- `description` (String) The description of the Feature +- `name` (String) The name of the Feature +- `no_authentication` (String) No Authentication +- `no_overwrite` (Boolean) No Overwrite +- `no_overwrite_variable` (String) Variable name +- `packet_data_network_type` (String) Set packet data network type +- `packet_data_network_type_variable` (String) Variable name +- `profile_id` (Number) Set Profile ID +- `profile_id_variable` (String) Variable name +- `profile_password` (String) Set the profile password +- `profile_password_variable` (String) Variable name +- `profile_username` (String) Set the profile username +- `profile_username_variable` (String) Variable name +- `version` (Number) The version of the Feature diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index d4379422..5a6fc00b 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -10,6 +10,8 @@ description: |- ## 0.5.1 (unreleased) - BREAKING CHANGE: Adds `gateway` attribute to `sdwan_transport_wan_vpn_feature` resource +- Add `sdwan_transport_cellular_controller_feature` resource and data source +- Add `sdwan_transport_cellular_profile_feature` resource and data source ## 0.5.0 diff --git a/docs/resources/transport_cellular_controller_feature.md b/docs/resources/transport_cellular_controller_feature.md new file mode 100644 index 00000000..137f126a --- /dev/null +++ b/docs/resources/transport_cellular_controller_feature.md @@ -0,0 +1,68 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_cellular_controller_feature Resource - terraform-provider-sdwan" +subcategory: "Features" +description: |- + This resource can manage a Transport Cellular Controller Feature. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_transport_cellular_controller_feature (Resource) + +This resource can manage a Transport Cellular Controller Feature. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_transport_cellular_controller_feature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + cellular_id = "0/3/0" + primary_sim_slot = 0 + sim_failover_retries = 5 + sim_failover_timeout = 3 + firmware_auto_sim = true +} +``` + + +## Schema + +### Required + +- `cellular_id` (String) Cellular ID +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Feature + +### Optional + +- `cellular_id_variable` (String) Variable name +- `description` (String) The description of the Feature +- `firmware_auto_sim` (Boolean) Enable/Disable Firmware Auto Sim + - Default value: `true` +- `firmware_auto_sim_variable` (String) Variable name +- `primary_sim_slot` (Number) Set primary SIM slot + - Range: `0`-`1` +- `primary_sim_slot_variable` (String) Variable name +- `sim_failover_retries` (Number) Set SIM failover retries + - Range: `0`-`65535` +- `sim_failover_retries_variable` (String) Variable name +- `sim_failover_timeout` (Number) Set SIM failover timeout in minutes + - Range: `3`-`7` +- `sim_failover_timeout_variable` (String) Variable name + +### Read-Only + +- `id` (String) The id of the Feature +- `version` (Number) The version of the Feature + +## Import + +Import is supported using the following syntax: + +```shell +# Expected import identifier with the format: "transport_cellular_controller_feature_id,feature_profile_id" +terraform import sdwan_transport_cellular_controller_feature.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +``` diff --git a/docs/resources/transport_cellular_profile_feature.md b/docs/resources/transport_cellular_profile_feature.md new file mode 100644 index 00000000..c983c8b8 --- /dev/null +++ b/docs/resources/transport_cellular_profile_feature.md @@ -0,0 +1,75 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_cellular_profile_feature Resource - terraform-provider-sdwan" +subcategory: "Features" +description: |- + This resource can manage a Transport Cellular Profile Feature. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_transport_cellular_profile_feature (Resource) + +This resource can manage a Transport Cellular Profile Feature. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_transport_cellular_profile_feature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + profile_id = 1 + access_point_name = "apn1" + authentication_type = "pap" + profile_username = "example" + profile_password = "example123!" + packet_data_network_type = "ipv4" + no_overwrite = false +} +``` + + +## Schema + +### Required + +- `access_point_name` (String) Set access point name +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Feature +- `profile_id` (Number) Set Profile ID + - Range: `1`-`16` + +### Optional + +- `access_point_name_variable` (String) Variable name +- `authentication_type` (String) Set authentication type + - Choices: `pap`, `chap`, `pap_chap` +- `authentication_type_variable` (String) Variable name +- `description` (String) The description of the Feature +- `no_authentication` (String) No Authentication +- `no_overwrite` (Boolean) No Overwrite +- `no_overwrite_variable` (String) Variable name +- `packet_data_network_type` (String) Set packet data network type + - Choices: `ipv4`, `ipv4v6`, `ipv6` + - Default value: `ipv4` +- `packet_data_network_type_variable` (String) Variable name +- `profile_id_variable` (String) Variable name +- `profile_password` (String) Set the profile password +- `profile_password_variable` (String) Variable name +- `profile_username` (String) Set the profile username +- `profile_username_variable` (String) Variable name + +### Read-Only + +- `id` (String) The id of the Feature +- `version` (Number) The version of the Feature + +## Import + +Import is supported using the following syntax: + +```shell +# Expected import identifier with the format: "transport_cellular_profile_feature_id,feature_profile_id" +terraform import sdwan_transport_cellular_profile_feature.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +``` diff --git a/examples/data-sources/sdwan_transport_cellular_controller_feature/data-source.tf b/examples/data-sources/sdwan_transport_cellular_controller_feature/data-source.tf new file mode 100644 index 00000000..6d39e3b5 --- /dev/null +++ b/examples/data-sources/sdwan_transport_cellular_controller_feature/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_transport_cellular_controller_feature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_transport_cellular_profile_feature/data-source.tf b/examples/data-sources/sdwan_transport_cellular_profile_feature/data-source.tf new file mode 100644 index 00000000..9d54a60c --- /dev/null +++ b/examples/data-sources/sdwan_transport_cellular_profile_feature/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_transport_cellular_profile_feature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/resources/sdwan_transport_cellular_controller_feature/import.sh b/examples/resources/sdwan_transport_cellular_controller_feature/import.sh new file mode 100644 index 00000000..af82d4cc --- /dev/null +++ b/examples/resources/sdwan_transport_cellular_controller_feature/import.sh @@ -0,0 +1,3 @@ + +# Expected import identifier with the format: "transport_cellular_controller_feature_id,feature_profile_id" +terraform import sdwan_transport_cellular_controller_feature.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" diff --git a/examples/resources/sdwan_transport_cellular_controller_feature/resource.tf b/examples/resources/sdwan_transport_cellular_controller_feature/resource.tf new file mode 100644 index 00000000..df9adc21 --- /dev/null +++ b/examples/resources/sdwan_transport_cellular_controller_feature/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_transport_cellular_controller_feature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + cellular_id = "0/3/0" + primary_sim_slot = 0 + sim_failover_retries = 5 + sim_failover_timeout = 3 + firmware_auto_sim = true +} diff --git a/examples/resources/sdwan_transport_cellular_profile_feature/import.sh b/examples/resources/sdwan_transport_cellular_profile_feature/import.sh new file mode 100644 index 00000000..b4153001 --- /dev/null +++ b/examples/resources/sdwan_transport_cellular_profile_feature/import.sh @@ -0,0 +1,3 @@ + +# Expected import identifier with the format: "transport_cellular_profile_feature_id,feature_profile_id" +terraform import sdwan_transport_cellular_profile_feature.example "f6b2c44c-693c-4763-b010-895aa3d236bd,f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" diff --git a/examples/resources/sdwan_transport_cellular_profile_feature/resource.tf b/examples/resources/sdwan_transport_cellular_profile_feature/resource.tf new file mode 100644 index 00000000..da86331c --- /dev/null +++ b/examples/resources/sdwan_transport_cellular_profile_feature/resource.tf @@ -0,0 +1,12 @@ +resource "sdwan_transport_cellular_profile_feature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + profile_id = 1 + access_point_name = "apn1" + authentication_type = "pap" + profile_username = "example" + profile_password = "example123!" + packet_data_network_type = "ipv4" + no_overwrite = false +} diff --git a/gen/definitions/profile_parcels/transport_cellular_controller.yaml b/gen/definitions/profile_parcels/transport_cellular_controller.yaml new file mode 100644 index 00000000..52b86473 --- /dev/null +++ b/gen/definitions/profile_parcels/transport_cellular_controller.yaml @@ -0,0 +1,45 @@ +--- +name: Transport Cellular Controller +rest_endpoint: /v1/feature-profile/sdwan/transport/%v/cellular-controller +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +parcel_type: feature +skip_minimum_test: true +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_transport_feature_profile.test.id + - model_name: configType + type: String + example: non-eSim + - model_name: id + tf_name: cellular_id + data_path: [controllerConfig] + mandatory: true + example: 0/3/0 + - model_name: slot + tf_name: primary_sim_slot + data_path: [controllerConfig] + example: 0 + - model_name: maxRetry + tf_name: sim_failover_retries + data_path: [controllerConfig] + example: 5 + - model_name: failovertimer + tf_name: sim_failover_timeout + data_path: [controllerConfig] + example: 3 + - model_name: autoSim + tf_name: firmware_auto_sim + data_path: [controllerConfig] + example: true + +test_prerequisites: | + resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/transport_cellular_profile.yaml b/gen/definitions/profile_parcels/transport_cellular_profile.yaml new file mode 100644 index 00000000..da93d80a --- /dev/null +++ b/gen/definitions/profile_parcels/transport_cellular_profile.yaml @@ -0,0 +1,62 @@ +--- +name: Transport Cellular Profile +rest_endpoint: /v1/feature-profile/sdwan/transport/%v/cellular-profile +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +parcel_type: feature +skip_minimum_test: true +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_transport_feature_profile.test.id + - model_name: configType + type: String + example: non-eSim + - model_name: id + tf_name: profile_id + data_path: [profileConfig] + mandatory: true + example: 1 + - model_name: apn + tf_name: access_point_name + data_path: [profileConfig, profileInfo] + mandatory: true + example: apn1 + - model_name: noAuthentication + data_path: [profileConfig, profileInfo, authentication] + type: String + exclude_test: true + example: none + - model_name: type + tf_name: authentication_type + data_path: [profileConfig, profileInfo, authentication, needAuthentication] + type: String + example: pap + - model_name: username + tf_name: profile_username + data_path: [profileConfig, profileInfo, authentication, needAuthentication] + type: String + example: example + - model_name: password + tf_name: profile_password + data_path: [profileConfig, profileInfo, authentication, needAuthentication] + type: String + write_only: true + example: example123! + - model_name: pdnType + tf_name: packet_data_network_type + data_path: [profileConfig, profileInfo] + example: ipv4 + - model_name: noOverwrite + data_path: [profileConfig, profileInfo] + example: false + +test_prerequisites: | + resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" + } \ No newline at end of file diff --git a/gen/generator.go b/gen/generator.go index a9ca0917..34edf686 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -739,7 +739,6 @@ func parseProfileParcelAttribute(attr *YamlConfigAttribute, model gjson.Result, if attr.ModelName == "" { return } - path := "" prefix := "properties." for i, e := range attr.DataPath { @@ -953,9 +952,12 @@ func augmentProfileParcelConfig(config *YamlConfig) { model := gjson.ParseBytes(modelBytes) for ia := range config.Attributes { - parseProfileParcelAttribute(&config.Attributes[ia], model.Get("request.properties.data"), false) + if model.Get("request.properties.data.oneOf").Exists() { + parseProfileParcelAttribute(&config.Attributes[ia], model.Get("request.properties.data.oneOf.0"), false) + } else { + parseProfileParcelAttribute(&config.Attributes[ia], model.Get("request.properties.data"), false) + } } - if config.DsDescription == "" { config.DsDescription = fmt.Sprintf("This data source can read the %s %s.", config.Name, CamelCase(config.ParcelType)) } diff --git a/internal/provider/data_source_sdwan_transport_cellular_controller_feature.go b/internal/provider/data_source_sdwan_transport_cellular_controller_feature.go new file mode 100644 index 00000000..c76929df --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_cellular_controller_feature.go @@ -0,0 +1,162 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &TransportCellularControllerProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &TransportCellularControllerProfileParcelDataSource{} +) + +func NewTransportCellularControllerProfileParcelDataSource() datasource.DataSource { + return &TransportCellularControllerProfileParcelDataSource{} +} + +type TransportCellularControllerProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *TransportCellularControllerProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_cellular_controller_feature" +} + +func (d *TransportCellularControllerProfileParcelDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "This data source can read the Transport Cellular Controller Feature.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Feature", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Feature", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Feature", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Feature", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "cellular_id": schema.StringAttribute{ + MarkdownDescription: "Cellular ID", + Computed: true, + }, + "cellular_id_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "primary_sim_slot": schema.Int64Attribute{ + MarkdownDescription: "Set primary SIM slot", + Computed: true, + }, + "primary_sim_slot_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "sim_failover_retries": schema.Int64Attribute{ + MarkdownDescription: "Set SIM failover retries", + Computed: true, + }, + "sim_failover_retries_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "sim_failover_timeout": schema.Int64Attribute{ + MarkdownDescription: "Set SIM failover timeout in minutes", + Computed: true, + }, + "sim_failover_timeout_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "firmware_auto_sim": schema.BoolAttribute{ + MarkdownDescription: "Enable/Disable Firmware Auto Sim", + Computed: true, + }, + "firmware_auto_sim_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *TransportCellularControllerProfileParcelDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.client = req.ProviderData.(*SdwanProviderData).Client +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin read +func (d *TransportCellularControllerProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransportCellularController + + // Read config + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) + + res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString())) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + config.fromBody(ctx, res) + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString())) + + diags = resp.State.Set(ctx, &config) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end read diff --git a/internal/provider/data_source_sdwan_transport_cellular_controller_feature_test.go b/internal/provider/data_source_sdwan_transport_cellular_controller_feature_test.go new file mode 100644 index 00000000..ac8ff918 --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_cellular_controller_feature_test.go @@ -0,0 +1,87 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource +func TestAccDataSourceSdwanTransportCellularControllerProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_controller_feature.test", "cellular_id", "0/3/0")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_controller_feature.test", "primary_sim_slot", "0")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_controller_feature.test", "sim_failover_retries", "5")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_controller_feature.test", "sim_failover_timeout", "3")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_controller_feature.test", "firmware_auto_sim", "true")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanTransportCellularControllerPrerequisitesProfileParcelConfig + testAccDataSourceSdwanTransportCellularControllerProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanTransportCellularControllerPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanTransportCellularControllerProfileParcelConfig() string { + config := `resource "sdwan_transport_cellular_controller_feature" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id` + "\n" + config += ` cellular_id = "0/3/0"` + "\n" + config += ` primary_sim_slot = 0` + "\n" + config += ` sim_failover_retries = 5` + "\n" + config += ` sim_failover_timeout = 3` + "\n" + config += ` firmware_auto_sim = true` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_transport_cellular_controller_feature" "test" { + id = sdwan_transport_cellular_controller_feature.test.id + feature_profile_id = sdwan_transport_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_transport_cellular_profile_feature.go b/internal/provider/data_source_sdwan_transport_cellular_profile_feature.go new file mode 100644 index 00000000..a829b11a --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_cellular_profile_feature.go @@ -0,0 +1,182 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &TransportCellularProfileProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &TransportCellularProfileProfileParcelDataSource{} +) + +func NewTransportCellularProfileProfileParcelDataSource() datasource.DataSource { + return &TransportCellularProfileProfileParcelDataSource{} +} + +type TransportCellularProfileProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *TransportCellularProfileProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_cellular_profile_feature" +} + +func (d *TransportCellularProfileProfileParcelDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "This data source can read the Transport Cellular Profile Feature.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Feature", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Feature", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Feature", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Feature", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "profile_id": schema.Int64Attribute{ + MarkdownDescription: "Set Profile ID", + Computed: true, + }, + "profile_id_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "access_point_name": schema.StringAttribute{ + MarkdownDescription: "Set access point name", + Computed: true, + }, + "access_point_name_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "no_authentication": schema.StringAttribute{ + MarkdownDescription: "No Authentication", + Computed: true, + }, + "authentication_type": schema.StringAttribute{ + MarkdownDescription: "Set authentication type", + Computed: true, + }, + "authentication_type_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "profile_username": schema.StringAttribute{ + MarkdownDescription: "Set the profile username", + Computed: true, + }, + "profile_username_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "profile_password": schema.StringAttribute{ + MarkdownDescription: "Set the profile password", + Computed: true, + }, + "profile_password_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "packet_data_network_type": schema.StringAttribute{ + MarkdownDescription: "Set packet data network type", + Computed: true, + }, + "packet_data_network_type_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "no_overwrite": schema.BoolAttribute{ + MarkdownDescription: "No Overwrite", + Computed: true, + }, + "no_overwrite_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *TransportCellularProfileProfileParcelDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + d.client = req.ProviderData.(*SdwanProviderData).Client +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin read +func (d *TransportCellularProfileProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransportCellularProfile + + // Read config + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) + + res, err := d.client.Get(config.getPath() + "/" + url.QueryEscape(config.Id.ValueString())) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object, got error: %s", err)) + return + } + + config.fromBody(ctx, res) + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Name.ValueString())) + + diags = resp.State.Set(ctx, &config) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end read diff --git a/internal/provider/data_source_sdwan_transport_cellular_profile_feature_test.go b/internal/provider/data_source_sdwan_transport_cellular_profile_feature_test.go new file mode 100644 index 00000000..6dd34e2f --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_cellular_profile_feature_test.go @@ -0,0 +1,90 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource +func TestAccDataSourceSdwanTransportCellularProfileProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "profile_id", "1")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "access_point_name", "apn1")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "authentication_type", "pap")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "profile_username", "example")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "packet_data_network_type", "ipv4")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_cellular_profile_feature.test", "no_overwrite", "false")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanTransportCellularProfilePrerequisitesProfileParcelConfig + testAccDataSourceSdwanTransportCellularProfileProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanTransportCellularProfilePrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanTransportCellularProfileProfileParcelConfig() string { + config := `resource "sdwan_transport_cellular_profile_feature" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id` + "\n" + config += ` profile_id = 1` + "\n" + config += ` access_point_name = "apn1"` + "\n" + config += ` authentication_type = "pap"` + "\n" + config += ` profile_username = "example"` + "\n" + config += ` profile_password = "example123!"` + "\n" + config += ` packet_data_network_type = "ipv4"` + "\n" + config += ` no_overwrite = false` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_transport_cellular_profile_feature" "test" { + id = sdwan_transport_cellular_profile_feature.test.id + feature_profile_id = sdwan_transport_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/model_sdwan_transport_cellular_controller_feature.go b/internal/provider/model_sdwan_transport_cellular_controller_feature.go new file mode 100644 index 00000000..4b357ae1 --- /dev/null +++ b/internal/provider/model_sdwan_transport_cellular_controller_feature.go @@ -0,0 +1,327 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin types +type TransportCellularController struct { + Id types.String `tfsdk:"id"` + Version types.Int64 `tfsdk:"version"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + FeatureProfileId types.String `tfsdk:"feature_profile_id"` + CellularId types.String `tfsdk:"cellular_id"` + CellularIdVariable types.String `tfsdk:"cellular_id_variable"` + PrimarySimSlot types.Int64 `tfsdk:"primary_sim_slot"` + PrimarySimSlotVariable types.String `tfsdk:"primary_sim_slot_variable"` + SimFailoverRetries types.Int64 `tfsdk:"sim_failover_retries"` + SimFailoverRetriesVariable types.String `tfsdk:"sim_failover_retries_variable"` + SimFailoverTimeout types.Int64 `tfsdk:"sim_failover_timeout"` + SimFailoverTimeoutVariable types.String `tfsdk:"sim_failover_timeout_variable"` + FirmwareAutoSim types.Bool `tfsdk:"firmware_auto_sim"` + FirmwareAutoSimVariable types.String `tfsdk:"firmware_auto_sim_variable"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data TransportCellularController) getModel() string { + return "transport_cellular_controller" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data TransportCellularController) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/transport/%v/cellular-controller", url.QueryEscape(data.FeatureProfileId.ValueString())) +} + +// End of section. //template:end getPath + +// Section below is generated&owned by "gen/generator.go". //template:begin toBody +func (data TransportCellularController) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + body, _ = sjson.Set(body, path+"configType.optionType", "default") + body, _ = sjson.Set(body, path+"configType.value", "non-eSim") + } + + if !data.CellularIdVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.id.optionType", "variable") + body, _ = sjson.Set(body, path+"controllerConfig.id.value", data.CellularIdVariable.ValueString()) + } + } else if !data.CellularId.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.id.optionType", "global") + body, _ = sjson.Set(body, path+"controllerConfig.id.value", data.CellularId.ValueString()) + } + } + + if !data.PrimarySimSlotVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.slot.optionType", "variable") + body, _ = sjson.Set(body, path+"controllerConfig.slot.value", data.PrimarySimSlotVariable.ValueString()) + } + } else if data.PrimarySimSlot.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.slot.optionType", "default") + + } + } else { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.slot.optionType", "global") + body, _ = sjson.Set(body, path+"controllerConfig.slot.value", data.PrimarySimSlot.ValueInt64()) + } + } + + if !data.SimFailoverRetriesVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.maxRetry.optionType", "variable") + body, _ = sjson.Set(body, path+"controllerConfig.maxRetry.value", data.SimFailoverRetriesVariable.ValueString()) + } + } else if data.SimFailoverRetries.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.maxRetry.optionType", "default") + + } + } else { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.maxRetry.optionType", "global") + body, _ = sjson.Set(body, path+"controllerConfig.maxRetry.value", data.SimFailoverRetries.ValueInt64()) + } + } + + if !data.SimFailoverTimeoutVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.failovertimer.optionType", "variable") + body, _ = sjson.Set(body, path+"controllerConfig.failovertimer.value", data.SimFailoverTimeoutVariable.ValueString()) + } + } else if data.SimFailoverTimeout.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.failovertimer.optionType", "default") + + } + } else { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.failovertimer.optionType", "global") + body, _ = sjson.Set(body, path+"controllerConfig.failovertimer.value", data.SimFailoverTimeout.ValueInt64()) + } + } + + if !data.FirmwareAutoSimVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.optionType", "variable") + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.value", data.FirmwareAutoSimVariable.ValueString()) + } + } else if data.FirmwareAutoSim.IsNull() { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.optionType", "default") + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.value", true) + } + } else { + if true { + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.optionType", "global") + body, _ = sjson.Set(body, path+"controllerConfig.autoSim.value", data.FirmwareAutoSim.ValueBool()) + } + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *TransportCellularController) fromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + data.CellularId = types.StringNull() + data.CellularIdVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.id.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.id.value") + if t.String() == "variable" { + data.CellularIdVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.CellularId = types.StringValue(va.String()) + } + } + data.PrimarySimSlot = types.Int64Null() + data.PrimarySimSlotVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.slot.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.slot.value") + if t.String() == "variable" { + data.PrimarySimSlotVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.PrimarySimSlot = types.Int64Value(va.Int()) + } + } + data.SimFailoverRetries = types.Int64Null() + data.SimFailoverRetriesVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.maxRetry.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.maxRetry.value") + if t.String() == "variable" { + data.SimFailoverRetriesVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.SimFailoverRetries = types.Int64Value(va.Int()) + } + } + data.SimFailoverTimeout = types.Int64Null() + data.SimFailoverTimeoutVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.failovertimer.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.failovertimer.value") + if t.String() == "variable" { + data.SimFailoverTimeoutVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.SimFailoverTimeout = types.Int64Value(va.Int()) + } + } + data.FirmwareAutoSim = types.BoolNull() + data.FirmwareAutoSimVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.autoSim.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.autoSim.value") + if t.String() == "variable" { + data.FirmwareAutoSimVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.FirmwareAutoSim = types.BoolValue(va.Bool()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *TransportCellularController) updateFromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + data.CellularId = types.StringNull() + data.CellularIdVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.id.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.id.value") + if t.String() == "variable" { + data.CellularIdVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.CellularId = types.StringValue(va.String()) + } + } + data.PrimarySimSlot = types.Int64Null() + data.PrimarySimSlotVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.slot.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.slot.value") + if t.String() == "variable" { + data.PrimarySimSlotVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.PrimarySimSlot = types.Int64Value(va.Int()) + } + } + data.SimFailoverRetries = types.Int64Null() + data.SimFailoverRetriesVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.maxRetry.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.maxRetry.value") + if t.String() == "variable" { + data.SimFailoverRetriesVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.SimFailoverRetries = types.Int64Value(va.Int()) + } + } + data.SimFailoverTimeout = types.Int64Null() + data.SimFailoverTimeoutVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.failovertimer.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.failovertimer.value") + if t.String() == "variable" { + data.SimFailoverTimeoutVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.SimFailoverTimeout = types.Int64Value(va.Int()) + } + } + data.FirmwareAutoSim = types.BoolNull() + data.FirmwareAutoSimVariable = types.StringNull() + if t := res.Get(path + "controllerConfig.autoSim.optionType"); t.Exists() { + va := res.Get(path + "controllerConfig.autoSim.value") + if t.String() == "variable" { + data.FirmwareAutoSimVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.FirmwareAutoSim = types.BoolValue(va.Bool()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *TransportCellularController) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if !data.CellularId.IsNull() { + return false + } + if !data.CellularIdVariable.IsNull() { + return false + } + if !data.PrimarySimSlot.IsNull() { + return false + } + if !data.PrimarySimSlotVariable.IsNull() { + return false + } + if !data.SimFailoverRetries.IsNull() { + return false + } + if !data.SimFailoverRetriesVariable.IsNull() { + return false + } + if !data.SimFailoverTimeout.IsNull() { + return false + } + if !data.SimFailoverTimeoutVariable.IsNull() { + return false + } + if !data.FirmwareAutoSim.IsNull() { + return false + } + if !data.FirmwareAutoSimVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_transport_cellular_profile_feature.go b/internal/provider/model_sdwan_transport_cellular_profile_feature.go new file mode 100644 index 00000000..633a3135 --- /dev/null +++ b/internal/provider/model_sdwan_transport_cellular_profile_feature.go @@ -0,0 +1,403 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/tidwall/gjson" + "github.com/tidwall/sjson" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin types +type TransportCellularProfile struct { + Id types.String `tfsdk:"id"` + Version types.Int64 `tfsdk:"version"` + Name types.String `tfsdk:"name"` + Description types.String `tfsdk:"description"` + FeatureProfileId types.String `tfsdk:"feature_profile_id"` + ProfileId types.Int64 `tfsdk:"profile_id"` + ProfileIdVariable types.String `tfsdk:"profile_id_variable"` + AccessPointName types.String `tfsdk:"access_point_name"` + AccessPointNameVariable types.String `tfsdk:"access_point_name_variable"` + NoAuthentication types.String `tfsdk:"no_authentication"` + AuthenticationType types.String `tfsdk:"authentication_type"` + AuthenticationTypeVariable types.String `tfsdk:"authentication_type_variable"` + ProfileUsername types.String `tfsdk:"profile_username"` + ProfileUsernameVariable types.String `tfsdk:"profile_username_variable"` + ProfilePassword types.String `tfsdk:"profile_password"` + ProfilePasswordVariable types.String `tfsdk:"profile_password_variable"` + PacketDataNetworkType types.String `tfsdk:"packet_data_network_type"` + PacketDataNetworkTypeVariable types.String `tfsdk:"packet_data_network_type_variable"` + NoOverwrite types.Bool `tfsdk:"no_overwrite"` + NoOverwriteVariable types.String `tfsdk:"no_overwrite_variable"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data TransportCellularProfile) getModel() string { + return "transport_cellular_profile" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data TransportCellularProfile) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/transport/%v/cellular-profile", url.QueryEscape(data.FeatureProfileId.ValueString())) +} + +// End of section. //template:end getPath + +// Section below is generated&owned by "gen/generator.go". //template:begin toBody +func (data TransportCellularProfile) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + body, _ = sjson.Set(body, path+"configType.optionType", "default") + body, _ = sjson.Set(body, path+"configType.value", "non-eSim") + } + + if !data.ProfileIdVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.id.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.id.value", data.ProfileIdVariable.ValueString()) + } + } else if !data.ProfileId.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.id.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.id.value", data.ProfileId.ValueInt64()) + } + } + + if !data.AccessPointNameVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.apn.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.apn.value", data.AccessPointNameVariable.ValueString()) + } + } else if !data.AccessPointName.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.apn.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.apn.value", data.AccessPointName.ValueString()) + } + } + if !data.NoAuthentication.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.noAuthentication.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.noAuthentication.value", data.NoAuthentication.ValueString()) + } + } + + if !data.AuthenticationTypeVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.type.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.type.value", data.AuthenticationTypeVariable.ValueString()) + } + } else if !data.AuthenticationType.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.type.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.type.value", data.AuthenticationType.ValueString()) + } + } + + if !data.ProfileUsernameVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.username.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.username.value", data.ProfileUsernameVariable.ValueString()) + } + } else if !data.ProfileUsername.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.username.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.username.value", data.ProfileUsername.ValueString()) + } + } + + if !data.ProfilePasswordVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.password.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.password.value", data.ProfilePasswordVariable.ValueString()) + } + } else if !data.ProfilePassword.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.password.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.authentication.needAuthentication.password.value", data.ProfilePassword.ValueString()) + } + } + + if !data.PacketDataNetworkTypeVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.value", data.PacketDataNetworkTypeVariable.ValueString()) + } + } else if data.PacketDataNetworkType.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.optionType", "default") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.value", "ipv4") + } + } else { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.pdnType.value", data.PacketDataNetworkType.ValueString()) + } + } + + if !data.NoOverwriteVariable.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.noOverwrite.optionType", "variable") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.noOverwrite.value", data.NoOverwriteVariable.ValueString()) + } + } else if data.NoOverwrite.IsNull() { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.noOverwrite.optionType", "default") + + } + } else { + if true { + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.noOverwrite.optionType", "global") + body, _ = sjson.Set(body, path+"profileConfig.profileInfo.noOverwrite.value", data.NoOverwrite.ValueBool()) + } + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *TransportCellularProfile) fromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + data.ProfileId = types.Int64Null() + data.ProfileIdVariable = types.StringNull() + if t := res.Get(path + "profileConfig.id.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.id.value") + if t.String() == "variable" { + data.ProfileIdVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ProfileId = types.Int64Value(va.Int()) + } + } + data.AccessPointName = types.StringNull() + data.AccessPointNameVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.apn.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.apn.value") + if t.String() == "variable" { + data.AccessPointNameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.AccessPointName = types.StringValue(va.String()) + } + } + data.NoAuthentication = types.StringNull() + + if t := res.Get(path + "profileConfig.profileInfo.authentication.noAuthentication.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.noAuthentication.value") + if t.String() == "global" { + data.NoAuthentication = types.StringValue(va.String()) + } + } + data.AuthenticationType = types.StringNull() + data.AuthenticationTypeVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.type.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.type.value") + if t.String() == "variable" { + data.AuthenticationTypeVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.AuthenticationType = types.StringValue(va.String()) + } + } + data.ProfileUsername = types.StringNull() + data.ProfileUsernameVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.username.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.username.value") + if t.String() == "variable" { + data.ProfileUsernameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ProfileUsername = types.StringValue(va.String()) + } + } + data.PacketDataNetworkType = types.StringNull() + data.PacketDataNetworkTypeVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.pdnType.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.pdnType.value") + if t.String() == "variable" { + data.PacketDataNetworkTypeVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.PacketDataNetworkType = types.StringValue(va.String()) + } + } + data.NoOverwrite = types.BoolNull() + data.NoOverwriteVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.noOverwrite.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.noOverwrite.value") + if t.String() == "variable" { + data.NoOverwriteVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.NoOverwrite = types.BoolValue(va.Bool()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *TransportCellularProfile) updateFromBody(ctx context.Context, res gjson.Result) { + data.Name = types.StringValue(res.Get("payload.name").String()) + if value := res.Get("payload.description"); value.Exists() && value.String() != "" { + data.Description = types.StringValue(value.String()) + } else { + data.Description = types.StringNull() + } + path := "payload.data." + data.ProfileId = types.Int64Null() + data.ProfileIdVariable = types.StringNull() + if t := res.Get(path + "profileConfig.id.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.id.value") + if t.String() == "variable" { + data.ProfileIdVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ProfileId = types.Int64Value(va.Int()) + } + } + data.AccessPointName = types.StringNull() + data.AccessPointNameVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.apn.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.apn.value") + if t.String() == "variable" { + data.AccessPointNameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.AccessPointName = types.StringValue(va.String()) + } + } + data.NoAuthentication = types.StringNull() + + if t := res.Get(path + "profileConfig.profileInfo.authentication.noAuthentication.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.noAuthentication.value") + if t.String() == "global" { + data.NoAuthentication = types.StringValue(va.String()) + } + } + data.AuthenticationType = types.StringNull() + data.AuthenticationTypeVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.type.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.type.value") + if t.String() == "variable" { + data.AuthenticationTypeVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.AuthenticationType = types.StringValue(va.String()) + } + } + data.ProfileUsername = types.StringNull() + data.ProfileUsernameVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.username.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.authentication.needAuthentication.username.value") + if t.String() == "variable" { + data.ProfileUsernameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ProfileUsername = types.StringValue(va.String()) + } + } + data.PacketDataNetworkType = types.StringNull() + data.PacketDataNetworkTypeVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.pdnType.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.pdnType.value") + if t.String() == "variable" { + data.PacketDataNetworkTypeVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.PacketDataNetworkType = types.StringValue(va.String()) + } + } + data.NoOverwrite = types.BoolNull() + data.NoOverwriteVariable = types.StringNull() + if t := res.Get(path + "profileConfig.profileInfo.noOverwrite.optionType"); t.Exists() { + va := res.Get(path + "profileConfig.profileInfo.noOverwrite.value") + if t.String() == "variable" { + data.NoOverwriteVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.NoOverwrite = types.BoolValue(va.Bool()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *TransportCellularProfile) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if !data.ProfileId.IsNull() { + return false + } + if !data.ProfileIdVariable.IsNull() { + return false + } + if !data.AccessPointName.IsNull() { + return false + } + if !data.AccessPointNameVariable.IsNull() { + return false + } + if !data.NoAuthentication.IsNull() { + return false + } + if !data.AuthenticationType.IsNull() { + return false + } + if !data.AuthenticationTypeVariable.IsNull() { + return false + } + if !data.ProfileUsername.IsNull() { + return false + } + if !data.ProfileUsernameVariable.IsNull() { + return false + } + if !data.ProfilePassword.IsNull() { + return false + } + if !data.ProfilePasswordVariable.IsNull() { + return false + } + if !data.PacketDataNetworkType.IsNull() { + return false + } + if !data.PacketDataNetworkTypeVariable.IsNull() { + return false + } + if !data.NoOverwrite.IsNull() { + return false + } + if !data.NoOverwriteVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 045c890b..35281ad9 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -351,6 +351,8 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewSystemRemoteAccessProfileParcelResource, NewSystemSecurityProfileParcelResource, NewSystemSNMPProfileParcelResource, + NewTransportCellularControllerProfileParcelResource, + NewTransportCellularProfileProfileParcelResource, NewTransportGPSProfileParcelResource, NewTransportIPv4ACLProfileParcelResource, NewTransportIPv6ACLProfileParcelResource, @@ -561,6 +563,8 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewSystemRemoteAccessProfileParcelDataSource, NewSystemSecurityProfileParcelDataSource, NewSystemSNMPProfileParcelDataSource, + NewTransportCellularControllerProfileParcelDataSource, + NewTransportCellularProfileProfileParcelDataSource, NewTransportGPSProfileParcelDataSource, NewTransportIPv4ACLProfileParcelDataSource, NewTransportIPv6ACLProfileParcelDataSource, diff --git a/internal/provider/resource_sdwan_transport_cellular_controller_feature.go b/internal/provider/resource_sdwan_transport_cellular_controller_feature.go new file mode 100644 index 00000000..f89b3478 --- /dev/null +++ b/internal/provider/resource_sdwan_transport_cellular_controller_feature.go @@ -0,0 +1,305 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + "strings" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure provider defined types fully satisfy framework interfaces +var _ resource.Resource = &TransportCellularControllerProfileParcelResource{} +var _ resource.ResourceWithImportState = &TransportCellularControllerProfileParcelResource{} + +func NewTransportCellularControllerProfileParcelResource() resource.Resource { + return &TransportCellularControllerProfileParcelResource{} +} + +type TransportCellularControllerProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *TransportCellularControllerProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_cellular_controller_feature" +} + +func (r *TransportCellularControllerProfileParcelResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Transport Cellular Controller Feature.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Feature", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Feature", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Feature", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Feature", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "cellular_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Cellular ID").String, + Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 5), + }, + }, + "cellular_id_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "primary_sim_slot": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set primary SIM slot").AddIntegerRangeDescription(0, 1).String, + Optional: true, + }, + "primary_sim_slot_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "sim_failover_retries": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set SIM failover retries").AddIntegerRangeDescription(0, 65535).String, + Optional: true, + }, + "sim_failover_retries_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "sim_failover_timeout": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set SIM failover timeout in minutes").AddIntegerRangeDescription(3, 7).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(3, 7), + }, + }, + "sim_failover_timeout_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "firmware_auto_sim": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Enable/Disable Firmware Auto Sim").AddDefaultValueDescription("true").String, + Optional: true, + }, + "firmware_auto_sim_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *TransportCellularControllerProfileParcelResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + r.client = req.ProviderData.(*SdwanProviderData).Client + r.updateMutex = req.ProviderData.(*SdwanProviderData).UpdateMutex +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin create +func (r *TransportCellularControllerProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransportCellularController + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + + // Create object + body := plan.toBody(ctx) + + res, err := r.client.Post(plan.getPath(), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) + return + } + + plan.Id = types.StringValue(res.Get("parcelId").String()) + plan.Version = types.Int64Value(0) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Name.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end create + +// Section below is generated&owned by "gen/generator.go". //template:begin read +func (r *TransportCellularControllerProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransportCellularController + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if res.Get("error.message").String() == "Invalid feature Id" { + resp.State.RemoveResource(ctx) + return + } else if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) + return + } + + // If every attribute is set to null we are dealing with an import operation and therefore reading all attributes + if state.isNull(ctx, res) { + state.fromBody(ctx, res) + } else { + state.updateFromBody(ctx, res) + } + if state.Version.IsNull() { + state.Version = types.Int64Value(0) + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Name.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end read + +// Section below is generated&owned by "gen/generator.go". //template:begin update +func (r *TransportCellularControllerProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransportCellularController + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Read state + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) + + body := plan.toBody(ctx) + res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) + return + } + + plan.Version = types.Int64Value(state.Version.ValueInt64() + 1) + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Name.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end update + +// Section below is generated&owned by "gen/generator.go". //template:begin delete +func (r *TransportCellularControllerProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransportCellularController + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Name.ValueString())) + + res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if err != nil && res.Get("error.message").String() != "Invalid Template Id" { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Name.ValueString())) + + resp.State.RemoveResource(ctx) +} + +// End of section. //template:end delete + +// Section below is generated&owned by "gen/generator.go". //template:begin import +func (r *TransportCellularControllerProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + count := 1 + parts := strings.SplitN(req.ID, ",", (count + 1)) + + pattern := "transport_cellular_controller_feature_id" + ",feature_profile_id" + if len(parts) != (count + 1) { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", fmt.Sprintf("Expected import identifier with the format: %s. Got: %q", pattern, req.ID), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), parts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("feature_profile_id"), parts[1])...) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_transport_cellular_controller_feature_test.go b/internal/provider/resource_sdwan_transport_cellular_controller_feature_test.go new file mode 100644 index 00000000..8b57a750 --- /dev/null +++ b/internal/provider/resource_sdwan_transport_cellular_controller_feature_test.go @@ -0,0 +1,85 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanTransportCellularControllerProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_controller_feature.test", "cellular_id", "0/3/0")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_controller_feature.test", "primary_sim_slot", "0")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_controller_feature.test", "sim_failover_retries", "5")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_controller_feature.test", "sim_failover_timeout", "3")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_controller_feature.test", "firmware_auto_sim", "true")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanTransportCellularControllerPrerequisitesProfileParcelConfig + testAccSdwanTransportCellularControllerProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanTransportCellularControllerPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanTransportCellularControllerProfileParcelConfig_all() string { + config := `resource "sdwan_transport_cellular_controller_feature" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id` + "\n" + config += ` cellular_id = "0/3/0"` + "\n" + config += ` primary_sim_slot = 0` + "\n" + config += ` sim_failover_retries = 5` + "\n" + config += ` sim_failover_timeout = 3` + "\n" + config += ` firmware_auto_sim = true` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_transport_cellular_profile_feature.go b/internal/provider/resource_sdwan_transport_cellular_profile_feature.go new file mode 100644 index 00000000..a020052a --- /dev/null +++ b/internal/provider/resource_sdwan_transport_cellular_profile_feature.go @@ -0,0 +1,328 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + "strings" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure provider defined types fully satisfy framework interfaces +var _ resource.Resource = &TransportCellularProfileProfileParcelResource{} +var _ resource.ResourceWithImportState = &TransportCellularProfileProfileParcelResource{} + +func NewTransportCellularProfileProfileParcelResource() resource.Resource { + return &TransportCellularProfileProfileParcelResource{} +} + +type TransportCellularProfileProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *TransportCellularProfileProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_cellular_profile_feature" +} + +func (r *TransportCellularProfileProfileParcelResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: helpers.NewAttributeDescription("This resource can manage a Transport Cellular Profile Feature.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Feature", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Feature", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Feature", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Feature", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "profile_id": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set Profile ID").AddIntegerRangeDescription(1, 16).String, + Required: true, + Validators: []validator.Int64{ + int64validator.Between(1, 16), + }, + }, + "profile_id_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "access_point_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set access point name").String, + Required: true, + }, + "access_point_name_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "no_authentication": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("No Authentication").String, + Optional: true, + }, + "authentication_type": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set authentication type").AddStringEnumDescription("pap", "chap", "pap_chap").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("pap", "chap", "pap_chap"), + }, + }, + "authentication_type_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "profile_username": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set the profile username").String, + Optional: true, + }, + "profile_username_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "profile_password": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set the profile password").String, + Optional: true, + }, + "profile_password_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "packet_data_network_type": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Set packet data network type").AddStringEnumDescription("ipv4", "ipv4v6", "ipv6").AddDefaultValueDescription("ipv4").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("ipv4", "ipv4v6", "ipv6"), + }, + }, + "packet_data_network_type_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "no_overwrite": schema.BoolAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("No Overwrite").String, + Optional: true, + }, + "no_overwrite_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *TransportCellularProfileProfileParcelResource) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + r.client = req.ProviderData.(*SdwanProviderData).Client + r.updateMutex = req.ProviderData.(*SdwanProviderData).UpdateMutex +} + +// End of section. //template:end model + +// Section below is generated&owned by "gen/generator.go". //template:begin create +func (r *TransportCellularProfileProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransportCellularProfile + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Create", plan.Name.ValueString())) + + // Create object + body := plan.toBody(ctx) + + res, err := r.client.Post(plan.getPath(), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (POST), got error: %s, %s", err, res.String())) + return + } + + plan.Id = types.StringValue(res.Get("parcelId").String()) + plan.Version = types.Int64Value(0) + + tflog.Debug(ctx, fmt.Sprintf("%s: Create finished successfully", plan.Name.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end create + +// Section below is generated&owned by "gen/generator.go". //template:begin read +func (r *TransportCellularProfileProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransportCellularProfile + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", state.Name.String())) + + res, err := r.client.Get(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if res.Get("error.message").String() == "Invalid feature Id" { + resp.State.RemoveResource(ctx) + return + } else if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String())) + return + } + + // If every attribute is set to null we are dealing with an import operation and therefore reading all attributes + if state.isNull(ctx, res) { + state.fromBody(ctx, res) + } else { + state.updateFromBody(ctx, res) + } + if state.Version.IsNull() { + state.Version = types.Int64Value(0) + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", state.Name.ValueString())) + + diags = resp.State.Set(ctx, &state) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end read + +// Section below is generated&owned by "gen/generator.go". //template:begin update +func (r *TransportCellularProfileProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransportCellularProfile + + // Read plan + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + // Read state + diags = req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Update", plan.Name.ValueString())) + + body := plan.toBody(ctx) + res, err := r.client.Put(plan.getPath()+"/"+url.QueryEscape(plan.Id.ValueString()), body) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to configure object (PUT), got error: %s, %s", err, res.String())) + return + } + + plan.Version = types.Int64Value(state.Version.ValueInt64() + 1) + + tflog.Debug(ctx, fmt.Sprintf("%s: Update finished successfully", plan.Name.ValueString())) + + diags = resp.State.Set(ctx, &plan) + resp.Diagnostics.Append(diags...) +} + +// End of section. //template:end update + +// Section below is generated&owned by "gen/generator.go". //template:begin delete +func (r *TransportCellularProfileProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransportCellularProfile + + // Read state + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Delete", state.Name.ValueString())) + + res, err := r.client.Delete(state.getPath() + "/" + url.QueryEscape(state.Id.ValueString())) + if err != nil && res.Get("error.message").String() != "Invalid Template Id" { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to delete object (DELETE), got error: %s, %s", err, res.String())) + return + } + + tflog.Debug(ctx, fmt.Sprintf("%s: Delete finished successfully", state.Name.ValueString())) + + resp.State.RemoveResource(ctx) +} + +// End of section. //template:end delete + +// Section below is generated&owned by "gen/generator.go". //template:begin import +func (r *TransportCellularProfileProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + count := 1 + parts := strings.SplitN(req.ID, ",", (count + 1)) + + pattern := "transport_cellular_profile_feature_id" + ",feature_profile_id" + if len(parts) != (count + 1) { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", fmt.Sprintf("Expected import identifier with the format: %s. Got: %q", pattern, req.ID), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), parts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("feature_profile_id"), parts[1])...) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_transport_cellular_profile_feature_test.go b/internal/provider/resource_sdwan_transport_cellular_profile_feature_test.go new file mode 100644 index 00000000..c11d7b1a --- /dev/null +++ b/internal/provider/resource_sdwan_transport_cellular_profile_feature_test.go @@ -0,0 +1,88 @@ +// 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 + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanTransportCellularProfileProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "profile_id", "1")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "access_point_name", "apn1")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "authentication_type", "pap")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "profile_username", "example")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "packet_data_network_type", "ipv4")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_cellular_profile_feature.test", "no_overwrite", "false")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanTransportCellularProfilePrerequisitesProfileParcelConfig + testAccSdwanTransportCellularProfileProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanTransportCellularProfilePrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanTransportCellularProfileProfileParcelConfig_all() string { + config := `resource "sdwan_transport_cellular_profile_feature" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id` + "\n" + config += ` profile_id = 1` + "\n" + config += ` access_point_name = "apn1"` + "\n" + config += ` authentication_type = "pap"` + "\n" + config += ` profile_username = "example"` + "\n" + config += ` profile_password = "example123!"` + "\n" + config += ` packet_data_network_type = "ipv4"` + "\n" + config += ` no_overwrite = false` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index d4379422..5a6fc00b 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -10,6 +10,8 @@ description: |- ## 0.5.1 (unreleased) - BREAKING CHANGE: Adds `gateway` attribute to `sdwan_transport_wan_vpn_feature` resource +- Add `sdwan_transport_cellular_controller_feature` resource and data source +- Add `sdwan_transport_cellular_profile_feature` resource and data source ## 0.5.0