From 4b34228f48aa097275407fd730960589e9f04af8 Mon Sep 17 00:00:00 2001 From: Sean Conroy Date: Wed, 17 Jul 2024 12:53:48 +0100 Subject: [PATCH] Add tracker groups profile parcel resources and data sources --- CHANGELOG.md | 3 + .../service_tracker_group_profile_parcel.md | 44 +++ ...sport_ipv6_tracker_group_profile_parcel.md | 46 +++ .../transport_tracker_group_profile_parcel.md | 44 +++ docs/guides/changelog.md | 3 + .../service_tracker_group_profile_parcel.md | 66 +++++ ...sport_ipv6_tracker_group_profile_parcel.md | 69 +++++ .../transport_tracker_group_profile_parcel.md | 66 +++++ .../data-source.tf | 4 + .../data-source.tf | 4 + .../data-source.tf | 4 + .../import.sh | 1 + .../resource.tf | 11 + .../import.sh | 1 + .../resource.tf | 12 + .../import.sh | 1 + .../resource.tf | 11 + .../service_tracker_group.yaml | 48 +++ .../transport_ipv6_tracker_group.yaml | 51 ++++ .../transport_tracker_group.yaml | 47 +++ .../service_tracker_group.json | 199 +++++++++++++ .../transport_ipv6_tracker_group.json | 247 +++++++++++++++ .../transport_tracker_group.json | 199 +++++++++++++ ...an_service_tracker_group_profile_parcel.go | 142 +++++++++ ...rvice_tracker_group_profile_parcel_test.go | 100 +++++++ ...sport_ipv6_tracker_group_profile_parcel.go | 150 ++++++++++ ..._ipv6_tracker_group_profile_parcel_test.go | 100 +++++++ ..._transport_tracker_group_profile_parcel.go | 142 +++++++++ ...sport_tracker_group_profile_parcel_test.go | 98 ++++++ ...an_service_tracker_group_profile_parcel.go | 210 +++++++++++++ ...sport_ipv6_tracker_group_profile_parcel.go | 246 +++++++++++++++ ..._transport_tracker_group_profile_parcel.go | 210 +++++++++++++ internal/provider/provider.go | 6 + ...an_service_tracker_group_profile_parcel.go | 269 +++++++++++++++++ ...rvice_tracker_group_profile_parcel_test.go | 108 +++++++ ...sport_ipv6_tracker_group_profile_parcel.go | 280 ++++++++++++++++++ ..._ipv6_tracker_group_profile_parcel_test.go | 109 +++++++ ..._transport_tracker_group_profile_parcel.go | 269 +++++++++++++++++ ...sport_tracker_group_profile_parcel_test.go | 106 +++++++ templates/guides/changelog.md.tmpl | 3 + 40 files changed, 3729 insertions(+) create mode 100644 docs/data-sources/service_tracker_group_profile_parcel.md create mode 100644 docs/data-sources/transport_ipv6_tracker_group_profile_parcel.md create mode 100644 docs/data-sources/transport_tracker_group_profile_parcel.md create mode 100644 docs/resources/service_tracker_group_profile_parcel.md create mode 100644 docs/resources/transport_ipv6_tracker_group_profile_parcel.md create mode 100644 docs/resources/transport_tracker_group_profile_parcel.md create mode 100644 examples/data-sources/sdwan_service_tracker_group_profile_parcel/data-source.tf create mode 100644 examples/data-sources/sdwan_transport_ipv6_tracker_group_profile_parcel/data-source.tf create mode 100644 examples/data-sources/sdwan_transport_tracker_group_profile_parcel/data-source.tf create mode 100644 examples/resources/sdwan_service_tracker_group_profile_parcel/import.sh create mode 100644 examples/resources/sdwan_service_tracker_group_profile_parcel/resource.tf create mode 100644 examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/import.sh create mode 100644 examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/resource.tf create mode 100644 examples/resources/sdwan_transport_tracker_group_profile_parcel/import.sh create mode 100644 examples/resources/sdwan_transport_tracker_group_profile_parcel/resource.tf create mode 100644 gen/definitions/profile_parcels/service_tracker_group.yaml create mode 100644 gen/definitions/profile_parcels/transport_ipv6_tracker_group.yaml create mode 100644 gen/definitions/profile_parcels/transport_tracker_group.yaml create mode 100644 gen/models/profile_parcels/service_tracker_group.json create mode 100644 gen/models/profile_parcels/transport_ipv6_tracker_group.json create mode 100644 gen/models/profile_parcels/transport_tracker_group.json create mode 100644 internal/provider/data_source_sdwan_service_tracker_group_profile_parcel.go create mode 100644 internal/provider/data_source_sdwan_service_tracker_group_profile_parcel_test.go create mode 100644 internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel.go create mode 100644 internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go create mode 100644 internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel.go create mode 100644 internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel_test.go create mode 100644 internal/provider/model_sdwan_service_tracker_group_profile_parcel.go create mode 100644 internal/provider/model_sdwan_transport_ipv6_tracker_group_profile_parcel.go create mode 100644 internal/provider/model_sdwan_transport_tracker_group_profile_parcel.go create mode 100644 internal/provider/resource_sdwan_service_tracker_group_profile_parcel.go create mode 100644 internal/provider/resource_sdwan_service_tracker_group_profile_parcel_test.go create mode 100644 internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel.go create mode 100644 internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go create mode 100644 internal/provider/resource_sdwan_transport_tracker_group_profile_parcel.go create mode 100644 internal/provider/resource_sdwan_transport_tracker_group_profile_parcel_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b2c642..283e383a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ## 0.3.14 (unreleased) - Add `sdwan_transport_tracker_profile_parcel` resource and data source +- Add `sdwan_service_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_ipv6_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_tracker_group_profile_parcel` resource and data source ## 0.3.13 diff --git a/docs/data-sources/service_tracker_group_profile_parcel.md b/docs/data-sources/service_tracker_group_profile_parcel.md new file mode 100644 index 00000000..f6b07d9d --- /dev/null +++ b/docs/data-sources/service_tracker_group_profile_parcel.md @@ -0,0 +1,44 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_service_tracker_group_profile_parcel Data Source - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This data source can read the Service Tracker Group profile parcel. +--- + +# sdwan_service_tracker_group_profile_parcel (Data Source) + +This data source can read the Service Tracker Group profile parcel. + +## Example Usage + +```terraform +data "sdwan_service_tracker_group_profile_parcel" "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 profile parcel + +### Read-Only + +- `description` (String) The description of the profile parcel +- `name` (String) The name of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) tracker parcel ref list (see [below for nested schema](#nestedatt--tracker_elements)) +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Read-Only: + +- `tracker_id` (String) diff --git a/docs/data-sources/transport_ipv6_tracker_group_profile_parcel.md b/docs/data-sources/transport_ipv6_tracker_group_profile_parcel.md new file mode 100644 index 00000000..a88d9348 --- /dev/null +++ b/docs/data-sources/transport_ipv6_tracker_group_profile_parcel.md @@ -0,0 +1,46 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_ipv6_tracker_group_profile_parcel Data Source - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This data source can read the Transport IPv6 Tracker Group profile parcel. +--- + +# sdwan_transport_ipv6_tracker_group_profile_parcel (Data Source) + +This data source can read the Transport IPv6 Tracker Group profile parcel. + +## Example Usage + +```terraform +data "sdwan_transport_ipv6_tracker_group_profile_parcel" "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 profile parcel + +### Read-Only + +- `description` (String) The description of the profile parcel +- `name` (String) The name of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) trackers ref list (see [below for nested schema](#nestedatt--tracker_elements)) +- `tracker_name` (String) Tracker Name +- `tracker_name_variable` (String) Variable name +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Read-Only: + +- `tracker_id` (String) diff --git a/docs/data-sources/transport_tracker_group_profile_parcel.md b/docs/data-sources/transport_tracker_group_profile_parcel.md new file mode 100644 index 00000000..f09c5c30 --- /dev/null +++ b/docs/data-sources/transport_tracker_group_profile_parcel.md @@ -0,0 +1,44 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_tracker_group_profile_parcel Data Source - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This data source can read the Transport Tracker Group profile parcel. +--- + +# sdwan_transport_tracker_group_profile_parcel (Data Source) + +This data source can read the Transport Tracker Group profile parcel. + +## Example Usage + +```terraform +data "sdwan_transport_tracker_group_profile_parcel" "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 profile parcel + +### Read-Only + +- `description` (String) The description of the profile parcel +- `name` (String) The name of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) tracker parcel ref list (see [below for nested schema](#nestedatt--tracker_elements)) +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Read-Only: + +- `tracker_id` (String) diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index b427ee30..eec561a3 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -10,6 +10,9 @@ description: |- ## 0.3.14 (unreleased) - Add `sdwan_transport_tracker_profile_parcel` resource and data source +- Add `sdwan_service_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_ipv6_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_tracker_group_profile_parcel` resource and data source ## 0.3.13 diff --git a/docs/resources/service_tracker_group_profile_parcel.md b/docs/resources/service_tracker_group_profile_parcel.md new file mode 100644 index 00000000..bca0a103 --- /dev/null +++ b/docs/resources/service_tracker_group_profile_parcel.md @@ -0,0 +1,66 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_service_tracker_group_profile_parcel Resource - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This resource can manage a Service Tracker Group profile parcel. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_service_tracker_group_profile_parcel (Resource) + +This resource can manage a Service Tracker Group profile parcel. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_service_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the profile parcel + +### Optional + +- `description` (String) The description of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or + - Choices: `and`, `or` + - Default value: `or` +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) tracker parcel ref list (see [below for nested schema](#nestedatt--tracker_elements)) + +### Read-Only + +- `id` (String) The id of the profile parcel +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Optional: + +- `tracker_id` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_service_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/transport_ipv6_tracker_group_profile_parcel.md b/docs/resources/transport_ipv6_tracker_group_profile_parcel.md new file mode 100644 index 00000000..b785c30d --- /dev/null +++ b/docs/resources/transport_ipv6_tracker_group_profile_parcel.md @@ -0,0 +1,69 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_ipv6_tracker_group_profile_parcel Resource - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This resource can manage a Transport IPv6 Tracker Group profile parcel. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_transport_ipv6_tracker_group_profile_parcel (Resource) + +This resource can manage a Transport IPv6 Tracker Group profile parcel. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_transport_ipv6_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_name = "TRACKER_GROUP_1" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the profile parcel +- `tracker_name` (String) Tracker Name + +### Optional + +- `description` (String) The description of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or + - Choices: `and`, `or` + - Default value: `or` +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) trackers ref list (see [below for nested schema](#nestedatt--tracker_elements)) +- `tracker_name_variable` (String) Variable name + +### Read-Only + +- `id` (String) The id of the profile parcel +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Optional: + +- `tracker_id` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_transport_ipv6_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/transport_tracker_group_profile_parcel.md b/docs/resources/transport_tracker_group_profile_parcel.md new file mode 100644 index 00000000..95c15ace --- /dev/null +++ b/docs/resources/transport_tracker_group_profile_parcel.md @@ -0,0 +1,66 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_transport_tracker_group_profile_parcel Resource - terraform-provider-sdwan" +subcategory: "Profile Parcels" +description: |- + This resource can manage a Transport Tracker Group profile parcel. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_transport_tracker_group_profile_parcel (Resource) + +This resource can manage a Transport Tracker Group profile parcel. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_transport_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the profile parcel + +### Optional + +- `description` (String) The description of the profile parcel +- `tracker_boolean` (String) tracker ref list combine boolean and or + - Choices: `and`, `or` + - Default value: `or` +- `tracker_boolean_variable` (String) Variable name +- `tracker_elements` (Attributes List) tracker parcel ref list (see [below for nested schema](#nestedatt--tracker_elements)) + +### Read-Only + +- `id` (String) The id of the profile parcel +- `version` (Number) The version of the profile parcel + + +### Nested Schema for `tracker_elements` + +Optional: + +- `tracker_id` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_transport_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/examples/data-sources/sdwan_service_tracker_group_profile_parcel/data-source.tf b/examples/data-sources/sdwan_service_tracker_group_profile_parcel/data-source.tf new file mode 100644 index 00000000..24f9f2ab --- /dev/null +++ b/examples/data-sources/sdwan_service_tracker_group_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_service_tracker_group_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_transport_ipv6_tracker_group_profile_parcel/data-source.tf b/examples/data-sources/sdwan_transport_ipv6_tracker_group_profile_parcel/data-source.tf new file mode 100644 index 00000000..21f1a376 --- /dev/null +++ b/examples/data-sources/sdwan_transport_ipv6_tracker_group_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_transport_ipv6_tracker_group_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_transport_tracker_group_profile_parcel/data-source.tf b/examples/data-sources/sdwan_transport_tracker_group_profile_parcel/data-source.tf new file mode 100644 index 00000000..9543cb3b --- /dev/null +++ b/examples/data-sources/sdwan_transport_tracker_group_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_transport_tracker_group_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/resources/sdwan_service_tracker_group_profile_parcel/import.sh b/examples/resources/sdwan_service_tracker_group_profile_parcel/import.sh new file mode 100644 index 00000000..d3820f18 --- /dev/null +++ b/examples/resources/sdwan_service_tracker_group_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_service_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_service_tracker_group_profile_parcel/resource.tf b/examples/resources/sdwan_service_tracker_group_profile_parcel/resource.tf new file mode 100644 index 00000000..eccfc472 --- /dev/null +++ b/examples/resources/sdwan_service_tracker_group_profile_parcel/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_service_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} diff --git a/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/import.sh b/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/import.sh new file mode 100644 index 00000000..af0e6c38 --- /dev/null +++ b/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_transport_ipv6_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/resource.tf b/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/resource.tf new file mode 100644 index 00000000..45e9f71f --- /dev/null +++ b/examples/resources/sdwan_transport_ipv6_tracker_group_profile_parcel/resource.tf @@ -0,0 +1,12 @@ +resource "sdwan_transport_ipv6_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_name = "TRACKER_GROUP_1" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} diff --git a/examples/resources/sdwan_transport_tracker_group_profile_parcel/import.sh b/examples/resources/sdwan_transport_tracker_group_profile_parcel/import.sh new file mode 100644 index 00000000..8fab5785 --- /dev/null +++ b/examples/resources/sdwan_transport_tracker_group_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_transport_tracker_group_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_transport_tracker_group_profile_parcel/resource.tf b/examples/resources/sdwan_transport_tracker_group_profile_parcel/resource.tf new file mode 100644 index 00000000..e62a9fc7 --- /dev/null +++ b/examples/resources/sdwan_transport_tracker_group_profile_parcel/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_transport_tracker_group_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + tracker_elements = [ + { + tracker_id = "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + ] + tracker_boolean = "or" +} diff --git a/gen/definitions/profile_parcels/service_tracker_group.yaml b/gen/definitions/profile_parcels/service_tracker_group.yaml new file mode 100644 index 00000000..de2ae588 --- /dev/null +++ b/gen/definitions/profile_parcels/service_tracker_group.yaml @@ -0,0 +1,48 @@ +--- +name: Service Tracker Group +rest_endpoint: /v1/feature-profile/sdwan/service/%v/trackergroup +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +exclude_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_service_feature_profile.test.id + - model_name: trackerRefs + tf_name: tracker_elements + attributes: + - model_name: refId + tf_name: tracker_id + data_path: [trackerRef] + example: 615d948f-34ee-4a2e-810e-a9bd8d3d48ec + test_value: sdwan_service_tracker_profile_parcel.test.id + - model_name: combineBoolean + tf_name: tracker_boolean + example: or + +test_prerequisites: | + resource "sdwan_service_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" + } + + resource "sdwan_service_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform test" + feature_profile_id = sdwan_service_feature_profile.test.id + tracker_name = "TRACKER_2" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + protocol = "tcp" + port = 123 + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "static-route" + tracker_type = "endpoint" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/transport_ipv6_tracker_group.yaml b/gen/definitions/profile_parcels/transport_ipv6_tracker_group.yaml new file mode 100644 index 00000000..0babe2f3 --- /dev/null +++ b/gen/definitions/profile_parcels/transport_ipv6_tracker_group.yaml @@ -0,0 +1,51 @@ +--- +name: Transport IPv6 Tracker Group +rest_endpoint: /v1/feature-profile/sdwan/transport/%v/ipv6-trackergroup +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +exclude_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: trackerGroupName + tf_name: tracker_name + mandatory: true + example: TRACKER_GROUP_1 + - model_name: trackerRefs + tf_name: tracker_elements + attributes: + - model_name: refId + tf_name: tracker_id + data_path: [trackerRef] + id: true + example: 615d948f-34ee-4a2e-810e-a9bd8d3d48ec + test_value: sdwan_transport_ipv6_tracker_profile_parcel.test.id + - model_name: combineBoolean + tf_name: tracker_boolean + example: or + +test_prerequisites: | + resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" + } + + resource "sdwan_transport_ipv6_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "2001:0:0:1::0" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "ipv6-interface" + tracker_type = "endpoint" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/transport_tracker_group.yaml b/gen/definitions/profile_parcels/transport_tracker_group.yaml new file mode 100644 index 00000000..37452ffe --- /dev/null +++ b/gen/definitions/profile_parcels/transport_tracker_group.yaml @@ -0,0 +1,47 @@ +--- +name: Transport Tracker Group +rest_endpoint: /v1/feature-profile/sdwan/transport/%v/trackergroup +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +exclude_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.id1 + - model_name: trackerRefs + tf_name: tracker_elements + attributes: + - model_name: refId + tf_name: tracker_id + data_path: [trackerRef] + id: true + example: 615d948f-34ee-4a2e-810e-a9bd8d3d48ec + test_value: sdwan_transport_tracker_profile_parcel.test.id + - model_name: combineBoolean + tf_name: tracker_boolean + example: or + +test_prerequisites: | + resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" + } + + resource "sdwan_transport_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "interface" + tracker_type = "endpoint" + } \ No newline at end of file diff --git a/gen/models/profile_parcels/service_tracker_group.json b/gen/models/profile_parcels/service_tracker_group.json new file mode 100644 index 00000000..410e4327 --- /dev/null +++ b/gen/models/profile_parcels/service_tracker_group.json @@ -0,0 +1,199 @@ +{ + "request": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "https://cisco.com/schema/profileparcel/sdwan/common/trackergroup/common/request_schema.json", + "title": "common tracker group Schema", + "description": "TrackerGroup profile parcel schema for common request", + "type": "object", + "properties": { + "name": { + "description": "Set the parcel name", + "type": "string", + "pattern": "^[^&<>! \"]+$", + "minLength": 1, + "maxLength": 128 + }, + "description": { + "description": "Set the parcel description", + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "trackerRefs": { + "description": "tracker parcel ref list", + "type": "array", + "items": { + "type": "object", + "properties": { + "trackerRef": { + "properties": { + "refId": { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "pattern": "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + }, + "required": [ + "refId" + ], + "additionalProperties": false + } + }, + "required": [ + "trackerRef" + ], + "additionalProperties": false + }, + "minItems": 2, + "maxItems": 2, + "uniqueItems": true + }, + "combineBoolean": { + "description": "tracker ref list combine boolean and or", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "variable" + ] + }, + "value": { + "type": "string", + "pattern": "^\\{\\{[.\/\\[\\]a-zA-Z0-9_-]+\\}\\}$", + "minLength": 1, + "maxLength": 64 + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "enum": [ + "and", + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "default" + ] + }, + "value": { + "type": "string", + "enum": [ + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "trackerRefs", + "combineBoolean" + ], + "additionalProperties": false + }, + "metadata": { + "parcelRefDefinition": [ + { + "refIdPath": "data.trackerRefs[*].trackerRef", + "parcelType": [ + "tracker" + ] + } + ] + }, + "documentation": { + "description": "This is the documentation for common request schema for common LAN/WAN VPN profile parcel", + "examples": [ + { + "data": { + "trackerRefs": [ + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + } + }, + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec12" + } + } + } + ], + "combineBoolean": { + "optionType": "global", + "value": "and" + } + }, + "description": "common_track_group_cedge_parcel_1", + "name": "common_track_group_cedge_parcel_1" + } + ] + } + }, + "required": [ + "name", + "data" + ], + "not": { + "required": [ + "metadata", + "documentation" + ] + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/gen/models/profile_parcels/transport_ipv6_tracker_group.json b/gen/models/profile_parcels/transport_ipv6_tracker_group.json new file mode 100644 index 00000000..4502cb64 --- /dev/null +++ b/gen/models/profile_parcels/transport_ipv6_tracker_group.json @@ -0,0 +1,247 @@ +{ + "request": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "https://cisco.com/schema/profileparcel/sdwan/transport/ipv6-trackergroup/common/request_schema.json", + "title": "transport ipv6 tracker group Schema", + "description": "IPv6 TrackerGroup profile parcel schema for common request", + "type": "object", + "properties": { + "name": { + "description": "Set the feature name", + "type": "string", + "pattern": "^[^&<>! \"]+$", + "minLength": 1, + "maxLength": 128 + }, + "description": { + "description": "Set the feature description", + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "trackerGroupName": { + "description": "Tracker Name", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "variable" + ] + }, + "value": { + "type": "string", + "pattern": "^\\{\\{[.\/\\[\\]a-zA-Z0-9_-]+\\}\\}$", + "minLength": 1, + "maxLength": 64 + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "minLength": 1, + "maxLength": 128, + "type": "string" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + }, + "trackerRefs": { + "description": "trackers ref list", + "type": "array", + "items": { + "type": "object", + "properties": { + "trackerRef": { + "properties": { + "refId": { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "pattern": "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + }, + "required": [ + "refId" + ], + "additionalProperties": false + } + }, + "required": [ + "trackerRef" + ], + "additionalProperties": false + }, + "minItems": 2, + "maxItems": 2, + "uniqueItems": true + }, + "combineBoolean": { + "description": "tracker ref list combine boolean and or", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "variable" + ] + }, + "value": { + "type": "string", + "pattern": "^\\{\\{[.\/\\[\\]a-zA-Z0-9_-]+\\}\\}$", + "minLength": 1, + "maxLength": 64 + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "enum": [ + "and", + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "default" + ] + }, + "value": { + "type": "string", + "enum": [ + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "trackerGroupName", + "trackerRefs", + "combineBoolean" + ], + "additionalProperties": false + }, + "metadata": { + "parcelRefDefinition": [ + { + "refIdPath": "data.trackerRefs[*].trackerRef", + "parcelType": [ + "ipv6-tracker" + ] + } + ] + }, + "documentation": { + "description": "This is the documentation for common request schema for WAN VPN ipv6-trackergroup profile parcel", + "examples": [ + { + "data": { + "trackerRefs": [ + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + } + }, + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec12" + } + } + } + ], + "combineBoolean": { + "optionType": "global", + "value": "and" + } + }, + "description": "common_track_group_cedge_parcel_1", + "name": "common_track_group_cedge_parcel_1" + } + ] + } + }, + "required": [ + "name", + "data" + ], + "not": { + "required": [ + "metadata", + "documentation" + ] + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/gen/models/profile_parcels/transport_tracker_group.json b/gen/models/profile_parcels/transport_tracker_group.json new file mode 100644 index 00000000..410e4327 --- /dev/null +++ b/gen/models/profile_parcels/transport_tracker_group.json @@ -0,0 +1,199 @@ +{ + "request": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "https://cisco.com/schema/profileparcel/sdwan/common/trackergroup/common/request_schema.json", + "title": "common tracker group Schema", + "description": "TrackerGroup profile parcel schema for common request", + "type": "object", + "properties": { + "name": { + "description": "Set the parcel name", + "type": "string", + "pattern": "^[^&<>! \"]+$", + "minLength": 1, + "maxLength": 128 + }, + "description": { + "description": "Set the parcel description", + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "trackerRefs": { + "description": "tracker parcel ref list", + "type": "array", + "items": { + "type": "object", + "properties": { + "trackerRef": { + "properties": { + "refId": { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "pattern": "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + }, + "required": [ + "refId" + ], + "additionalProperties": false + } + }, + "required": [ + "trackerRef" + ], + "additionalProperties": false + }, + "minItems": 2, + "maxItems": 2, + "uniqueItems": true + }, + "combineBoolean": { + "description": "tracker ref list combine boolean and or", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "variable" + ] + }, + "value": { + "type": "string", + "pattern": "^\\{\\{[.\/\\[\\]a-zA-Z0-9_-]+\\}\\}$", + "minLength": 1, + "maxLength": 64 + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "enum": [ + "and", + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + }, + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "default" + ] + }, + "value": { + "type": "string", + "enum": [ + "or" + ] + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "trackerRefs", + "combineBoolean" + ], + "additionalProperties": false + }, + "metadata": { + "parcelRefDefinition": [ + { + "refIdPath": "data.trackerRefs[*].trackerRef", + "parcelType": [ + "tracker" + ] + } + ] + }, + "documentation": { + "description": "This is the documentation for common request schema for common LAN/WAN VPN profile parcel", + "examples": [ + { + "data": { + "trackerRefs": [ + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec" + } + } + }, + { + "trackerRef": { + "refId": { + "optionType": "global", + "value": "615d948f-34ee-4a2e-810e-a9bd8d3d48ec12" + } + } + } + ], + "combineBoolean": { + "optionType": "global", + "value": "and" + } + }, + "description": "common_track_group_cedge_parcel_1", + "name": "common_track_group_cedge_parcel_1" + } + ] + } + }, + "required": [ + "name", + "data" + ], + "not": { + "required": [ + "metadata", + "documentation" + ] + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/internal/provider/data_source_sdwan_service_tracker_group_profile_parcel.go b/internal/provider/data_source_sdwan_service_tracker_group_profile_parcel.go new file mode 100644 index 00000000..1b59baff --- /dev/null +++ b/internal/provider/data_source_sdwan_service_tracker_group_profile_parcel.go @@ -0,0 +1,142 @@ +// 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 = &ServiceTrackerGroupProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &ServiceTrackerGroupProfileParcelDataSource{} +) + +func NewServiceTrackerGroupProfileParcelDataSource() datasource.DataSource { + return &ServiceTrackerGroupProfileParcelDataSource{} +} + +type ServiceTrackerGroupProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *ServiceTrackerGroupProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_service_tracker_group_profile_parcel" +} + +func (d *ServiceTrackerGroupProfileParcelDataSource) 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 Service Tracker Group profile parcel.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: "tracker parcel ref list", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: "tracker ref list combine boolean and or", + Computed: true, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *ServiceTrackerGroupProfileParcelDataSource) 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 *ServiceTrackerGroupProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config ServiceTrackerGroup + + // 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_service_tracker_group_profile_parcel_test.go b/internal/provider/data_source_sdwan_service_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..27061ed2 --- /dev/null +++ b/internal/provider/data_source_sdwan_service_tracker_group_profile_parcel_test.go @@ -0,0 +1,100 @@ +// 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 TestAccDataSourceSdwanServiceTrackerGroupProfileParcel(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_service_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_service_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanServiceTrackerGroupPrerequisitesProfileParcelConfig + testAccDataSourceSdwanServiceTrackerGroupProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanServiceTrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_service_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_service_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform test" + feature_profile_id = sdwan_service_feature_profile.test.id + tracker_name = "TRACKER_2" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + protocol = "tcp" + port = 123 + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "static-route" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanServiceTrackerGroupProfileParcelConfig() string { + config := `resource "sdwan_service_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_service_feature_profile.test.id` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_service_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_service_tracker_group_profile_parcel" "test" { + id = sdwan_service_tracker_group_profile_parcel.test.id + feature_profile_id = sdwan_service_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel.go b/internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel.go new file mode 100644 index 00000000..8cc45a1d --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel.go @@ -0,0 +1,150 @@ +// 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 = &TransportIPv6TrackerGroupProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &TransportIPv6TrackerGroupProfileParcelDataSource{} +) + +func NewTransportIPv6TrackerGroupProfileParcelDataSource() datasource.DataSource { + return &TransportIPv6TrackerGroupProfileParcelDataSource{} +} + +type TransportIPv6TrackerGroupProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *TransportIPv6TrackerGroupProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_ipv6_tracker_group_profile_parcel" +} + +func (d *TransportIPv6TrackerGroupProfileParcelDataSource) 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 IPv6 Tracker Group profile parcel.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "tracker_name": schema.StringAttribute{ + MarkdownDescription: "Tracker Name", + Computed: true, + }, + "tracker_name_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: "trackers ref list", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: "tracker ref list combine boolean and or", + Computed: true, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *TransportIPv6TrackerGroupProfileParcelDataSource) 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 *TransportIPv6TrackerGroupProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransportIPv6TrackerGroup + + // 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_ipv6_tracker_group_profile_parcel_test.go b/internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..d871658e --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go @@ -0,0 +1,100 @@ +// 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 TestAccDataSourceSdwanTransportIPv6TrackerGroupProfileParcel(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_ipv6_tracker_group_profile_parcel.test", "tracker_name", "TRACKER_GROUP_1")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_ipv6_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_ipv6_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanTransportIPv6TrackerGroupPrerequisitesProfileParcelConfig + testAccDataSourceSdwanTransportIPv6TrackerGroupProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanTransportIPv6TrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_transport_ipv6_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "2001:0:0:1::0" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "ipv6-interface" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanTransportIPv6TrackerGroupProfileParcelConfig() string { + config := `resource "sdwan_transport_ipv6_tracker_group_profile_parcel" "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 += ` tracker_name = "TRACKER_GROUP_1"` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_transport_ipv6_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_transport_ipv6_tracker_group_profile_parcel" "test" { + id = sdwan_transport_ipv6_tracker_group_profile_parcel.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_tracker_group_profile_parcel.go b/internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel.go new file mode 100644 index 00000000..e91d91f9 --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel.go @@ -0,0 +1,142 @@ +// 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 = &TransportTrackerGroupProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &TransportTrackerGroupProfileParcelDataSource{} +) + +func NewTransportTrackerGroupProfileParcelDataSource() datasource.DataSource { + return &TransportTrackerGroupProfileParcelDataSource{} +} + +type TransportTrackerGroupProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *TransportTrackerGroupProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_tracker_group_profile_parcel" +} + +func (d *TransportTrackerGroupProfileParcelDataSource) 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 Tracker Group profile parcel.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: "tracker parcel ref list", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: "tracker ref list combine boolean and or", + Computed: true, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *TransportTrackerGroupProfileParcelDataSource) 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 *TransportTrackerGroupProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config TransportTrackerGroup + + // 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_tracker_group_profile_parcel_test.go b/internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..243d7312 --- /dev/null +++ b/internal/provider/data_source_sdwan_transport_tracker_group_profile_parcel_test.go @@ -0,0 +1,98 @@ +// 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 TestAccDataSourceSdwanTransportTrackerGroupProfileParcel(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_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_transport_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanTransportTrackerGroupPrerequisitesProfileParcelConfig + testAccDataSourceSdwanTransportTrackerGroupProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanTransportTrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_transport_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "interface" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanTransportTrackerGroupProfileParcelConfig() string { + config := `resource "sdwan_transport_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id1` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_transport_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_transport_tracker_group_profile_parcel" "test" { + id = sdwan_transport_tracker_group_profile_parcel.test.id + feature_profile_id = sdwan_transport_feature_profile.test.id1 + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/model_sdwan_service_tracker_group_profile_parcel.go b/internal/provider/model_sdwan_service_tracker_group_profile_parcel.go new file mode 100644 index 00000000..18747f31 --- /dev/null +++ b/internal/provider/model_sdwan_service_tracker_group_profile_parcel.go @@ -0,0 +1,210 @@ +// 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 ServiceTrackerGroup 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"` + TrackerElements []ServiceTrackerGroupTrackerElements `tfsdk:"tracker_elements"` + TrackerBoolean types.String `tfsdk:"tracker_boolean"` + TrackerBooleanVariable types.String `tfsdk:"tracker_boolean_variable"` +} + +type ServiceTrackerGroupTrackerElements struct { + TrackerId types.String `tfsdk:"tracker_id"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data ServiceTrackerGroup) getModel() string { + return "service_tracker_group" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data ServiceTrackerGroup) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/service/%v/trackergroup", 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 ServiceTrackerGroup) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + + for _, item := range data.TrackerElements { + itemBody := "" + if !item.TrackerId.IsNull() { + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.value", item.TrackerId.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"trackerRefs.-1", itemBody) + } + + if !data.TrackerBooleanVariable.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "variable") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBooleanVariable.ValueString()) + } else if data.TrackerBoolean.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "default") + body, _ = sjson.Set(body, path+"combineBoolean.value", "or") + } else { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "global") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBoolean.ValueString()) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *ServiceTrackerGroup) 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." + if value := res.Get(path + "trackerRefs"); value.Exists() { + data.TrackerElements = make([]ServiceTrackerGroupTrackerElements, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := ServiceTrackerGroupTrackerElements{} + item.TrackerId = types.StringNull() + + if t := v.Get("trackerRef.refId.optionType"); t.Exists() { + va := v.Get("trackerRef.refId.value") + if t.String() == "global" { + item.TrackerId = types.StringValue(va.String()) + } + } + data.TrackerElements = append(data.TrackerElements, item) + return true + }) + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *ServiceTrackerGroup) 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." + for i := range data.TrackerElements { + keys := [...]string{} + keyValues := [...]string{} + keyValuesVariables := [...]string{} + + var r gjson.Result + res.Get(path + "trackerRefs").ForEach( + func(_, v gjson.Result) bool { + found := false + for ik := range keys { + tt := v.Get(keys[ik] + ".optionType").String() + vv := v.Get(keys[ik] + ".value").String() + if (tt == "variable" && vv == keyValuesVariables[ik]) || (tt == "global" && vv == keyValues[ik]) { + found = true + continue + } + found = false + break + } + if found { + r = v + return false + } + return true + }, + ) + data.TrackerElements[i].TrackerId = types.StringNull() + + if t := r.Get("trackerRef.refId.optionType"); t.Exists() { + va := r.Get("trackerRef.refId.value") + if t.String() == "global" { + data.TrackerElements[i].TrackerId = types.StringValue(va.String()) + } + } + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *ServiceTrackerGroup) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.TrackerElements) > 0 { + return false + } + if !data.TrackerBoolean.IsNull() { + return false + } + if !data.TrackerBooleanVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_transport_ipv6_tracker_group_profile_parcel.go b/internal/provider/model_sdwan_transport_ipv6_tracker_group_profile_parcel.go new file mode 100644 index 00000000..fb73d4f0 --- /dev/null +++ b/internal/provider/model_sdwan_transport_ipv6_tracker_group_profile_parcel.go @@ -0,0 +1,246 @@ +// 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 TransportIPv6TrackerGroup 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"` + TrackerName types.String `tfsdk:"tracker_name"` + TrackerNameVariable types.String `tfsdk:"tracker_name_variable"` + TrackerElements []TransportIPv6TrackerGroupTrackerElements `tfsdk:"tracker_elements"` + TrackerBoolean types.String `tfsdk:"tracker_boolean"` + TrackerBooleanVariable types.String `tfsdk:"tracker_boolean_variable"` +} + +type TransportIPv6TrackerGroupTrackerElements struct { + TrackerId types.String `tfsdk:"tracker_id"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data TransportIPv6TrackerGroup) getModel() string { + return "transport_ipv6_tracker_group" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data TransportIPv6TrackerGroup) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/transport/%v/ipv6-trackergroup", 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 TransportIPv6TrackerGroup) 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 !data.TrackerNameVariable.IsNull() { + body, _ = sjson.Set(body, path+"trackerGroupName.optionType", "variable") + body, _ = sjson.Set(body, path+"trackerGroupName.value", data.TrackerNameVariable.ValueString()) + } else if !data.TrackerName.IsNull() { + body, _ = sjson.Set(body, path+"trackerGroupName.optionType", "global") + body, _ = sjson.Set(body, path+"trackerGroupName.value", data.TrackerName.ValueString()) + } + + for _, item := range data.TrackerElements { + itemBody := "" + if !item.TrackerId.IsNull() { + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.value", item.TrackerId.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"trackerRefs.-1", itemBody) + } + + if !data.TrackerBooleanVariable.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "variable") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBooleanVariable.ValueString()) + } else if data.TrackerBoolean.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "default") + body, _ = sjson.Set(body, path+"combineBoolean.value", "or") + } else { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "global") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBoolean.ValueString()) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *TransportIPv6TrackerGroup) 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.TrackerName = types.StringNull() + data.TrackerNameVariable = types.StringNull() + if t := res.Get(path + "trackerGroupName.optionType"); t.Exists() { + va := res.Get(path + "trackerGroupName.value") + if t.String() == "variable" { + data.TrackerNameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerName = types.StringValue(va.String()) + } + } + if value := res.Get(path + "trackerRefs"); value.Exists() { + data.TrackerElements = make([]TransportIPv6TrackerGroupTrackerElements, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := TransportIPv6TrackerGroupTrackerElements{} + item.TrackerId = types.StringNull() + + if t := v.Get("trackerRef.refId.optionType"); t.Exists() { + va := v.Get("trackerRef.refId.value") + if t.String() == "global" { + item.TrackerId = types.StringValue(va.String()) + } + } + data.TrackerElements = append(data.TrackerElements, item) + return true + }) + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *TransportIPv6TrackerGroup) 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.TrackerName = types.StringNull() + data.TrackerNameVariable = types.StringNull() + if t := res.Get(path + "trackerGroupName.optionType"); t.Exists() { + va := res.Get(path + "trackerGroupName.value") + if t.String() == "variable" { + data.TrackerNameVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerName = types.StringValue(va.String()) + } + } + for i := range data.TrackerElements { + keys := [...]string{"trackerRef.refId"} + keyValues := [...]string{data.TrackerElements[i].TrackerId.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "trackerRefs").ForEach( + func(_, v gjson.Result) bool { + found := false + for ik := range keys { + tt := v.Get(keys[ik] + ".optionType").String() + vv := v.Get(keys[ik] + ".value").String() + if (tt == "variable" && vv == keyValuesVariables[ik]) || (tt == "global" && vv == keyValues[ik]) { + found = true + continue + } + found = false + break + } + if found { + r = v + return false + } + return true + }, + ) + data.TrackerElements[i].TrackerId = types.StringNull() + + if t := r.Get("trackerRef.refId.optionType"); t.Exists() { + va := r.Get("trackerRef.refId.value") + if t.String() == "global" { + data.TrackerElements[i].TrackerId = types.StringValue(va.String()) + } + } + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *TransportIPv6TrackerGroup) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if !data.TrackerName.IsNull() { + return false + } + if !data.TrackerNameVariable.IsNull() { + return false + } + if len(data.TrackerElements) > 0 { + return false + } + if !data.TrackerBoolean.IsNull() { + return false + } + if !data.TrackerBooleanVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_transport_tracker_group_profile_parcel.go b/internal/provider/model_sdwan_transport_tracker_group_profile_parcel.go new file mode 100644 index 00000000..277679ca --- /dev/null +++ b/internal/provider/model_sdwan_transport_tracker_group_profile_parcel.go @@ -0,0 +1,210 @@ +// 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 TransportTrackerGroup 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"` + TrackerElements []TransportTrackerGroupTrackerElements `tfsdk:"tracker_elements"` + TrackerBoolean types.String `tfsdk:"tracker_boolean"` + TrackerBooleanVariable types.String `tfsdk:"tracker_boolean_variable"` +} + +type TransportTrackerGroupTrackerElements struct { + TrackerId types.String `tfsdk:"tracker_id"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data TransportTrackerGroup) getModel() string { + return "transport_tracker_group" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data TransportTrackerGroup) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/transport/%v/trackergroup", 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 TransportTrackerGroup) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + + for _, item := range data.TrackerElements { + itemBody := "" + if !item.TrackerId.IsNull() { + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "trackerRef.refId.value", item.TrackerId.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"trackerRefs.-1", itemBody) + } + + if !data.TrackerBooleanVariable.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "variable") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBooleanVariable.ValueString()) + } else if data.TrackerBoolean.IsNull() { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "default") + body, _ = sjson.Set(body, path+"combineBoolean.value", "or") + } else { + body, _ = sjson.Set(body, path+"combineBoolean.optionType", "global") + body, _ = sjson.Set(body, path+"combineBoolean.value", data.TrackerBoolean.ValueString()) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *TransportTrackerGroup) 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." + if value := res.Get(path + "trackerRefs"); value.Exists() { + data.TrackerElements = make([]TransportTrackerGroupTrackerElements, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := TransportTrackerGroupTrackerElements{} + item.TrackerId = types.StringNull() + + if t := v.Get("trackerRef.refId.optionType"); t.Exists() { + va := v.Get("trackerRef.refId.value") + if t.String() == "global" { + item.TrackerId = types.StringValue(va.String()) + } + } + data.TrackerElements = append(data.TrackerElements, item) + return true + }) + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *TransportTrackerGroup) 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." + for i := range data.TrackerElements { + keys := [...]string{"trackerRef.refId"} + keyValues := [...]string{data.TrackerElements[i].TrackerId.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "trackerRefs").ForEach( + func(_, v gjson.Result) bool { + found := false + for ik := range keys { + tt := v.Get(keys[ik] + ".optionType").String() + vv := v.Get(keys[ik] + ".value").String() + if (tt == "variable" && vv == keyValuesVariables[ik]) || (tt == "global" && vv == keyValues[ik]) { + found = true + continue + } + found = false + break + } + if found { + r = v + return false + } + return true + }, + ) + data.TrackerElements[i].TrackerId = types.StringNull() + + if t := r.Get("trackerRef.refId.optionType"); t.Exists() { + va := r.Get("trackerRef.refId.value") + if t.String() == "global" { + data.TrackerElements[i].TrackerId = types.StringValue(va.String()) + } + } + } + data.TrackerBoolean = types.StringNull() + data.TrackerBooleanVariable = types.StringNull() + if t := res.Get(path + "combineBoolean.optionType"); t.Exists() { + va := res.Get(path + "combineBoolean.value") + if t.String() == "variable" { + data.TrackerBooleanVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.TrackerBoolean = types.StringValue(va.String()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *TransportTrackerGroup) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.TrackerElements) > 0 { + return false + } + if !data.TrackerBoolean.IsNull() { + return false + } + if !data.TrackerBooleanVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 378f16f0..eabf037f 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -289,6 +289,7 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewServiceLANVPNInterfaceIPSecProfileParcelResource, NewServiceLANVPNInterfaceSVIProfileParcelResource, NewServiceTrackerProfileParcelResource, + NewServiceTrackerGroupProfileParcelResource, NewSystemAAAProfileParcelResource, NewSystemBannerProfileParcelResource, NewSystemBasicProfileParcelResource, @@ -306,10 +307,12 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewSystemSecurityProfileParcelResource, NewSystemSNMPProfileParcelResource, NewTransportIPv6TrackerProfileParcelResource, + NewTransportIPv6TrackerGroupProfileParcelResource, NewTransportManagementVPNProfileParcelResource, NewTransportManagementVPNInterfaceEthernetProfileParcelResource, NewTransportRoutingBGPProfileParcelResource, NewTransportTrackerProfileParcelResource, + NewTransportTrackerGroupProfileParcelResource, NewTransportWANVPNProfileParcelResource, NewTransportWANVPNInterfaceCellularProfileParcelResource, NewTransportWANVPNInterfaceEthernetProfileParcelResource, @@ -438,6 +441,7 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewServiceLANVPNInterfaceIPSecProfileParcelDataSource, NewServiceLANVPNInterfaceSVIProfileParcelDataSource, NewServiceTrackerProfileParcelDataSource, + NewServiceTrackerGroupProfileParcelDataSource, NewSystemAAAProfileParcelDataSource, NewSystemBannerProfileParcelDataSource, NewSystemBasicProfileParcelDataSource, @@ -455,10 +459,12 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewSystemSecurityProfileParcelDataSource, NewSystemSNMPProfileParcelDataSource, NewTransportIPv6TrackerProfileParcelDataSource, + NewTransportIPv6TrackerGroupProfileParcelDataSource, NewTransportManagementVPNProfileParcelDataSource, NewTransportManagementVPNInterfaceEthernetProfileParcelDataSource, NewTransportRoutingBGPProfileParcelDataSource, NewTransportTrackerProfileParcelDataSource, + NewTransportTrackerGroupProfileParcelDataSource, NewTransportWANVPNProfileParcelDataSource, NewTransportWANVPNInterfaceCellularProfileParcelDataSource, NewTransportWANVPNInterfaceEthernetProfileParcelDataSource, diff --git a/internal/provider/resource_sdwan_service_tracker_group_profile_parcel.go b/internal/provider/resource_sdwan_service_tracker_group_profile_parcel.go new file mode 100644 index 00000000..f85e09ff --- /dev/null +++ b/internal/provider/resource_sdwan_service_tracker_group_profile_parcel.go @@ -0,0 +1,269 @@ +// 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" + "regexp" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "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 = &ServiceTrackerGroupProfileParcelResource{} +var _ resource.ResourceWithImportState = &ServiceTrackerGroupProfileParcelResource{} + +func NewServiceTrackerGroupProfileParcelResource() resource.Resource { + return &ServiceTrackerGroupProfileParcelResource{} +} + +type ServiceTrackerGroupProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *ServiceTrackerGroupProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_service_tracker_group_profile_parcel" +} + +func (r *ServiceTrackerGroupProfileParcelResource) 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 Service Tracker Group profile parcel.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tracker parcel ref list").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`), ""), + }, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tracker ref list combine boolean and or").AddStringEnumDescription("and", "or").AddDefaultValueDescription("or").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("and", "or"), + }, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *ServiceTrackerGroupProfileParcelResource) 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 *ServiceTrackerGroupProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan ServiceTrackerGroup + + // 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 *ServiceTrackerGroupProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ServiceTrackerGroup + + // 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) + } + + 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 *ServiceTrackerGroupProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state ServiceTrackerGroup + + // 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 *ServiceTrackerGroupProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state ServiceTrackerGroup + + // 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 *ServiceTrackerGroupProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_service_tracker_group_profile_parcel_test.go b/internal/provider/resource_sdwan_service_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..bfbdbdcb --- /dev/null +++ b/internal/provider/resource_sdwan_service_tracker_group_profile_parcel_test.go @@ -0,0 +1,108 @@ +// 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 TestAccSdwanServiceTrackerGroupProfileParcel(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_service_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_service_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanServiceTrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanServiceTrackerGroupProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanServiceTrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanServiceTrackerGroupProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanServiceTrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_service_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_service_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform test" + feature_profile_id = sdwan_service_feature_profile.test.id + tracker_name = "TRACKER_2" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + protocol = "tcp" + port = 123 + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "static-route" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanServiceTrackerGroupProfileParcelConfig_minimum() string { + config := `resource "sdwan_service_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_service_feature_profile.test.id` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanServiceTrackerGroupProfileParcelConfig_all() string { + config := `resource "sdwan_service_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_service_feature_profile.test.id` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_service_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel.go b/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel.go new file mode 100644 index 00000000..57ade3d4 --- /dev/null +++ b/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel.go @@ -0,0 +1,280 @@ +// 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" + "regexp" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "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 = &TransportIPv6TrackerGroupProfileParcelResource{} +var _ resource.ResourceWithImportState = &TransportIPv6TrackerGroupProfileParcelResource{} + +func NewTransportIPv6TrackerGroupProfileParcelResource() resource.Resource { + return &TransportIPv6TrackerGroupProfileParcelResource{} +} + +type TransportIPv6TrackerGroupProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *TransportIPv6TrackerGroupProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_ipv6_tracker_group_profile_parcel" +} + +func (r *TransportIPv6TrackerGroupProfileParcelResource) 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 IPv6 Tracker Group profile parcel.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "tracker_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Tracker Name").String, + Required: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 128), + }, + }, + "tracker_name_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("trackers ref list").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`), ""), + }, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tracker ref list combine boolean and or").AddStringEnumDescription("and", "or").AddDefaultValueDescription("or").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("and", "or"), + }, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *TransportIPv6TrackerGroupProfileParcelResource) 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 *TransportIPv6TrackerGroupProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransportIPv6TrackerGroup + + // 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 *TransportIPv6TrackerGroupProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransportIPv6TrackerGroup + + // 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) + } + + 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 *TransportIPv6TrackerGroupProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransportIPv6TrackerGroup + + // 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 *TransportIPv6TrackerGroupProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransportIPv6TrackerGroup + + // 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 *TransportIPv6TrackerGroupProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go b/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..7d22c1a4 --- /dev/null +++ b/internal/provider/resource_sdwan_transport_ipv6_tracker_group_profile_parcel_test.go @@ -0,0 +1,109 @@ +// 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 TestAccSdwanTransportIPv6TrackerGroupProfileParcel(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_ipv6_tracker_group_profile_parcel.test", "tracker_name", "TRACKER_GROUP_1")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_ipv6_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_ipv6_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanTransportIPv6TrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanTransportIPv6TrackerGroupProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanTransportIPv6TrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanTransportIPv6TrackerGroupProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanTransportIPv6TrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_transport_ipv6_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "2001:0:0:1::0" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "ipv6-interface" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanTransportIPv6TrackerGroupProfileParcelConfig_minimum() string { + config := `resource "sdwan_transport_ipv6_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id` + "\n" + config += ` tracker_name = "TRACKER_GROUP_1"` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanTransportIPv6TrackerGroupProfileParcelConfig_all() string { + config := `resource "sdwan_transport_ipv6_tracker_group_profile_parcel" "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 += ` tracker_name = "TRACKER_GROUP_1"` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_transport_ipv6_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel.go b/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel.go new file mode 100644 index 00000000..07afb3fc --- /dev/null +++ b/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel.go @@ -0,0 +1,269 @@ +// 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" + "regexp" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "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 = &TransportTrackerGroupProfileParcelResource{} +var _ resource.ResourceWithImportState = &TransportTrackerGroupProfileParcelResource{} + +func NewTransportTrackerGroupProfileParcelResource() resource.Resource { + return &TransportTrackerGroupProfileParcelResource{} +} + +type TransportTrackerGroupProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *TransportTrackerGroupProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_transport_tracker_group_profile_parcel" +} + +func (r *TransportTrackerGroupProfileParcelResource) 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 Tracker Group profile parcel.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the profile parcel", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the profile parcel", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the profile parcel", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the profile parcel", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "tracker_elements": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tracker parcel ref list").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tracker_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`), ""), + }, + }, + }, + }, + }, + "tracker_boolean": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tracker ref list combine boolean and or").AddStringEnumDescription("and", "or").AddDefaultValueDescription("or").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("and", "or"), + }, + }, + "tracker_boolean_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *TransportTrackerGroupProfileParcelResource) 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 *TransportTrackerGroupProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan TransportTrackerGroup + + // 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 *TransportTrackerGroupProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state TransportTrackerGroup + + // 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) + } + + 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 *TransportTrackerGroupProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state TransportTrackerGroup + + // 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 *TransportTrackerGroupProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state TransportTrackerGroup + + // 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 *TransportTrackerGroupProfileParcelResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} + +// End of section. //template:end import diff --git a/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel_test.go b/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel_test.go new file mode 100644 index 00000000..dd17415e --- /dev/null +++ b/internal/provider/resource_sdwan_transport_tracker_group_profile_parcel_test.go @@ -0,0 +1,106 @@ +// 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 TestAccSdwanTransportTrackerGroupProfileParcel(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_tracker_group_profile_parcel.test", "tracker_elements.0.tracker_id", "615d948f-34ee-4a2e-810e-a9bd8d3d48ec")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_transport_tracker_group_profile_parcel.test", "tracker_boolean", "or")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanTransportTrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanTransportTrackerGroupProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanTransportTrackerGroupPrerequisitesProfileParcelConfig + testAccSdwanTransportTrackerGroupProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanTransportTrackerGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_transport_feature_profile" "test" { + name = "TF_TEST" + description = "Terraform test" +} + +resource "sdwan_transport_tracker_profile_parcel" "test" { + name = "TF_TEST" + description = "Terraform Test" + feature_profile_id = sdwan_transport_feature_profile.test.id + tracker_name = "TRACKER_1" + endpoint_api_url = "google.com" + endpoint_dns_name = "google.com" + endpoint_ip = "1.2.3.4" + interval = 30 + multiplier = 3 + threshold = 300 + endpoint_tracker_type = "interface" + tracker_type = "endpoint" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanTransportTrackerGroupProfileParcelConfig_minimum() string { + config := `resource "sdwan_transport_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id1` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanTransportTrackerGroupProfileParcelConfig_all() string { + config := `resource "sdwan_transport_tracker_group_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_transport_feature_profile.test.id1` + "\n" + config += ` tracker_elements = [{` + "\n" + config += ` tracker_id = sdwan_transport_tracker_profile_parcel.test.id` + "\n" + config += ` }]` + "\n" + config += ` tracker_boolean = "or"` + "\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 b427ee30..eec561a3 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -10,6 +10,9 @@ description: |- ## 0.3.14 (unreleased) - Add `sdwan_transport_tracker_profile_parcel` resource and data source +- Add `sdwan_service_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_ipv6_tracker_group_profile_parcel` resource and data source +- Add `sdwan_transport_tracker_group_profile_parcel` resource and data source ## 0.3.13