diff --git a/docs/data-sources/policy_object_color_profile_parcel.md b/docs/data-sources/policy_object_color_list_profile_parcel.md similarity index 68% rename from docs/data-sources/policy_object_color_profile_parcel.md rename to docs/data-sources/policy_object_color_list_profile_parcel.md index b3397b90..4686d0ae 100644 --- a/docs/data-sources/policy_object_color_profile_parcel.md +++ b/docs/data-sources/policy_object_color_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_color_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_color_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Color profile parcel. + This data source can read the Policy Object Color List profile parcel. --- -# sdwan_policy_object_color_profile_parcel (Data Source) +# sdwan_policy_object_color_list_profile_parcel (Data Source) -This data source can read the Policy Object Color profile parcel. +This data source can read the Policy Object Color List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_color_profile_parcel" "example" { +data "sdwan_policy_object_color_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } diff --git a/docs/data-sources/policy_object_data_prefix_profile_parcel.md b/docs/data-sources/policy_object_data_ipv4_prefix_list_profile_parcel.md similarity index 68% rename from docs/data-sources/policy_object_data_prefix_profile_parcel.md rename to docs/data-sources/policy_object_data_ipv4_prefix_list_profile_parcel.md index af07f4c3..5d065c5a 100644 --- a/docs/data-sources/policy_object_data_prefix_profile_parcel.md +++ b/docs/data-sources/policy_object_data_ipv4_prefix_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_data_prefix_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Data Prefix profile parcel. + This data source can read the Policy Object Data IPv4 Prefix List profile parcel. --- -# sdwan_policy_object_data_prefix_profile_parcel (Data Source) +# sdwan_policy_object_data_ipv4_prefix_list_profile_parcel (Data Source) -This data source can read the Policy Object Data Prefix profile parcel. +This data source can read the Policy Object Data IPv4 Prefix List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_data_prefix_profile_parcel" "example" { +data "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } diff --git a/docs/data-sources/policy_object_data_ipv6_prefix_profile_parcel.md b/docs/data-sources/policy_object_data_ipv6_prefix_list_profile_parcel.md similarity index 67% rename from docs/data-sources/policy_object_data_ipv6_prefix_profile_parcel.md rename to docs/data-sources/policy_object_data_ipv6_prefix_list_profile_parcel.md index 7bec7a45..9e78716d 100644 --- a/docs/data-sources/policy_object_data_ipv6_prefix_profile_parcel.md +++ b/docs/data-sources/policy_object_data_ipv6_prefix_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_data_ipv6_prefix_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Data IPv6 Prefix profile parcel. + This data source can read the Policy Object Data IPv6 Prefix List profile parcel. --- -# sdwan_policy_object_data_ipv6_prefix_profile_parcel (Data Source) +# sdwan_policy_object_data_ipv6_prefix_list_profile_parcel (Data Source) -This data source can read the Policy Object Data IPv6 Prefix profile parcel. +This data source can read the Policy Object Data IPv6 Prefix List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_data_ipv6_prefix_profile_parcel" "example" { +data "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } diff --git a/docs/data-sources/policy_object_expanded_community_profile_parcel.md b/docs/data-sources/policy_object_expanded_community_list_profile_parcel.md similarity index 69% rename from docs/data-sources/policy_object_expanded_community_profile_parcel.md rename to docs/data-sources/policy_object_expanded_community_list_profile_parcel.md index 388e42d1..f8076889 100644 --- a/docs/data-sources/policy_object_expanded_community_profile_parcel.md +++ b/docs/data-sources/policy_object_expanded_community_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_expanded_community_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_expanded_community_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Expanded Community profile parcel. + This data source can read the Policy Object Expanded Community List profile parcel. --- -# sdwan_policy_object_expanded_community_profile_parcel (Data Source) +# sdwan_policy_object_expanded_community_list_profile_parcel (Data Source) -This data source can read the Policy Object Expanded Community profile parcel. +This data source can read the Policy Object Expanded Community List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_expanded_community_profile_parcel" "example" { +data "sdwan_policy_object_expanded_community_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } diff --git a/docs/data-sources/policy_object_extended_community_profile_parcel.md b/docs/data-sources/policy_object_extended_community_list_profile_parcel.md similarity index 72% rename from docs/data-sources/policy_object_extended_community_profile_parcel.md rename to docs/data-sources/policy_object_extended_community_list_profile_parcel.md index 97952c0b..acfb55de 100644 --- a/docs/data-sources/policy_object_extended_community_profile_parcel.md +++ b/docs/data-sources/policy_object_extended_community_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_extended_community_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_extended_community_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Extended Community profile parcel. + This data source can read the Policy Object Extended Community List profile parcel. --- -# sdwan_policy_object_extended_community_profile_parcel (Data Source) +# sdwan_policy_object_extended_community_list_profile_parcel (Data Source) -This data source can read the Policy Object Extended Community profile parcel. +This data source can read the Policy Object Extended Community List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_extended_community_profile_parcel" "example" { +data "sdwan_policy_object_extended_community_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } diff --git a/docs/data-sources/policy_object_prefix_profile_parcel.md b/docs/data-sources/policy_object_ipv4_prefix_list_profile_parcel.md similarity index 63% rename from docs/data-sources/policy_object_prefix_profile_parcel.md rename to docs/data-sources/policy_object_ipv4_prefix_list_profile_parcel.md index 7fb96547..9664bb51 100644 --- a/docs/data-sources/policy_object_prefix_profile_parcel.md +++ b/docs/data-sources/policy_object_ipv4_prefix_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_prefix_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_ipv4_prefix_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object Prefix profile parcel. + This data source can read the Policy Object IPv4 Prefix List profile parcel. --- -# sdwan_policy_object_prefix_profile_parcel (Data Source) +# sdwan_policy_object_ipv4_prefix_list_profile_parcel (Data Source) -This data source can read the Policy Object Prefix profile parcel. +This data source can read the Policy Object IPv4 Prefix List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_prefix_profile_parcel" "example" { +data "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } @@ -39,7 +39,7 @@ data "sdwan_policy_object_prefix_profile_parcel" "example" { Read-Only: -- `ge_range_prefix_length` (Number) IPv4 prefix length with ge range operator +- `ge` (Number) IPv4 prefix length with ge range operator - `ipv4_address` (String) IPv4 address - `ipv4_prefix_length` (Number) IPv4 prefix length -- `le_range_prefix_length` (Number) IPv4 prefix length with le range operator +- `le` (Number) IPv4 prefix length with le range operator diff --git a/docs/data-sources/policy_object_ipv6_prefix_profile_parcel.md b/docs/data-sources/policy_object_ipv6_prefix_list_profile_parcel.md similarity index 62% rename from docs/data-sources/policy_object_ipv6_prefix_profile_parcel.md rename to docs/data-sources/policy_object_ipv6_prefix_list_profile_parcel.md index 8f363975..faa16c98 100644 --- a/docs/data-sources/policy_object_ipv6_prefix_profile_parcel.md +++ b/docs/data-sources/policy_object_ipv6_prefix_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_ipv6_prefix_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_ipv6_prefix_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object IPv6 Prefix profile parcel. + This data source can read the Policy Object IPv6 Prefix List profile parcel. --- -# sdwan_policy_object_ipv6_prefix_profile_parcel (Data Source) +# sdwan_policy_object_ipv6_prefix_list_profile_parcel (Data Source) -This data source can read the Policy Object IPv6 Prefix profile parcel. +This data source can read the Policy Object IPv6 Prefix List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_ipv6_prefix_profile_parcel" "example" { +data "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } @@ -39,7 +39,7 @@ data "sdwan_policy_object_ipv6_prefix_profile_parcel" "example" { Read-Only: -- `ge_range_prefix_length` (Number) IPv6 prefix length with ge range operator +- `ge` (Number) IPv6 prefix length with ge range operator - `ipv6_address` (String) IPv6 address - `ipv6_prefix_length` (Number) IPv6 prefix length -- `le_range_prefix_length` (Number) IPv6 prefix length with le range operator +- `le` (Number) IPv6 prefix length with le range operator diff --git a/docs/data-sources/policy_object_policer_profile_parcel.md b/docs/data-sources/policy_object_policer_profile_parcel.md index 2cdae9ec..e1cbe08e 100644 --- a/docs/data-sources/policy_object_policer_profile_parcel.md +++ b/docs/data-sources/policy_object_policer_profile_parcel.md @@ -40,5 +40,5 @@ data "sdwan_policy_object_policer_profile_parcel" "example" { Read-Only: - `burst_bytes` (Number) Burst (Bytes) +- `exceed_action` (String) Exceed options such as Drop or Remark - `rate_bps` (Number) Rate (bps) -- `select_value` (String) Exceed options such as Drop or Remark diff --git a/docs/data-sources/policy_object_tloc_profile_parcel.md b/docs/data-sources/policy_object_tloc_list_profile_parcel.md similarity index 69% rename from docs/data-sources/policy_object_tloc_profile_parcel.md rename to docs/data-sources/policy_object_tloc_list_profile_parcel.md index dd4223cf..342a27c0 100644 --- a/docs/data-sources/policy_object_tloc_profile_parcel.md +++ b/docs/data-sources/policy_object_tloc_list_profile_parcel.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_tloc_profile_parcel Data Source - terraform-provider-sdwan" +page_title: "sdwan_policy_object_tloc_list_profile_parcel Data Source - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This data source can read the Policy Object TLOC profile parcel. + This data source can read the Policy Object TLOC List profile parcel. --- -# sdwan_policy_object_tloc_profile_parcel (Data Source) +# sdwan_policy_object_tloc_list_profile_parcel (Data Source) -This data source can read the Policy Object TLOC profile parcel. +This data source can read the Policy Object TLOC List profile parcel. ## Example Usage ```terraform -data "sdwan_policy_object_tloc_profile_parcel" "example" { +data "sdwan_policy_object_tloc_list_profile_parcel" "example" { id = "f6b2c44c-693c-4763-b010-895aa3d236bd" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" } @@ -42,4 +42,4 @@ Read-Only: - `color` (String) color - `encapsulation` (String) encapsulation - `preference` (String) Preference -- `tloc` (String) tloc +- `tloc_ip` (String) tloc diff --git a/docs/resources/policy_object_color_profile_parcel.md b/docs/resources/policy_object_color_list_profile_parcel.md similarity index 73% rename from docs/resources/policy_object_color_profile_parcel.md rename to docs/resources/policy_object_color_list_profile_parcel.md index 78c4b580..76c71f96 100644 --- a/docs/resources/policy_object_color_profile_parcel.md +++ b/docs/resources/policy_object_color_list_profile_parcel.md @@ -1,21 +1,21 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_color_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_color_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Color profile parcel. + This resource can manage a Policy Object Color List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_color_profile_parcel (Resource) +# sdwan_policy_object_color_list_profile_parcel (Resource) -This resource can manage a Policy Object Color profile parcel. +This resource can manage a Policy Object Color List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_color_profile_parcel" "example" { +resource "sdwan_policy_object_color_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" @@ -57,5 +57,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_color_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_color_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_data_prefix_profile_parcel.md b/docs/resources/policy_object_data_ipv4_prefix_list_profile_parcel.md similarity index 69% rename from docs/resources/policy_object_data_prefix_profile_parcel.md rename to docs/resources/policy_object_data_ipv4_prefix_list_profile_parcel.md index 0a814689..cc00d579 100644 --- a/docs/resources/policy_object_data_prefix_profile_parcel.md +++ b/docs/resources/policy_object_data_ipv4_prefix_list_profile_parcel.md @@ -1,21 +1,21 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_data_prefix_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Data Prefix profile parcel. + This resource can manage a Policy Object Data IPv4 Prefix List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_data_prefix_profile_parcel (Resource) +# sdwan_policy_object_data_ipv4_prefix_list_profile_parcel (Resource) -This resource can manage a Policy Object Data Prefix profile parcel. +This resource can manage a Policy Object Data IPv4 Prefix List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_data_prefix_profile_parcel" "example" { +resource "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" @@ -60,5 +60,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_data_prefix_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_data_ipv6_prefix_profile_parcel.md b/docs/resources/policy_object_data_ipv6_prefix_list_profile_parcel.md similarity index 69% rename from docs/resources/policy_object_data_ipv6_prefix_profile_parcel.md rename to docs/resources/policy_object_data_ipv6_prefix_list_profile_parcel.md index 0b6ba185..d87ed08b 100644 --- a/docs/resources/policy_object_data_ipv6_prefix_profile_parcel.md +++ b/docs/resources/policy_object_data_ipv6_prefix_list_profile_parcel.md @@ -1,21 +1,21 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_data_ipv6_prefix_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Data IPv6 Prefix profile parcel. + This resource can manage a Policy Object Data IPv6 Prefix List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_data_ipv6_prefix_profile_parcel (Resource) +# sdwan_policy_object_data_ipv6_prefix_list_profile_parcel (Resource) -This resource can manage a Policy Object Data IPv6 Prefix profile parcel. +This resource can manage a Policy Object Data IPv6 Prefix List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_data_ipv6_prefix_profile_parcel" "example" { +resource "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" @@ -60,5 +60,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_data_ipv6_prefix_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_expanded_community_profile_parcel.md b/docs/resources/policy_object_expanded_community_list_profile_parcel.md similarity index 64% rename from docs/resources/policy_object_expanded_community_profile_parcel.md rename to docs/resources/policy_object_expanded_community_list_profile_parcel.md index bdad2f82..ac5053b4 100644 --- a/docs/resources/policy_object_expanded_community_profile_parcel.md +++ b/docs/resources/policy_object_expanded_community_list_profile_parcel.md @@ -1,21 +1,21 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_expanded_community_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_expanded_community_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Expanded Community profile parcel. + This resource can manage a Policy Object Expanded Community List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_expanded_community_profile_parcel (Resource) +# sdwan_policy_object_expanded_community_list_profile_parcel (Resource) -This resource can manage a Policy Object Expanded Community profile parcel. +This resource can manage a Policy Object Expanded Community List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_expanded_community_profile_parcel" "example" { +resource "sdwan_policy_object_expanded_community_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" @@ -47,5 +47,5 @@ resource "sdwan_policy_object_expanded_community_profile_parcel" "example" { Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_expanded_community_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_expanded_community_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_extended_community_profile_parcel.md b/docs/resources/policy_object_extended_community_list_profile_parcel.md similarity index 67% rename from docs/resources/policy_object_extended_community_profile_parcel.md rename to docs/resources/policy_object_extended_community_list_profile_parcel.md index 19a42bb3..5e74ea1e 100644 --- a/docs/resources/policy_object_extended_community_profile_parcel.md +++ b/docs/resources/policy_object_extended_community_list_profile_parcel.md @@ -1,21 +1,21 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_extended_community_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_extended_community_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Extended Community profile parcel. + This resource can manage a Policy Object Extended Community List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_extended_community_profile_parcel (Resource) +# sdwan_policy_object_extended_community_list_profile_parcel (Resource) -This resource can manage a Policy Object Extended Community profile parcel. +This resource can manage a Policy Object Extended Community List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_extended_community_profile_parcel" "example" { +resource "sdwan_policy_object_extended_community_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" @@ -57,5 +57,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_extended_community_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_extended_community_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_prefix_profile_parcel.md b/docs/resources/policy_object_ipv4_prefix_list_profile_parcel.md similarity index 61% rename from docs/resources/policy_object_prefix_profile_parcel.md rename to docs/resources/policy_object_ipv4_prefix_list_profile_parcel.md index 0ddea057..5d26736f 100644 --- a/docs/resources/policy_object_prefix_profile_parcel.md +++ b/docs/resources/policy_object_ipv4_prefix_list_profile_parcel.md @@ -1,30 +1,30 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_prefix_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_ipv4_prefix_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object Prefix profile parcel. + This resource can manage a Policy Object IPv4 Prefix List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_prefix_profile_parcel (Resource) +# sdwan_policy_object_ipv4_prefix_list_profile_parcel (Resource) -This resource can manage a Policy Object Prefix profile parcel. +This resource can manage a Policy Object IPv4 Prefix List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_prefix_profile_parcel" "example" { +resource "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" entries = [ { - ipv4_address = "10.0.0.0" - ipv4_prefix_length = 8 - le_range_prefix_length = 24 - ge_range_prefix_length = 16 + ipv4_address = "10.0.0.0" + ipv4_prefix_length = 8 + le = 24 + ge = 16 } ] } @@ -53,12 +53,12 @@ resource "sdwan_policy_object_prefix_profile_parcel" "example" { Optional: -- `ge_range_prefix_length` (Number) IPv4 prefix length with ge range operator +- `ge` (Number) IPv4 prefix length with ge range operator - Range: `1`-`32` - `ipv4_address` (String) IPv4 address - `ipv4_prefix_length` (Number) IPv4 prefix length - Range: `0`-`32` -- `le_range_prefix_length` (Number) IPv4 prefix length with le range operator +- `le` (Number) IPv4 prefix length with le range operator - Range: `1`-`32` ## Import @@ -66,5 +66,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_prefix_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_ipv4_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_ipv6_prefix_profile_parcel.md b/docs/resources/policy_object_ipv6_prefix_list_profile_parcel.md similarity index 59% rename from docs/resources/policy_object_ipv6_prefix_profile_parcel.md rename to docs/resources/policy_object_ipv6_prefix_list_profile_parcel.md index 175635e3..18168101 100644 --- a/docs/resources/policy_object_ipv6_prefix_profile_parcel.md +++ b/docs/resources/policy_object_ipv6_prefix_list_profile_parcel.md @@ -1,30 +1,30 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_ipv6_prefix_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_ipv6_prefix_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object IPv6 Prefix profile parcel. + This resource can manage a Policy Object IPv6 Prefix List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_ipv6_prefix_profile_parcel (Resource) +# sdwan_policy_object_ipv6_prefix_list_profile_parcel (Resource) -This resource can manage a Policy Object IPv6 Prefix profile parcel. +This resource can manage a Policy Object IPv6 Prefix List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_ipv6_prefix_profile_parcel" "example" { +resource "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" entries = [ { - ipv6_address = "2001:db8:85a3::8a2e:370:7334" - ipv6_prefix_length = 64 - le_range_prefix_length = 100 - ge_range_prefix_length = 70 + ipv6_address = "2001:db8:85a3::8a2e:370:7334" + ipv6_prefix_length = 64 + le = 100 + ge = 70 } ] } @@ -53,12 +53,12 @@ resource "sdwan_policy_object_ipv6_prefix_profile_parcel" "example" { Optional: -- `ge_range_prefix_length` (Number) IPv6 prefix length with ge range operator +- `ge` (Number) IPv6 prefix length with ge range operator - Range: `1`-`128` - `ipv6_address` (String) IPv6 address - `ipv6_prefix_length` (Number) IPv6 prefix length - Range: `0`-`128` -- `le_range_prefix_length` (Number) IPv6 prefix length with le range operator +- `le` (Number) IPv6 prefix length with le range operator - Range: `1`-`128` ## Import @@ -66,5 +66,5 @@ Optional: Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_ipv6_prefix_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_ipv6_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/docs/resources/policy_object_policer_profile_parcel.md b/docs/resources/policy_object_policer_profile_parcel.md index 7616a5bf..56dcd33f 100644 --- a/docs/resources/policy_object_policer_profile_parcel.md +++ b/docs/resources/policy_object_policer_profile_parcel.md @@ -21,9 +21,9 @@ resource "sdwan_policy_object_policer_profile_parcel" "example" { feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" entries = [ { - burst_bytes = 56500 - select_value = "remark" - rate_bps = 60000 + burst_bytes = 56500 + exceed_action = "remark" + rate_bps = 60000 } ] } @@ -54,10 +54,10 @@ Optional: - `burst_bytes` (Number) Burst (Bytes) - Range: `15000`-`10000000` +- `exceed_action` (String) Exceed options such as Drop or Remark + - Choices: `drop`, `remark` - `rate_bps` (Number) Rate (bps) - Range: `8`-`100000000000` -- `select_value` (String) Exceed options such as Drop or Remark - - Choices: `drop`, `remark` ## Import diff --git a/docs/resources/policy_object_tloc_profile_parcel.md b/docs/resources/policy_object_tloc_list_profile_parcel.md similarity index 73% rename from docs/resources/policy_object_tloc_profile_parcel.md rename to docs/resources/policy_object_tloc_list_profile_parcel.md index c32c4e2c..fdd3241b 100644 --- a/docs/resources/policy_object_tloc_profile_parcel.md +++ b/docs/resources/policy_object_tloc_list_profile_parcel.md @@ -1,27 +1,27 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "sdwan_policy_object_tloc_profile_parcel Resource - terraform-provider-sdwan" +page_title: "sdwan_policy_object_tloc_list_profile_parcel Resource - terraform-provider-sdwan" subcategory: "Profile Parcels" description: |- - This resource can manage a Policy Object TLOC profile parcel. + This resource can manage a Policy Object TLOC List profile parcel. Minimum SD-WAN Manager version: 20.12.0 --- -# sdwan_policy_object_tloc_profile_parcel (Resource) +# sdwan_policy_object_tloc_list_profile_parcel (Resource) -This resource can manage a Policy Object TLOC profile parcel. +This resource can manage a Policy Object TLOC List profile parcel. - Minimum SD-WAN Manager version: `20.12.0` ## Example Usage ```terraform -resource "sdwan_policy_object_tloc_profile_parcel" "example" { +resource "sdwan_policy_object_tloc_list_profile_parcel" "example" { name = "Example" description = "My Example" feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" entries = [ { - tloc = "10.0.0.0" + tloc_ip = "10.0.0.0" color = "3g" encapsulation = "gre" preference = "33" @@ -58,12 +58,12 @@ Optional: - `encapsulation` (String) encapsulation - Choices: `ipsec`, `gre` - `preference` (String) Preference -- `tloc` (String) tloc +- `tloc_ip` (String) tloc ## Import Import is supported using the following syntax: ```shell -terraform import sdwan_policy_object_tloc_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +terraform import sdwan_policy_object_tloc_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" ``` diff --git a/examples/data-sources/sdwan_policy_object_color_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_color_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..af5e48f5 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_color_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_color_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..3e6ac963 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..06f3df4e --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_expanded_community_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_expanded_community_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..12edef1b --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_expanded_community_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_expanded_community_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_extended_community_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_extended_community_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..b5fe70f1 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_extended_community_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_extended_community_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..ce8f8c88 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..affc22e4 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_tloc_list_profile_parcel/data-source.tf b/examples/data-sources/sdwan_policy_object_tloc_list_profile_parcel/data-source.tf new file mode 100644 index 00000000..1373a48d --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_tloc_list_profile_parcel/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_tloc_list_profile_parcel" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/resources/sdwan_policy_object_color_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_color_list_profile_parcel/import.sh new file mode 100644 index 00000000..056b11dd --- /dev/null +++ b/examples/resources/sdwan_policy_object_color_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_color_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_color_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_color_list_profile_parcel/resource.tf new file mode 100644 index 00000000..bb50af90 --- /dev/null +++ b/examples/resources/sdwan_policy_object_color_list_profile_parcel/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_color_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + color = "blue" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/import.sh new file mode 100644 index 00000000..c7c395ca --- /dev/null +++ b/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/resource.tf new file mode 100644 index 00000000..5f403724 --- /dev/null +++ b/examples/resources/sdwan_policy_object_data_ipv4_prefix_list_profile_parcel/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ipv4_address = "10.0.0.0" + ipv4_prefix_length = 8 + } + ] +} diff --git a/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/import.sh new file mode 100644 index 00000000..682e381c --- /dev/null +++ b/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/resource.tf new file mode 100644 index 00000000..56284aa8 --- /dev/null +++ b/examples/resources/sdwan_policy_object_data_ipv6_prefix_list_profile_parcel/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ipv6_address = "2001:db8:85a3::8a2e:370:7334" + ipv6_prefix_length = 64 + } + ] +} diff --git a/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/import.sh new file mode 100644 index 00000000..31aed67f --- /dev/null +++ b/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_expanded_community_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/resource.tf new file mode 100644 index 00000000..358fc731 --- /dev/null +++ b/examples/resources/sdwan_policy_object_expanded_community_list_profile_parcel/resource.tf @@ -0,0 +1,6 @@ +resource "sdwan_policy_object_expanded_community_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + expanded_community_lists = ["abcd"] +} diff --git a/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/import.sh new file mode 100644 index 00000000..2e4a7b14 --- /dev/null +++ b/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_extended_community_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/resource.tf new file mode 100644 index 00000000..fe3da1c1 --- /dev/null +++ b/examples/resources/sdwan_policy_object_extended_community_list_profile_parcel/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_extended_community_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + extended_community = "soo 10.0.0.1:30" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/import.sh new file mode 100644 index 00000000..4a91ea84 --- /dev/null +++ b/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_ipv4_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/resource.tf new file mode 100644 index 00000000..d7ac927a --- /dev/null +++ b/examples/resources/sdwan_policy_object_ipv4_prefix_list_profile_parcel/resource.tf @@ -0,0 +1,13 @@ +resource "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ipv4_address = "10.0.0.0" + ipv4_prefix_length = 8 + le = 24 + ge = 16 + } + ] +} diff --git a/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/import.sh new file mode 100644 index 00000000..2e556cb5 --- /dev/null +++ b/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_ipv6_prefix_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/resource.tf new file mode 100644 index 00000000..53417120 --- /dev/null +++ b/examples/resources/sdwan_policy_object_ipv6_prefix_list_profile_parcel/resource.tf @@ -0,0 +1,13 @@ +resource "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ipv6_address = "2001:db8:85a3::8a2e:370:7334" + ipv6_prefix_length = 64 + le = 100 + ge = 70 + } + ] +} diff --git a/examples/resources/sdwan_policy_object_policer_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_policer_profile_parcel/resource.tf index 11841bba..ebd5c5f6 100644 --- a/examples/resources/sdwan_policy_object_policer_profile_parcel/resource.tf +++ b/examples/resources/sdwan_policy_object_policer_profile_parcel/resource.tf @@ -4,9 +4,9 @@ resource "sdwan_policy_object_policer_profile_parcel" "example" { feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" entries = [ { - burst_bytes = 56500 - select_value = "remark" - rate_bps = 60000 + burst_bytes = 56500 + exceed_action = "remark" + rate_bps = 60000 } ] } diff --git a/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/import.sh b/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/import.sh new file mode 100644 index 00000000..9faa9b1a --- /dev/null +++ b/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_tloc_list_profile_parcel.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/resource.tf b/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/resource.tf new file mode 100644 index 00000000..c2f06817 --- /dev/null +++ b/examples/resources/sdwan_policy_object_tloc_list_profile_parcel/resource.tf @@ -0,0 +1,13 @@ +resource "sdwan_policy_object_tloc_list_profile_parcel" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + tloc_ip = "10.0.0.0" + color = "3g" + encapsulation = "gre" + preference = "33" + } + ] +} diff --git a/gen/definitions/profile_parcels/policy_object_color.yaml b/gen/definitions/profile_parcels/policy_object_color_list.yaml similarity index 94% rename from gen/definitions/profile_parcels/policy_object_color.yaml rename to gen/definitions/profile_parcels/policy_object_color_list.yaml index f3f66f00..62b15ea9 100644 --- a/gen/definitions/profile_parcels/policy_object_color.yaml +++ b/gen/definitions/profile_parcels/policy_object_color_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Color +name: Policy Object Color List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/color minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] diff --git a/gen/definitions/profile_parcels/policy_object_data_prefix.yaml b/gen/definitions/profile_parcels/policy_object_data_ipv4_prefix_list.yaml similarity index 94% rename from gen/definitions/profile_parcels/policy_object_data_prefix.yaml rename to gen/definitions/profile_parcels/policy_object_data_ipv4_prefix_list.yaml index c420902e..ed9a7f61 100644 --- a/gen/definitions/profile_parcels/policy_object_data_prefix.yaml +++ b/gen/definitions/profile_parcels/policy_object_data_ipv4_prefix_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Data Prefix +name: Policy Object Data IPv4 Prefix List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/data-prefix minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] diff --git a/gen/definitions/profile_parcels/policy_object_data_ipv6_prefix.yaml b/gen/definitions/profile_parcels/policy_object_data_ipv6_prefix_list.yaml similarity index 94% rename from gen/definitions/profile_parcels/policy_object_data_ipv6_prefix.yaml rename to gen/definitions/profile_parcels/policy_object_data_ipv6_prefix_list.yaml index 3b97f95b..e6c8ddbd 100644 --- a/gen/definitions/profile_parcels/policy_object_data_ipv6_prefix.yaml +++ b/gen/definitions/profile_parcels/policy_object_data_ipv6_prefix_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Data IPv6 Prefix +name: Policy Object Data IPv6 Prefix List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/data-ipv6-prefix minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] diff --git a/gen/definitions/profile_parcels/policy_object_expanded_community.yaml b/gen/definitions/profile_parcels/policy_object_expanded_community_list.yaml similarity index 92% rename from gen/definitions/profile_parcels/policy_object_expanded_community.yaml rename to gen/definitions/profile_parcels/policy_object_expanded_community_list.yaml index 22d67bed..5192b1b3 100644 --- a/gen/definitions/profile_parcels/policy_object_expanded_community.yaml +++ b/gen/definitions/profile_parcels/policy_object_expanded_community_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Expanded Community +name: Policy Object Expanded Community List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/expanded-community minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] diff --git a/gen/definitions/profile_parcels/policy_object_extended_community.yaml b/gen/definitions/profile_parcels/policy_object_extended_community_list.yaml similarity index 93% rename from gen/definitions/profile_parcels/policy_object_extended_community.yaml rename to gen/definitions/profile_parcels/policy_object_extended_community_list.yaml index 8fd6ed85..3f9c8370 100644 --- a/gen/definitions/profile_parcels/policy_object_extended_community.yaml +++ b/gen/definitions/profile_parcels/policy_object_extended_community_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Extended Community +name: Policy Object Extended Community List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/ext-community minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] diff --git a/gen/definitions/profile_parcels/policy_object_prefix.yaml b/gen/definitions/profile_parcels/policy_object_ipv4_prefix_list.yaml similarity index 91% rename from gen/definitions/profile_parcels/policy_object_prefix.yaml rename to gen/definitions/profile_parcels/policy_object_ipv4_prefix_list.yaml index e699b4c9..00c0b658 100644 --- a/gen/definitions/profile_parcels/policy_object_prefix.yaml +++ b/gen/definitions/profile_parcels/policy_object_ipv4_prefix_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object Prefix +name: Policy Object IPv4 Prefix List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/prefix minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] @@ -25,6 +25,8 @@ attributes: example: 8 minimum_test_value: '8' - model_name: leRangePrefixLength + tf_name: le example: 24 - model_name: geRangePrefixLength + tf_name: ge example: 16 diff --git a/gen/definitions/profile_parcels/policy_object_ipv6_prefix.yaml b/gen/definitions/profile_parcels/policy_object_ipv6_prefix_list.yaml similarity index 92% rename from gen/definitions/profile_parcels/policy_object_ipv6_prefix.yaml rename to gen/definitions/profile_parcels/policy_object_ipv6_prefix_list.yaml index 5864c030..07fd1d1c 100644 --- a/gen/definitions/profile_parcels/policy_object_ipv6_prefix.yaml +++ b/gen/definitions/profile_parcels/policy_object_ipv6_prefix_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object IPv6 Prefix +name: Policy Object IPv6 Prefix List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/ipv6-prefix minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] @@ -25,6 +25,8 @@ attributes: example: 64 minimum_test_value: '64' - model_name: leRangePrefixLength + tf_name: le example: 100 - model_name: geRangePrefixLength + tf_name: ge example: 70 diff --git a/gen/definitions/profile_parcels/policy_object_policer.yaml b/gen/definitions/profile_parcels/policy_object_policer.yaml index 2cadf673..63a93993 100644 --- a/gen/definitions/profile_parcels/policy_object_policer.yaml +++ b/gen/definitions/profile_parcels/policy_object_policer.yaml @@ -21,7 +21,7 @@ attributes: example: 56500 minimum_test_value: '56500' - model_name: exceed - tf_name: select_value + tf_name: exceed_action id: true mandatory: true example: remark diff --git a/gen/definitions/profile_parcels/policy_object_tloc.yaml b/gen/definitions/profile_parcels/policy_object_tloc_list.yaml similarity index 94% rename from gen/definitions/profile_parcels/policy_object_tloc.yaml rename to gen/definitions/profile_parcels/policy_object_tloc_list.yaml index 680d79a7..0b9c42c2 100644 --- a/gen/definitions/profile_parcels/policy_object_tloc.yaml +++ b/gen/definitions/profile_parcels/policy_object_tloc_list.yaml @@ -1,5 +1,5 @@ --- -name: Policy Object TLOC +name: Policy Object TLOC List rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/tloc minimum_version: 20.12.0 test_tags: [SDWAN_2012, POLICY_OBJECT_FEATURE_TEMPLATE_ID] @@ -15,6 +15,7 @@ attributes: mandatory: true attributes: - model_name: tloc + tf_name: tloc_ip id: true mandatory: true example: 10.0.0.0 diff --git a/gen/models/profile_parcels/policy_object_color.json b/gen/models/profile_parcels/policy_object_color_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_color.json rename to gen/models/profile_parcels/policy_object_color_list.json diff --git a/gen/models/profile_parcels/policy_object_data_prefix.json b/gen/models/profile_parcels/policy_object_data_ipv4_prefix_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_data_prefix.json rename to gen/models/profile_parcels/policy_object_data_ipv4_prefix_list.json diff --git a/gen/models/profile_parcels/policy_object_data_ipv6_prefix.json b/gen/models/profile_parcels/policy_object_data_ipv6_prefix_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_data_ipv6_prefix.json rename to gen/models/profile_parcels/policy_object_data_ipv6_prefix_list.json diff --git a/gen/models/profile_parcels/policy_object_expanded_community.json b/gen/models/profile_parcels/policy_object_expanded_community_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_expanded_community.json rename to gen/models/profile_parcels/policy_object_expanded_community_list.json diff --git a/gen/models/profile_parcels/policy_object_extended_community.json b/gen/models/profile_parcels/policy_object_extended_community_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_extended_community.json rename to gen/models/profile_parcels/policy_object_extended_community_list.json diff --git a/gen/models/profile_parcels/policy_object_prefix.json b/gen/models/profile_parcels/policy_object_ipv4_prefix_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_prefix.json rename to gen/models/profile_parcels/policy_object_ipv4_prefix_list.json diff --git a/gen/models/profile_parcels/policy_object_ipv6_prefix.json b/gen/models/profile_parcels/policy_object_ipv6_prefix_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_ipv6_prefix.json rename to gen/models/profile_parcels/policy_object_ipv6_prefix_list.json diff --git a/gen/models/profile_parcels/policy_object_tloc.json b/gen/models/profile_parcels/policy_object_tloc_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_tloc.json rename to gen/models/profile_parcels/policy_object_tloc_list.json diff --git a/internal/provider/data_source_sdwan_policy_object_color_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_color_list_profile_parcel.go new file mode 100644 index 00000000..197b23a5 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_color_list_profile_parcel.go @@ -0,0 +1,133 @@ +// 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/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 = &PolicyObjectColorListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectColorListProfileParcelDataSource{} +) + +func NewPolicyObjectColorListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectColorListProfileParcelDataSource{} +} + +type PolicyObjectColorListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectColorListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_color_list_profile_parcel" +} + +func (d *PolicyObjectColorListProfileParcelDataSource) 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 Policy Object Color List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Color List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "color": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectColorListProfileParcelDataSource) 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 *PolicyObjectColorListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectColorList + + // 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_policy_object_color_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_color_list_profile_parcel_test.go new file mode 100644 index 00000000..2cde7c32 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_color_list_profile_parcel_test.go @@ -0,0 +1,74 @@ +// 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 TestAccDataSourceSdwanPolicyObjectColorListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_color_list_profile_parcel.test", "entries.0.color", "blue")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectColorListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectColorListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_color_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` color = "blue"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_color_list_profile_parcel" "test" { + id = sdwan_policy_object_color_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..6ec084b7 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,137 @@ +// 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/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 = &PolicyObjectDataIPv4PrefixListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectDataIPv4PrefixListProfileParcelDataSource{} +) + +func NewPolicyObjectDataIPv4PrefixListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectDataIPv4PrefixListProfileParcelDataSource{} +} + +type PolicyObjectDataIPv4PrefixListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectDataIPv4PrefixListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_data_ipv4_prefix_list_profile_parcel" +} + +func (d *PolicyObjectDataIPv4PrefixListProfileParcelDataSource) 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 Policy Object Data IPv4 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "IPv4 Data Prefix List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv4_address": schema.StringAttribute{ + MarkdownDescription: "IPv4 address", + Computed: true, + }, + "ipv4_prefix_length": schema.Int64Attribute{ + MarkdownDescription: "IPv4 prefix Length", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectDataIPv4PrefixListProfileParcelDataSource) 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 *PolicyObjectDataIPv4PrefixListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectDataIPv4PrefixList + + // 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_policy_object_data_ipv4_prefix_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..29d5a4b3 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel_test.go @@ -0,0 +1,76 @@ +// 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 TestAccDataSourceSdwanPolicyObjectDataIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_address", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_prefix_length", "8")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "test" { + id = sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..e7b4b788 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,137 @@ +// 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/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 = &PolicyObjectDataIPv6PrefixListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectDataIPv6PrefixListProfileParcelDataSource{} +) + +func NewPolicyObjectDataIPv6PrefixListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectDataIPv6PrefixListProfileParcelDataSource{} +} + +type PolicyObjectDataIPv6PrefixListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectDataIPv6PrefixListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_data_ipv6_prefix_list_profile_parcel" +} + +func (d *PolicyObjectDataIPv6PrefixListProfileParcelDataSource) 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 Policy Object Data IPv6 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "IPv6 Prefix List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv6_address": schema.StringAttribute{ + MarkdownDescription: "IPv6 address", + Computed: true, + }, + "ipv6_prefix_length": schema.Int64Attribute{ + MarkdownDescription: "IPv6 prefix", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectDataIPv6PrefixListProfileParcelDataSource) 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 *PolicyObjectDataIPv6PrefixListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectDataIPv6PrefixList + + // 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_policy_object_data_ipv6_prefix_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..3be07319 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel_test.go @@ -0,0 +1,76 @@ +// 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 TestAccDataSourceSdwanPolicyObjectDataIPv6PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_address", "2001:db8:85a3::8a2e:370:7334")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_prefix_length", "64")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "test" { + id = sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_expanded_community_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_expanded_community_list_profile_parcel.go new file mode 100644 index 00000000..a7639fb2 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_expanded_community_list_profile_parcel.go @@ -0,0 +1,132 @@ +// 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-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 the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &PolicyObjectExpandedCommunityListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectExpandedCommunityListProfileParcelDataSource{} +) + +func NewPolicyObjectExpandedCommunityListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectExpandedCommunityListProfileParcelDataSource{} +} + +type PolicyObjectExpandedCommunityListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectExpandedCommunityListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_expanded_community_list_profile_parcel" +} + +func (d *PolicyObjectExpandedCommunityListProfileParcelDataSource) 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 Policy Object Expanded Community List 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, + }, + "expanded_community_lists": schema.SetAttribute{ + MarkdownDescription: "Expanded Community List", + ElementType: types.StringType, + Computed: true, + }, + "expanded_community_lists_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + } +} + +func (d *PolicyObjectExpandedCommunityListProfileParcelDataSource) 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 *PolicyObjectExpandedCommunityListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectExpandedCommunityList + + // 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_policy_object_expanded_community_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_expanded_community_list_profile_parcel_test.go new file mode 100644 index 00000000..b7401803 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_expanded_community_list_profile_parcel_test.go @@ -0,0 +1,71 @@ +// 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 TestAccDataSourceSdwanPolicyObjectExpandedCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectExpandedCommunityListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectExpandedCommunityListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_expanded_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` expanded_community_lists = ["abcd"]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_expanded_community_list_profile_parcel" "test" { + id = sdwan_policy_object_expanded_community_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_extended_community_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_extended_community_list_profile_parcel.go new file mode 100644 index 00000000..b3a6e2de --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_extended_community_list_profile_parcel.go @@ -0,0 +1,133 @@ +// 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/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 = &PolicyObjectExtendedCommunityListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectExtendedCommunityListProfileParcelDataSource{} +) + +func NewPolicyObjectExtendedCommunityListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectExtendedCommunityListProfileParcelDataSource{} +} + +type PolicyObjectExtendedCommunityListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectExtendedCommunityListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_extended_community_list_profile_parcel" +} + +func (d *PolicyObjectExtendedCommunityListProfileParcelDataSource) 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 Policy Object Extended Community List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Extended Community List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "extended_community": schema.StringAttribute{ + MarkdownDescription: "can be soo 10.0.0.1:30 or rt 500:50 etc.", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectExtendedCommunityListProfileParcelDataSource) 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 *PolicyObjectExtendedCommunityListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectExtendedCommunityList + + // 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_policy_object_extended_community_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_extended_community_list_profile_parcel_test.go new file mode 100644 index 00000000..7ad4b107 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_extended_community_list_profile_parcel_test.go @@ -0,0 +1,74 @@ +// 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 TestAccDataSourceSdwanPolicyObjectExtendedCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_extended_community_list_profile_parcel.test", "entries.0.extended_community", "soo 10.0.0.1:30")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectExtendedCommunityListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectExtendedCommunityListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_extended_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` extended_community = "soo 10.0.0.1:30"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_extended_community_list_profile_parcel" "test" { + id = sdwan_policy_object_extended_community_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..bf100acf --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,145 @@ +// 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/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 = &PolicyObjectIPv4PrefixListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectIPv4PrefixListProfileParcelDataSource{} +) + +func NewPolicyObjectIPv4PrefixListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectIPv4PrefixListProfileParcelDataSource{} +} + +type PolicyObjectIPv4PrefixListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectIPv4PrefixListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_ipv4_prefix_list_profile_parcel" +} + +func (d *PolicyObjectIPv4PrefixListProfileParcelDataSource) 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 Policy Object IPv4 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "IPv4 Prefix List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv4_address": schema.StringAttribute{ + MarkdownDescription: "IPv4 address", + Computed: true, + }, + "ipv4_prefix_length": schema.Int64Attribute{ + MarkdownDescription: "IPv4 prefix length", + Computed: true, + }, + "le": schema.Int64Attribute{ + MarkdownDescription: "IPv4 prefix length with le range operator", + Computed: true, + }, + "ge": schema.Int64Attribute{ + MarkdownDescription: "IPv4 prefix length with ge range operator", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectIPv4PrefixListProfileParcelDataSource) 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 *PolicyObjectIPv4PrefixListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectIPv4PrefixList + + // 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_policy_object_ipv4_prefix_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_ipv4_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..a20829de --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_ipv4_prefix_list_profile_parcel_test.go @@ -0,0 +1,80 @@ +// 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 TestAccDataSourceSdwanPolicyObjectIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_address", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_prefix_length", "8")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.le", "24")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ge", "16")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectIPv4PrefixListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectIPv4PrefixListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` le = 24` + "\n" + config += ` ge = 16` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "test" { + id = sdwan_policy_object_ipv4_prefix_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..0dfb5e82 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,145 @@ +// 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/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 = &PolicyObjectIPv6PrefixListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectIPv6PrefixListProfileParcelDataSource{} +) + +func NewPolicyObjectIPv6PrefixListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectIPv6PrefixListProfileParcelDataSource{} +} + +type PolicyObjectIPv6PrefixListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectIPv6PrefixListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_ipv6_prefix_list_profile_parcel" +} + +func (d *PolicyObjectIPv6PrefixListProfileParcelDataSource) 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 Policy Object IPv6 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "IPv6 Prefix List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv6_address": schema.StringAttribute{ + MarkdownDescription: "IPv6 address", + Computed: true, + }, + "ipv6_prefix_length": schema.Int64Attribute{ + MarkdownDescription: "IPv6 prefix length", + Computed: true, + }, + "le": schema.Int64Attribute{ + MarkdownDescription: "IPv6 prefix length with le range operator", + Computed: true, + }, + "ge": schema.Int64Attribute{ + MarkdownDescription: "IPv6 prefix length with ge range operator", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectIPv6PrefixListProfileParcelDataSource) 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 *PolicyObjectIPv6PrefixListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectIPv6PrefixList + + // 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_policy_object_ipv6_prefix_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_ipv6_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..b38dfb54 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_ipv6_prefix_list_profile_parcel_test.go @@ -0,0 +1,80 @@ +// 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 TestAccDataSourceSdwanPolicyObjectIPv6PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_address", "2001:db8:85a3::8a2e:370:7334")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_prefix_length", "64")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.le", "100")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ge", "70")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectIPv6PrefixListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectIPv6PrefixListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` le = 100` + "\n" + config += ` ge = 70` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "test" { + id = sdwan_policy_object_ipv6_prefix_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel.go index 917fff9a..afe3f59d 100644 --- a/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel.go +++ b/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel.go @@ -86,7 +86,7 @@ func (d *PolicyObjectPolicerProfileParcelDataSource) Schema(ctx context.Context, MarkdownDescription: "Burst (Bytes)", Computed: true, }, - "select_value": schema.StringAttribute{ + "exceed_action": schema.StringAttribute{ MarkdownDescription: "Exceed options such as Drop or Remark", Computed: true, }, diff --git a/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel_test.go index 2998985b..879ca2f1 100644 --- a/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel_test.go +++ b/internal/provider/data_source_sdwan_policy_object_policer_profile_parcel_test.go @@ -34,7 +34,7 @@ func TestAccDataSourceSdwanPolicyObjectPolicerProfileParcel(t *testing.T) { } var checks []resource.TestCheckFunc checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_policer_profile_parcel.test", "entries.0.burst_bytes", "56500")) - checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_policer_profile_parcel.test", "entries.0.select_value", "remark")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_policer_profile_parcel.test", "entries.0.exceed_action", "remark")) checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_policer_profile_parcel.test", "entries.0.rate_bps", "60000")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -61,7 +61,7 @@ func testAccDataSourceSdwanPolicyObjectPolicerProfileParcelConfig() string { config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" config += ` entries = [{` + "\n" config += ` burst_bytes = 56500` + "\n" - config += ` select_value = "remark"` + "\n" + config += ` exceed_action = "remark"` + "\n" config += ` rate_bps = 60000` + "\n" config += ` }]` + "\n" config += `}` + "\n" diff --git a/internal/provider/data_source_sdwan_policy_object_tloc_list_profile_parcel.go b/internal/provider/data_source_sdwan_policy_object_tloc_list_profile_parcel.go new file mode 100644 index 00000000..6cd538c8 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_tloc_list_profile_parcel.go @@ -0,0 +1,145 @@ +// 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/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 = &PolicyObjectTLOCListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectTLOCListProfileParcelDataSource{} +) + +func NewPolicyObjectTLOCListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectTLOCListProfileParcelDataSource{} +} + +type PolicyObjectTLOCListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectTLOCListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_tloc_list_profile_parcel" +} + +func (d *PolicyObjectTLOCListProfileParcelDataSource) 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 Policy Object TLOC List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "TLOC List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tloc_ip": schema.StringAttribute{ + MarkdownDescription: "tloc", + Computed: true, + }, + "color": schema.StringAttribute{ + MarkdownDescription: "color", + Computed: true, + }, + "encapsulation": schema.StringAttribute{ + MarkdownDescription: "encapsulation", + Computed: true, + }, + "preference": schema.StringAttribute{ + MarkdownDescription: "Preference", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectTLOCListProfileParcelDataSource) 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 *PolicyObjectTLOCListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectTLOCList + + // 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_policy_object_tloc_list_profile_parcel_test.go b/internal/provider/data_source_sdwan_policy_object_tloc_list_profile_parcel_test.go new file mode 100644 index 00000000..008e6b32 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_tloc_list_profile_parcel_test.go @@ -0,0 +1,80 @@ +// 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 TestAccDataSourceSdwanPolicyObjectTLOCListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.tloc_ip", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.color", "3g")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.encapsulation", "gre")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.preference", "33")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectTLOCListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectTLOCListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_tloc_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` tloc_ip = "10.0.0.0"` + "\n" + config += ` color = "3g"` + "\n" + config += ` encapsulation = "gre"` + "\n" + config += ` preference = "33"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_tloc_list_profile_parcel" "test" { + id = sdwan_policy_object_tloc_list_profile_parcel.test.id + feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + ` + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/model_sdwan_policy_object_color_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_color_list_profile_parcel.go new file mode 100644 index 00000000..ecc8fe6f --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_color_list_profile_parcel.go @@ -0,0 +1,171 @@ +// 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 PolicyObjectColorList 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"` + Entries []PolicyObjectColorListEntries `tfsdk:"entries"` +} + +type PolicyObjectColorListEntries struct { + Color types.String `tfsdk:"color"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectColorList) getModel() string { + return "policy_object_color_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectColorList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/color", 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 PolicyObjectColorList) 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.Entries { + itemBody := "" + if !item.Color.IsNull() { + itemBody, _ = sjson.Set(itemBody, "color.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "color.value", item.Color.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectColorList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectColorListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectColorListEntries{} + item.Color = types.StringNull() + + if t := v.Get("color.optionType"); t.Exists() { + va := v.Get("color.value") + if t.String() == "global" { + item.Color = types.StringValue(va.String()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectColorList) 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.Entries { + keys := [...]string{"color"} + keyValues := [...]string{data.Entries[i].Color.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].Color = types.StringNull() + + if t := r.Get("color.optionType"); t.Exists() { + va := r.Get("color.value") + if t.String() == "global" { + data.Entries[i].Color = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectColorList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..b913f99e --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,192 @@ +// 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 PolicyObjectDataIPv4PrefixList 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"` + Entries []PolicyObjectDataIPv4PrefixListEntries `tfsdk:"entries"` +} + +type PolicyObjectDataIPv4PrefixListEntries struct { + Ipv4Address types.String `tfsdk:"ipv4_address"` + Ipv4PrefixLength types.Int64 `tfsdk:"ipv4_prefix_length"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectDataIPv4PrefixList) getModel() string { + return "policy_object_data_ipv4_prefix_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectDataIPv4PrefixList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/data-prefix", 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 PolicyObjectDataIPv4PrefixList) 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.Entries { + itemBody := "" + if !item.Ipv4Address.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv4Address.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv4Address.value", item.Ipv4Address.ValueString()) + } + if !item.Ipv4PrefixLength.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv4PrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv4PrefixLength.value", item.Ipv4PrefixLength.ValueInt64()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectDataIPv4PrefixList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectDataIPv4PrefixListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectDataIPv4PrefixListEntries{} + item.Ipv4Address = types.StringNull() + + if t := v.Get("ipv4Address.optionType"); t.Exists() { + va := v.Get("ipv4Address.value") + if t.String() == "global" { + item.Ipv4Address = types.StringValue(va.String()) + } + } + item.Ipv4PrefixLength = types.Int64Null() + + if t := v.Get("ipv4PrefixLength.optionType"); t.Exists() { + va := v.Get("ipv4PrefixLength.value") + if t.String() == "global" { + item.Ipv4PrefixLength = types.Int64Value(va.Int()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectDataIPv4PrefixList) 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.Entries { + keys := [...]string{"ipv4Address"} + keyValues := [...]string{data.Entries[i].Ipv4Address.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].Ipv4Address = types.StringNull() + + if t := r.Get("ipv4Address.optionType"); t.Exists() { + va := r.Get("ipv4Address.value") + if t.String() == "global" { + data.Entries[i].Ipv4Address = types.StringValue(va.String()) + } + } + data.Entries[i].Ipv4PrefixLength = types.Int64Null() + + if t := r.Get("ipv4PrefixLength.optionType"); t.Exists() { + va := r.Get("ipv4PrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ipv4PrefixLength = types.Int64Value(va.Int()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectDataIPv4PrefixList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..5e59321c --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,192 @@ +// 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 PolicyObjectDataIPv6PrefixList 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"` + Entries []PolicyObjectDataIPv6PrefixListEntries `tfsdk:"entries"` +} + +type PolicyObjectDataIPv6PrefixListEntries struct { + Ipv6Address types.String `tfsdk:"ipv6_address"` + Ipv6PrefixLength types.Int64 `tfsdk:"ipv6_prefix_length"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectDataIPv6PrefixList) getModel() string { + return "policy_object_data_ipv6_prefix_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectDataIPv6PrefixList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/data-ipv6-prefix", 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 PolicyObjectDataIPv6PrefixList) 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.Entries { + itemBody := "" + if !item.Ipv6Address.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv6Address.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv6Address.value", item.Ipv6Address.ValueString()) + } + if !item.Ipv6PrefixLength.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv6PrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv6PrefixLength.value", item.Ipv6PrefixLength.ValueInt64()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectDataIPv6PrefixList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectDataIPv6PrefixListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectDataIPv6PrefixListEntries{} + item.Ipv6Address = types.StringNull() + + if t := v.Get("ipv6Address.optionType"); t.Exists() { + va := v.Get("ipv6Address.value") + if t.String() == "global" { + item.Ipv6Address = types.StringValue(va.String()) + } + } + item.Ipv6PrefixLength = types.Int64Null() + + if t := v.Get("ipv6PrefixLength.optionType"); t.Exists() { + va := v.Get("ipv6PrefixLength.value") + if t.String() == "global" { + item.Ipv6PrefixLength = types.Int64Value(va.Int()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectDataIPv6PrefixList) 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.Entries { + keys := [...]string{"ipv6Address"} + keyValues := [...]string{data.Entries[i].Ipv6Address.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].Ipv6Address = types.StringNull() + + if t := r.Get("ipv6Address.optionType"); t.Exists() { + va := r.Get("ipv6Address.value") + if t.String() == "global" { + data.Entries[i].Ipv6Address = types.StringValue(va.String()) + } + } + data.Entries[i].Ipv6PrefixLength = types.Int64Null() + + if t := r.Get("ipv6PrefixLength.optionType"); t.Exists() { + va := r.Get("ipv6PrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ipv6PrefixLength = types.Int64Value(va.Int()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectDataIPv6PrefixList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_expanded_community_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_expanded_community_list_profile_parcel.go new file mode 100644 index 00000000..af71057a --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_expanded_community_list_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/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 PolicyObjectExpandedCommunityList 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"` + ExpandedCommunityLists types.Set `tfsdk:"expanded_community_lists"` + ExpandedCommunityListsVariable types.String `tfsdk:"expanded_community_lists_variable"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectExpandedCommunityList) getModel() string { + return "policy_object_expanded_community_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectExpandedCommunityList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/expanded-community", 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 PolicyObjectExpandedCommunityList) 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.ExpandedCommunityListsVariable.IsNull() { + body, _ = sjson.Set(body, path+"expandedCommunityList.optionType", "variable") + body, _ = sjson.Set(body, path+"expandedCommunityList.value", data.ExpandedCommunityListsVariable.ValueString()) + } else if !data.ExpandedCommunityLists.IsNull() { + body, _ = sjson.Set(body, path+"expandedCommunityList.optionType", "global") + var values []string + data.ExpandedCommunityLists.ElementsAs(ctx, &values, false) + body, _ = sjson.Set(body, path+"expandedCommunityList.value", values) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectExpandedCommunityList) 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.ExpandedCommunityLists = types.SetNull(types.StringType) + data.ExpandedCommunityListsVariable = types.StringNull() + if t := res.Get(path + "expandedCommunityList.optionType"); t.Exists() { + va := res.Get(path + "expandedCommunityList.value") + if t.String() == "variable" { + data.ExpandedCommunityListsVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ExpandedCommunityLists = helpers.GetStringSet(va.Array()) + } + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectExpandedCommunityList) 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.ExpandedCommunityLists = types.SetNull(types.StringType) + data.ExpandedCommunityListsVariable = types.StringNull() + if t := res.Get(path + "expandedCommunityList.optionType"); t.Exists() { + va := res.Get(path + "expandedCommunityList.value") + if t.String() == "variable" { + data.ExpandedCommunityListsVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.ExpandedCommunityLists = helpers.GetStringSet(va.Array()) + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectExpandedCommunityList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if !data.ExpandedCommunityLists.IsNull() { + return false + } + if !data.ExpandedCommunityListsVariable.IsNull() { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_extended_community_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_extended_community_list_profile_parcel.go new file mode 100644 index 00000000..c777a0bf --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_extended_community_list_profile_parcel.go @@ -0,0 +1,171 @@ +// 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 PolicyObjectExtendedCommunityList 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"` + Entries []PolicyObjectExtendedCommunityListEntries `tfsdk:"entries"` +} + +type PolicyObjectExtendedCommunityListEntries struct { + ExtendedCommunity types.String `tfsdk:"extended_community"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectExtendedCommunityList) getModel() string { + return "policy_object_extended_community_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectExtendedCommunityList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/ext-community", 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 PolicyObjectExtendedCommunityList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + body, _ = sjson.Set(body, path+"entries", []interface{}{}) + for _, item := range data.Entries { + itemBody := "" + if !item.ExtendedCommunity.IsNull() { + itemBody, _ = sjson.Set(itemBody, "extCommunity.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "extCommunity.value", item.ExtendedCommunity.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectExtendedCommunityList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectExtendedCommunityListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectExtendedCommunityListEntries{} + item.ExtendedCommunity = types.StringNull() + + if t := v.Get("extCommunity.optionType"); t.Exists() { + va := v.Get("extCommunity.value") + if t.String() == "global" { + item.ExtendedCommunity = types.StringValue(va.String()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectExtendedCommunityList) 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.Entries { + keys := [...]string{"extCommunity"} + keyValues := [...]string{data.Entries[i].ExtendedCommunity.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].ExtendedCommunity = types.StringNull() + + if t := r.Get("extCommunity.optionType"); t.Exists() { + va := r.Get("extCommunity.value") + if t.String() == "global" { + data.Entries[i].ExtendedCommunity = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectExtendedCommunityList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..01da183d --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,235 @@ +// 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" + "strconv" + + "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 PolicyObjectIPv4PrefixList 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"` + Entries []PolicyObjectIPv4PrefixListEntries `tfsdk:"entries"` +} + +type PolicyObjectIPv4PrefixListEntries struct { + Ipv4Address types.String `tfsdk:"ipv4_address"` + Ipv4PrefixLength types.Int64 `tfsdk:"ipv4_prefix_length"` + Le types.Int64 `tfsdk:"le"` + Ge types.Int64 `tfsdk:"ge"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectIPv4PrefixList) getModel() string { + return "policy_object_ipv4_prefix_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectIPv4PrefixList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/prefix", 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 PolicyObjectIPv4PrefixList) 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.Entries { + itemBody := "" + if !item.Ipv4Address.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv4Address.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv4Address.value", item.Ipv4Address.ValueString()) + } + if !item.Ipv4PrefixLength.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv4PrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv4PrefixLength.value", item.Ipv4PrefixLength.ValueInt64()) + } + if !item.Le.IsNull() { + itemBody, _ = sjson.Set(itemBody, "leRangePrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "leRangePrefixLength.value", item.Le.ValueInt64()) + } + if !item.Ge.IsNull() { + itemBody, _ = sjson.Set(itemBody, "geRangePrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "geRangePrefixLength.value", item.Ge.ValueInt64()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectIPv4PrefixList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectIPv4PrefixListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectIPv4PrefixListEntries{} + item.Ipv4Address = types.StringNull() + + if t := v.Get("ipv4Address.optionType"); t.Exists() { + va := v.Get("ipv4Address.value") + if t.String() == "global" { + item.Ipv4Address = types.StringValue(va.String()) + } + } + item.Ipv4PrefixLength = types.Int64Null() + + if t := v.Get("ipv4PrefixLength.optionType"); t.Exists() { + va := v.Get("ipv4PrefixLength.value") + if t.String() == "global" { + item.Ipv4PrefixLength = types.Int64Value(va.Int()) + } + } + item.Le = types.Int64Null() + + if t := v.Get("leRangePrefixLength.optionType"); t.Exists() { + va := v.Get("leRangePrefixLength.value") + if t.String() == "global" { + item.Le = types.Int64Value(va.Int()) + } + } + item.Ge = types.Int64Null() + + if t := v.Get("geRangePrefixLength.optionType"); t.Exists() { + va := v.Get("geRangePrefixLength.value") + if t.String() == "global" { + item.Ge = types.Int64Value(va.Int()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectIPv4PrefixList) 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.Entries { + keys := [...]string{"ipv4Address", "ipv4PrefixLength"} + keyValues := [...]string{data.Entries[i].Ipv4Address.ValueString(), strconv.FormatInt(data.Entries[i].Ipv4PrefixLength.ValueInt64(), 10)} + keyValuesVariables := [...]string{"", ""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].Ipv4Address = types.StringNull() + + if t := r.Get("ipv4Address.optionType"); t.Exists() { + va := r.Get("ipv4Address.value") + if t.String() == "global" { + data.Entries[i].Ipv4Address = types.StringValue(va.String()) + } + } + data.Entries[i].Ipv4PrefixLength = types.Int64Null() + + if t := r.Get("ipv4PrefixLength.optionType"); t.Exists() { + va := r.Get("ipv4PrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ipv4PrefixLength = types.Int64Value(va.Int()) + } + } + data.Entries[i].Le = types.Int64Null() + + if t := r.Get("leRangePrefixLength.optionType"); t.Exists() { + va := r.Get("leRangePrefixLength.value") + if t.String() == "global" { + data.Entries[i].Le = types.Int64Value(va.Int()) + } + } + data.Entries[i].Ge = types.Int64Null() + + if t := r.Get("geRangePrefixLength.optionType"); t.Exists() { + va := r.Get("geRangePrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ge = types.Int64Value(va.Int()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectIPv4PrefixList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..38deee8d --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,235 @@ +// 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" + "strconv" + + "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 PolicyObjectIPv6PrefixList 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"` + Entries []PolicyObjectIPv6PrefixListEntries `tfsdk:"entries"` +} + +type PolicyObjectIPv6PrefixListEntries struct { + Ipv6Address types.String `tfsdk:"ipv6_address"` + Ipv6PrefixLength types.Int64 `tfsdk:"ipv6_prefix_length"` + Le types.Int64 `tfsdk:"le"` + Ge types.Int64 `tfsdk:"ge"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectIPv6PrefixList) getModel() string { + return "policy_object_ipv6_prefix_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectIPv6PrefixList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/ipv6-prefix", 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 PolicyObjectIPv6PrefixList) 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.Entries { + itemBody := "" + if !item.Ipv6Address.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv6Address.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv6Address.value", item.Ipv6Address.ValueString()) + } + if !item.Ipv6PrefixLength.IsNull() { + itemBody, _ = sjson.Set(itemBody, "ipv6PrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipv6PrefixLength.value", item.Ipv6PrefixLength.ValueInt64()) + } + if !item.Le.IsNull() { + itemBody, _ = sjson.Set(itemBody, "leRangePrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "leRangePrefixLength.value", item.Le.ValueInt64()) + } + if !item.Ge.IsNull() { + itemBody, _ = sjson.Set(itemBody, "geRangePrefixLength.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "geRangePrefixLength.value", item.Ge.ValueInt64()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectIPv6PrefixList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectIPv6PrefixListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectIPv6PrefixListEntries{} + item.Ipv6Address = types.StringNull() + + if t := v.Get("ipv6Address.optionType"); t.Exists() { + va := v.Get("ipv6Address.value") + if t.String() == "global" { + item.Ipv6Address = types.StringValue(va.String()) + } + } + item.Ipv6PrefixLength = types.Int64Null() + + if t := v.Get("ipv6PrefixLength.optionType"); t.Exists() { + va := v.Get("ipv6PrefixLength.value") + if t.String() == "global" { + item.Ipv6PrefixLength = types.Int64Value(va.Int()) + } + } + item.Le = types.Int64Null() + + if t := v.Get("leRangePrefixLength.optionType"); t.Exists() { + va := v.Get("leRangePrefixLength.value") + if t.String() == "global" { + item.Le = types.Int64Value(va.Int()) + } + } + item.Ge = types.Int64Null() + + if t := v.Get("geRangePrefixLength.optionType"); t.Exists() { + va := v.Get("geRangePrefixLength.value") + if t.String() == "global" { + item.Ge = types.Int64Value(va.Int()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectIPv6PrefixList) 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.Entries { + keys := [...]string{"ipv6Address", "ipv6PrefixLength"} + keyValues := [...]string{data.Entries[i].Ipv6Address.ValueString(), strconv.FormatInt(data.Entries[i].Ipv6PrefixLength.ValueInt64(), 10)} + keyValuesVariables := [...]string{"", ""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].Ipv6Address = types.StringNull() + + if t := r.Get("ipv6Address.optionType"); t.Exists() { + va := r.Get("ipv6Address.value") + if t.String() == "global" { + data.Entries[i].Ipv6Address = types.StringValue(va.String()) + } + } + data.Entries[i].Ipv6PrefixLength = types.Int64Null() + + if t := r.Get("ipv6PrefixLength.optionType"); t.Exists() { + va := r.Get("ipv6PrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ipv6PrefixLength = types.Int64Value(va.Int()) + } + } + data.Entries[i].Le = types.Int64Null() + + if t := r.Get("leRangePrefixLength.optionType"); t.Exists() { + va := r.Get("leRangePrefixLength.value") + if t.String() == "global" { + data.Entries[i].Le = types.Int64Value(va.Int()) + } + } + data.Entries[i].Ge = types.Int64Null() + + if t := r.Get("geRangePrefixLength.optionType"); t.Exists() { + va := r.Get("geRangePrefixLength.value") + if t.String() == "global" { + data.Entries[i].Ge = types.Int64Value(va.Int()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectIPv6PrefixList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/model_sdwan_policy_object_policer_profile_parcel.go b/internal/provider/model_sdwan_policy_object_policer_profile_parcel.go index e949fc5b..38ec4b56 100644 --- a/internal/provider/model_sdwan_policy_object_policer_profile_parcel.go +++ b/internal/provider/model_sdwan_policy_object_policer_profile_parcel.go @@ -42,9 +42,9 @@ type PolicyObjectPolicer struct { } type PolicyObjectPolicerEntries struct { - BurstBytes types.Int64 `tfsdk:"burst_bytes"` - SelectValue types.String `tfsdk:"select_value"` - RateBps types.Int64 `tfsdk:"rate_bps"` + BurstBytes types.Int64 `tfsdk:"burst_bytes"` + ExceedAction types.String `tfsdk:"exceed_action"` + RateBps types.Int64 `tfsdk:"rate_bps"` } // End of section. //template:end types @@ -76,9 +76,9 @@ func (data PolicyObjectPolicer) toBody(ctx context.Context) string { itemBody, _ = sjson.Set(itemBody, "burst.optionType", "global") itemBody, _ = sjson.Set(itemBody, "burst.value", item.BurstBytes.ValueInt64()) } - if !item.SelectValue.IsNull() { + if !item.ExceedAction.IsNull() { itemBody, _ = sjson.Set(itemBody, "exceed.optionType", "global") - itemBody, _ = sjson.Set(itemBody, "exceed.value", item.SelectValue.ValueString()) + itemBody, _ = sjson.Set(itemBody, "exceed.value", item.ExceedAction.ValueString()) } if !item.RateBps.IsNull() { itemBody, _ = sjson.Set(itemBody, "rate.optionType", "global") @@ -112,12 +112,12 @@ func (data *PolicyObjectPolicer) fromBody(ctx context.Context, res gjson.Result) item.BurstBytes = types.Int64Value(va.Int()) } } - item.SelectValue = types.StringNull() + item.ExceedAction = types.StringNull() if t := v.Get("exceed.optionType"); t.Exists() { va := v.Get("exceed.value") if t.String() == "global" { - item.SelectValue = types.StringValue(va.String()) + item.ExceedAction = types.StringValue(va.String()) } } item.RateBps = types.Int64Null() @@ -147,7 +147,7 @@ func (data *PolicyObjectPolicer) updateFromBody(ctx context.Context, res gjson.R path := "payload.data." for i := range data.Entries { keys := [...]string{"burst", "exceed", "rate"} - keyValues := [...]string{strconv.FormatInt(data.Entries[i].BurstBytes.ValueInt64(), 10), data.Entries[i].SelectValue.ValueString(), strconv.FormatInt(data.Entries[i].RateBps.ValueInt64(), 10)} + keyValues := [...]string{strconv.FormatInt(data.Entries[i].BurstBytes.ValueInt64(), 10), data.Entries[i].ExceedAction.ValueString(), strconv.FormatInt(data.Entries[i].RateBps.ValueInt64(), 10)} keyValuesVariables := [...]string{"", "", ""} var r gjson.Result @@ -179,12 +179,12 @@ func (data *PolicyObjectPolicer) updateFromBody(ctx context.Context, res gjson.R data.Entries[i].BurstBytes = types.Int64Value(va.Int()) } } - data.Entries[i].SelectValue = types.StringNull() + data.Entries[i].ExceedAction = types.StringNull() if t := r.Get("exceed.optionType"); t.Exists() { va := r.Get("exceed.value") if t.String() == "global" { - data.Entries[i].SelectValue = types.StringValue(va.String()) + data.Entries[i].ExceedAction = types.StringValue(va.String()) } } data.Entries[i].RateBps = types.Int64Null() diff --git a/internal/provider/model_sdwan_policy_object_tloc_list_profile_parcel.go b/internal/provider/model_sdwan_policy_object_tloc_list_profile_parcel.go new file mode 100644 index 00000000..92866fa0 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_tloc_list_profile_parcel.go @@ -0,0 +1,234 @@ +// 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 PolicyObjectTLOCList 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"` + Entries []PolicyObjectTLOCListEntries `tfsdk:"entries"` +} + +type PolicyObjectTLOCListEntries struct { + TlocIp types.String `tfsdk:"tloc_ip"` + Color types.String `tfsdk:"color"` + Encapsulation types.String `tfsdk:"encapsulation"` + Preference types.String `tfsdk:"preference"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectTLOCList) getModel() string { + return "policy_object_tloc_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectTLOCList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/tloc", 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 PolicyObjectTLOCList) 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.Entries { + itemBody := "" + if !item.TlocIp.IsNull() { + itemBody, _ = sjson.Set(itemBody, "tloc.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "tloc.value", item.TlocIp.ValueString()) + } + if !item.Color.IsNull() { + itemBody, _ = sjson.Set(itemBody, "color.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "color.value", item.Color.ValueString()) + } + if !item.Encapsulation.IsNull() { + itemBody, _ = sjson.Set(itemBody, "encap.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "encap.value", item.Encapsulation.ValueString()) + } + if !item.Preference.IsNull() { + itemBody, _ = sjson.Set(itemBody, "preference.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "preference.value", item.Preference.ValueString()) + } + body, _ = sjson.SetRaw(body, path+"entries.-1", itemBody) + } + return body +} + +// End of section. //template:end toBody + +// Section below is generated&owned by "gen/generator.go". //template:begin fromBody +func (data *PolicyObjectTLOCList) 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 + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectTLOCListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectTLOCListEntries{} + item.TlocIp = types.StringNull() + + if t := v.Get("tloc.optionType"); t.Exists() { + va := v.Get("tloc.value") + if t.String() == "global" { + item.TlocIp = types.StringValue(va.String()) + } + } + item.Color = types.StringNull() + + if t := v.Get("color.optionType"); t.Exists() { + va := v.Get("color.value") + if t.String() == "global" { + item.Color = types.StringValue(va.String()) + } + } + item.Encapsulation = types.StringNull() + + if t := v.Get("encap.optionType"); t.Exists() { + va := v.Get("encap.value") + if t.String() == "global" { + item.Encapsulation = types.StringValue(va.String()) + } + } + item.Preference = types.StringNull() + + if t := v.Get("preference.optionType"); t.Exists() { + va := v.Get("preference.value") + if t.String() == "global" { + item.Preference = types.StringValue(va.String()) + } + } + data.Entries = append(data.Entries, item) + return true + }) + } +} + +// End of section. //template:end fromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin updateFromBody +func (data *PolicyObjectTLOCList) 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.Entries { + keys := [...]string{"tloc"} + keyValues := [...]string{data.Entries[i].TlocIp.ValueString()} + keyValuesVariables := [...]string{""} + + var r gjson.Result + res.Get(path + "entries").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.Entries[i].TlocIp = types.StringNull() + + if t := r.Get("tloc.optionType"); t.Exists() { + va := r.Get("tloc.value") + if t.String() == "global" { + data.Entries[i].TlocIp = types.StringValue(va.String()) + } + } + data.Entries[i].Color = types.StringNull() + + if t := r.Get("color.optionType"); t.Exists() { + va := r.Get("color.value") + if t.String() == "global" { + data.Entries[i].Color = types.StringValue(va.String()) + } + } + data.Entries[i].Encapsulation = types.StringNull() + + if t := r.Get("encap.optionType"); t.Exists() { + va := r.Get("encap.value") + if t.String() == "global" { + data.Entries[i].Encapsulation = types.StringValue(va.String()) + } + } + data.Entries[i].Preference = types.StringNull() + + if t := r.Get("preference.optionType"); t.Exists() { + va := r.Get("preference.value") + if t.String() == "global" { + data.Entries[i].Preference = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectTLOCList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if len(data.Entries) > 0 { + return false + } + return true +} + +// End of section. //template:end isNull diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b040bb8f..83746d6c 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -284,16 +284,16 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewVPNInterfaceT1E1SerialFeatureTemplateResource, NewApplicationPriorityQoSPolicyProfileParcelResource, NewPolicyObjectClassMapProfileParcelResource, - NewPolicyObjectColorProfileParcelResource, - NewPolicyObjectDataIPv6PrefixProfileParcelResource, - NewPolicyObjectDataPrefixProfileParcelResource, - NewPolicyObjectExpandedCommunityProfileParcelResource, - NewPolicyObjectExtendedCommunityProfileParcelResource, - NewPolicyObjectIPv6PrefixProfileParcelResource, + NewPolicyObjectColorListProfileParcelResource, + NewPolicyObjectDataIPv4PrefixListProfileParcelResource, + NewPolicyObjectDataIPv6PrefixListProfileParcelResource, + NewPolicyObjectExpandedCommunityListProfileParcelResource, + NewPolicyObjectExtendedCommunityListProfileParcelResource, + NewPolicyObjectIPv4PrefixListProfileParcelResource, + NewPolicyObjectIPv6PrefixListProfileParcelResource, NewPolicyObjectMirrorProfileParcelResource, NewPolicyObjectPolicerProfileParcelResource, - NewPolicyObjectPrefixProfileParcelResource, - NewPolicyObjectTLOCProfileParcelResource, + NewPolicyObjectTLOCListProfileParcelResource, NewServiceLANVPNProfileParcelResource, NewServiceLANVPNInterfaceEthernetProfileParcelResource, NewServiceLANVPNInterfaceGREProfileParcelResource, @@ -444,16 +444,16 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewVPNInterfaceT1E1SerialFeatureTemplateDataSource, NewApplicationPriorityQoSPolicyProfileParcelDataSource, NewPolicyObjectClassMapProfileParcelDataSource, - NewPolicyObjectColorProfileParcelDataSource, - NewPolicyObjectDataIPv6PrefixProfileParcelDataSource, - NewPolicyObjectDataPrefixProfileParcelDataSource, - NewPolicyObjectExpandedCommunityProfileParcelDataSource, - NewPolicyObjectExtendedCommunityProfileParcelDataSource, - NewPolicyObjectIPv6PrefixProfileParcelDataSource, + NewPolicyObjectColorListProfileParcelDataSource, + NewPolicyObjectDataIPv4PrefixListProfileParcelDataSource, + NewPolicyObjectDataIPv6PrefixListProfileParcelDataSource, + NewPolicyObjectExpandedCommunityListProfileParcelDataSource, + NewPolicyObjectExtendedCommunityListProfileParcelDataSource, + NewPolicyObjectIPv4PrefixListProfileParcelDataSource, + NewPolicyObjectIPv6PrefixListProfileParcelDataSource, NewPolicyObjectMirrorProfileParcelDataSource, NewPolicyObjectPolicerProfileParcelDataSource, - NewPolicyObjectPrefixProfileParcelDataSource, - NewPolicyObjectTLOCProfileParcelDataSource, + NewPolicyObjectTLOCListProfileParcelDataSource, NewServiceLANVPNProfileParcelDataSource, NewServiceLANVPNInterfaceEthernetProfileParcelDataSource, NewServiceLANVPNInterfaceGREProfileParcelDataSource, diff --git a/internal/provider/resource_sdwan_policy_object_color_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_color_list_profile_parcel.go new file mode 100644 index 00000000..5e98f4fd --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_color_list_profile_parcel.go @@ -0,0 +1,257 @@ +// 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" + "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 = &PolicyObjectColorListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectColorListProfileParcelResource{} + +func NewPolicyObjectColorListProfileParcelResource() resource.Resource { + return &PolicyObjectColorListProfileParcelResource{} +} + +type PolicyObjectColorListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectColorListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_color_list_profile_parcel" +} + +func (r *PolicyObjectColorListProfileParcelResource) 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 Policy Object Color List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Color List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "color": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").AddStringEnumDescription("3g", "biz-internet", "blue", "bronze", "custom1", "custom2", "custom3", "default", "gold", "green", "lte", "metro-ethernet", "mpls", "private1", "private2", "private3", "private4", "private5", "private6", "public-internet", "red", "silver").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("3g", "biz-internet", "blue", "bronze", "custom1", "custom2", "custom3", "default", "gold", "green", "lte", "metro-ethernet", "mpls", "private1", "private2", "private3", "private4", "private5", "private6", "public-internet", "red", "silver"), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectColorListProfileParcelResource) 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 *PolicyObjectColorListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectColorList + + // 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 *PolicyObjectColorListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectColorList + + // 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 *PolicyObjectColorListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectColorList + + // 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 *PolicyObjectColorListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectColorList + + // 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 *PolicyObjectColorListProfileParcelResource) 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_policy_object_color_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_color_list_profile_parcel_test.go new file mode 100644 index 00000000..cd26aa6a --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_color_list_profile_parcel_test.go @@ -0,0 +1,85 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanPolicyObjectColorListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_color_list_profile_parcel.test", "entries.0.color", "blue")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectColorListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectColorListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectColorListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_color_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` color = "blue"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectColorListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_color_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` color = "blue"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..a17b209d --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,261 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "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 = &PolicyObjectDataIPv4PrefixListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectDataIPv4PrefixListProfileParcelResource{} + +func NewPolicyObjectDataIPv4PrefixListProfileParcelResource() resource.Resource { + return &PolicyObjectDataIPv4PrefixListProfileParcelResource{} +} + +type PolicyObjectDataIPv4PrefixListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectDataIPv4PrefixListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_data_ipv4_prefix_list_profile_parcel" +} + +func (r *PolicyObjectDataIPv4PrefixListProfileParcelResource) 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 Policy Object Data IPv4 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 Data Prefix List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv4_address": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 address").String, + Optional: true, + }, + "ipv4_prefix_length": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 prefix Length").AddIntegerRangeDescription(0, 32).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.AtMost(32), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectDataIPv4PrefixListProfileParcelResource) 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 *PolicyObjectDataIPv4PrefixListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectDataIPv4PrefixList + + // 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 *PolicyObjectDataIPv4PrefixListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectDataIPv4PrefixList + + // 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 *PolicyObjectDataIPv4PrefixListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectDataIPv4PrefixList + + // 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 *PolicyObjectDataIPv4PrefixListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectDataIPv4PrefixList + + // 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 *PolicyObjectDataIPv4PrefixListProfileParcelResource) 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_policy_object_data_ipv4_prefix_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..a526f03a --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_data_ipv4_prefix_list_profile_parcel_test.go @@ -0,0 +1,88 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanPolicyObjectDataIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_address", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_data_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_prefix_length", "8")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectDataIPv4PrefixListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_data_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..10cebe1d --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,261 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "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 = &PolicyObjectDataIPv6PrefixListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectDataIPv6PrefixListProfileParcelResource{} + +func NewPolicyObjectDataIPv6PrefixListProfileParcelResource() resource.Resource { + return &PolicyObjectDataIPv6PrefixListProfileParcelResource{} +} + +type PolicyObjectDataIPv6PrefixListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectDataIPv6PrefixListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_data_ipv6_prefix_list_profile_parcel" +} + +func (r *PolicyObjectDataIPv6PrefixListProfileParcelResource) 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 Policy Object Data IPv6 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 Prefix List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv6_address": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 address").String, + Optional: true, + }, + "ipv6_prefix_length": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 prefix").AddIntegerRangeDescription(0, 128).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.AtMost(128), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectDataIPv6PrefixListProfileParcelResource) 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 *PolicyObjectDataIPv6PrefixListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectDataIPv6PrefixList + + // 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 *PolicyObjectDataIPv6PrefixListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectDataIPv6PrefixList + + // 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 *PolicyObjectDataIPv6PrefixListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectDataIPv6PrefixList + + // 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 *PolicyObjectDataIPv6PrefixListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectDataIPv6PrefixList + + // 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 *PolicyObjectDataIPv6PrefixListProfileParcelResource) 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_policy_object_data_ipv6_prefix_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..53291c58 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_data_ipv6_prefix_list_profile_parcel_test.go @@ -0,0 +1,88 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanPolicyObjectDataIPv6PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_address", "2001:db8:85a3::8a2e:370:7334")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_data_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_prefix_length", "64")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectDataIPv6PrefixListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_data_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_expanded_community_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_expanded_community_list_profile_parcel.go new file mode 100644 index 00000000..90e62439 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_expanded_community_list_profile_parcel.go @@ -0,0 +1,249 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "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/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 = &PolicyObjectExpandedCommunityListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectExpandedCommunityListProfileParcelResource{} + +func NewPolicyObjectExpandedCommunityListProfileParcelResource() resource.Resource { + return &PolicyObjectExpandedCommunityListProfileParcelResource{} +} + +type PolicyObjectExpandedCommunityListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectExpandedCommunityListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_expanded_community_list_profile_parcel" +} + +func (r *PolicyObjectExpandedCommunityListProfileParcelResource) 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 Policy Object Expanded Community List 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, + }, + "expanded_community_lists": schema.SetAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Expanded Community List").String, + ElementType: types.StringType, + Required: true, + }, + "expanded_community_lists_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + } +} + +func (r *PolicyObjectExpandedCommunityListProfileParcelResource) 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 *PolicyObjectExpandedCommunityListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectExpandedCommunityList + + // 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 *PolicyObjectExpandedCommunityListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectExpandedCommunityList + + // 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 *PolicyObjectExpandedCommunityListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectExpandedCommunityList + + // 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 *PolicyObjectExpandedCommunityListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectExpandedCommunityList + + // 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 *PolicyObjectExpandedCommunityListProfileParcelResource) 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_policy_object_expanded_community_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_expanded_community_list_profile_parcel_test.go new file mode 100644 index 00000000..716b5807 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_expanded_community_list_profile_parcel_test.go @@ -0,0 +1,80 @@ +// 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 TestAccSdwanPolicyObjectExpandedCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectExpandedCommunityListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectExpandedCommunityListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectExpandedCommunityListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_expanded_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` expanded_community_lists = ["abcd"]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectExpandedCommunityListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_expanded_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` expanded_community_lists = ["abcd"]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_extended_community_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_extended_community_list_profile_parcel.go new file mode 100644 index 00000000..dfe180a4 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_extended_community_list_profile_parcel.go @@ -0,0 +1,258 @@ +// 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 = &PolicyObjectExtendedCommunityListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectExtendedCommunityListProfileParcelResource{} + +func NewPolicyObjectExtendedCommunityListProfileParcelResource() resource.Resource { + return &PolicyObjectExtendedCommunityListProfileParcelResource{} +} + +type PolicyObjectExtendedCommunityListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectExtendedCommunityListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_extended_community_list_profile_parcel" +} + +func (r *PolicyObjectExtendedCommunityListProfileParcelResource) 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 Policy Object Extended Community List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Extended Community List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "extended_community": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("can be soo 10.0.0.1:30 or rt 500:50 etc.").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`^(rt|soo) ([\d\.]+):(\d+)$`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectExtendedCommunityListProfileParcelResource) 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 *PolicyObjectExtendedCommunityListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectExtendedCommunityList + + // 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 *PolicyObjectExtendedCommunityListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectExtendedCommunityList + + // 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 *PolicyObjectExtendedCommunityListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectExtendedCommunityList + + // 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 *PolicyObjectExtendedCommunityListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectExtendedCommunityList + + // 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 *PolicyObjectExtendedCommunityListProfileParcelResource) 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_policy_object_extended_community_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_extended_community_list_profile_parcel_test.go new file mode 100644 index 00000000..60430b84 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_extended_community_list_profile_parcel_test.go @@ -0,0 +1,85 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAcc +func TestAccSdwanPolicyObjectExtendedCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_extended_community_list_profile_parcel.test", "entries.0.extended_community", "soo 10.0.0.1:30")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectExtendedCommunityListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectExtendedCommunityListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectExtendedCommunityListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_extended_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` extended_community = "soo 10.0.0.1:30"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectExtendedCommunityListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_extended_community_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` extended_community = "soo 10.0.0.1:30"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go new file mode 100644 index 00000000..cbb329d8 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_ipv4_prefix_list_profile_parcel.go @@ -0,0 +1,275 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "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 = &PolicyObjectIPv4PrefixListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectIPv4PrefixListProfileParcelResource{} + +func NewPolicyObjectIPv4PrefixListProfileParcelResource() resource.Resource { + return &PolicyObjectIPv4PrefixListProfileParcelResource{} +} + +type PolicyObjectIPv4PrefixListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectIPv4PrefixListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_ipv4_prefix_list_profile_parcel" +} + +func (r *PolicyObjectIPv4PrefixListProfileParcelResource) 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 Policy Object IPv4 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 Prefix List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv4_address": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 address").String, + Optional: true, + }, + "ipv4_prefix_length": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 prefix length").AddIntegerRangeDescription(0, 32).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.AtMost(32), + }, + }, + "le": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 prefix length with le range operator").AddIntegerRangeDescription(1, 32).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(1, 32), + }, + }, + "ge": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv4 prefix length with ge range operator").AddIntegerRangeDescription(1, 32).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(1, 32), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectIPv4PrefixListProfileParcelResource) 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 *PolicyObjectIPv4PrefixListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectIPv4PrefixList + + // 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 *PolicyObjectIPv4PrefixListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectIPv4PrefixList + + // 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 *PolicyObjectIPv4PrefixListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectIPv4PrefixList + + // 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 *PolicyObjectIPv4PrefixListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectIPv4PrefixList + + // 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 *PolicyObjectIPv4PrefixListProfileParcelResource) 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_policy_object_ipv4_prefix_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_ipv4_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..b9f42be5 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_ipv4_prefix_list_profile_parcel_test.go @@ -0,0 +1,94 @@ +// 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 TestAccSdwanPolicyObjectIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_address", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ipv4_prefix_length", "8")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.le", "24")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv4_prefix_list_profile_parcel.test", "entries.0.ge", "16")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectIPv4PrefixListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectIPv4PrefixListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectIPv4PrefixListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` le = 24` + "\n" + config += ` ge = 16` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectIPv4PrefixListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_ipv4_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv4_address = "10.0.0.0"` + "\n" + config += ` ipv4_prefix_length = 8` + "\n" + config += ` le = 24` + "\n" + config += ` ge = 16` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go new file mode 100644 index 00000000..caf498c0 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_ipv6_prefix_list_profile_parcel.go @@ -0,0 +1,275 @@ +// 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" + "sync" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "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 = &PolicyObjectIPv6PrefixListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectIPv6PrefixListProfileParcelResource{} + +func NewPolicyObjectIPv6PrefixListProfileParcelResource() resource.Resource { + return &PolicyObjectIPv6PrefixListProfileParcelResource{} +} + +type PolicyObjectIPv6PrefixListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectIPv6PrefixListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_ipv6_prefix_list_profile_parcel" +} + +func (r *PolicyObjectIPv6PrefixListProfileParcelResource) 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 Policy Object IPv6 Prefix List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 Prefix List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ipv6_address": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 address").String, + Optional: true, + }, + "ipv6_prefix_length": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 prefix length").AddIntegerRangeDescription(0, 128).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.AtMost(128), + }, + }, + "le": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 prefix length with le range operator").AddIntegerRangeDescription(1, 128).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(1, 128), + }, + }, + "ge": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("IPv6 prefix length with ge range operator").AddIntegerRangeDescription(1, 128).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.Between(1, 128), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectIPv6PrefixListProfileParcelResource) 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 *PolicyObjectIPv6PrefixListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectIPv6PrefixList + + // 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 *PolicyObjectIPv6PrefixListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectIPv6PrefixList + + // 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 *PolicyObjectIPv6PrefixListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectIPv6PrefixList + + // 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 *PolicyObjectIPv6PrefixListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectIPv6PrefixList + + // 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 *PolicyObjectIPv6PrefixListProfileParcelResource) 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_policy_object_ipv6_prefix_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_ipv6_prefix_list_profile_parcel_test.go new file mode 100644 index 00000000..ccfa82bd --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_ipv6_prefix_list_profile_parcel_test.go @@ -0,0 +1,94 @@ +// 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 TestAccSdwanPolicyObjectIPv6PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_address", "2001:db8:85a3::8a2e:370:7334")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ipv6_prefix_length", "64")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.le", "100")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_ipv6_prefix_list_profile_parcel.test", "entries.0.ge", "70")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectIPv6PrefixListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectIPv6PrefixListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectIPv6PrefixListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` le = 100` + "\n" + config += ` ge = 70` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectIPv6PrefixListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_ipv6_prefix_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` ipv6_address = "2001:db8:85a3::8a2e:370:7334"` + "\n" + config += ` ipv6_prefix_length = 64` + "\n" + config += ` le = 100` + "\n" + config += ` ge = 70` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_policer_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_policer_profile_parcel.go index f01bcd4c..ea7bf104 100644 --- a/internal/provider/resource_sdwan_policy_object_policer_profile_parcel.go +++ b/internal/provider/resource_sdwan_policy_object_policer_profile_parcel.go @@ -100,7 +100,7 @@ func (r *PolicyObjectPolicerProfileParcelResource) Schema(ctx context.Context, r int64validator.Between(15000, 10000000), }, }, - "select_value": schema.StringAttribute{ + "exceed_action": schema.StringAttribute{ MarkdownDescription: helpers.NewAttributeDescription("Exceed options such as Drop or Remark").AddStringEnumDescription("drop", "remark").String, Optional: true, Validators: []validator.String{ diff --git a/internal/provider/resource_sdwan_policy_object_policer_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_policer_profile_parcel_test.go index 211f88f2..6acfa2dd 100644 --- a/internal/provider/resource_sdwan_policy_object_policer_profile_parcel_test.go +++ b/internal/provider/resource_sdwan_policy_object_policer_profile_parcel_test.go @@ -34,7 +34,7 @@ func TestAccSdwanPolicyObjectPolicerProfileParcel(t *testing.T) { } var checks []resource.TestCheckFunc checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_policer_profile_parcel.test", "entries.0.burst_bytes", "56500")) - checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_policer_profile_parcel.test", "entries.0.select_value", "remark")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_policer_profile_parcel.test", "entries.0.exceed_action", "remark")) checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_policer_profile_parcel.test", "entries.0.rate_bps", "60000")) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -64,7 +64,7 @@ func testAccSdwanPolicyObjectPolicerProfileParcelConfig_minimum() string { config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" config += ` entries = [{` + "\n" config += ` burst_bytes = 56500` + "\n" - config += ` select_value = "remark"` + "\n" + config += ` exceed_action = "remark"` + "\n" config += ` rate_bps = 60000` + "\n" config += ` }]` + "\n" config += `}` + "\n" @@ -81,7 +81,7 @@ func testAccSdwanPolicyObjectPolicerProfileParcelConfig_all() string { config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" config += ` entries = [{` + "\n" config += ` burst_bytes = 56500` + "\n" - config += ` select_value = "remark"` + "\n" + config += ` exceed_action = "remark"` + "\n" config += ` rate_bps = 60000` + "\n" config += ` }]` + "\n" config += `}` + "\n" diff --git a/internal/provider/resource_sdwan_policy_object_tloc_list_profile_parcel.go b/internal/provider/resource_sdwan_policy_object_tloc_list_profile_parcel.go new file mode 100644 index 00000000..4056cbcb --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_tloc_list_profile_parcel.go @@ -0,0 +1,272 @@ +// 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" + "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 = &PolicyObjectTLOCListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectTLOCListProfileParcelResource{} + +func NewPolicyObjectTLOCListProfileParcelResource() resource.Resource { + return &PolicyObjectTLOCListProfileParcelResource{} +} + +type PolicyObjectTLOCListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectTLOCListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_tloc_list_profile_parcel" +} + +func (r *PolicyObjectTLOCListProfileParcelResource) 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 Policy Object TLOC List 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, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("TLOC List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "tloc_ip": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("tloc").String, + Optional: true, + }, + "color": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("color").AddStringEnumDescription("3g", "biz-internet", "blue", "bronze", "custom1", "custom2", "custom3", "default", "gold", "green", "lte", "metro-ethernet", "mpls", "private1", "private2", "private3", "private4", "private5", "private6", "public-internet", "red", "silver").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("3g", "biz-internet", "blue", "bronze", "custom1", "custom2", "custom3", "default", "gold", "green", "lte", "metro-ethernet", "mpls", "private1", "private2", "private3", "private4", "private5", "private6", "public-internet", "red", "silver"), + }, + }, + "encapsulation": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("encapsulation").AddStringEnumDescription("ipsec", "gre").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("ipsec", "gre"), + }, + }, + "preference": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Preference").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectTLOCListProfileParcelResource) 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 *PolicyObjectTLOCListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectTLOCList + + // 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 *PolicyObjectTLOCListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectTLOCList + + // 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 *PolicyObjectTLOCListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectTLOCList + + // 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 *PolicyObjectTLOCListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectTLOCList + + // 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 *PolicyObjectTLOCListProfileParcelResource) 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_policy_object_tloc_list_profile_parcel_test.go b/internal/provider/resource_sdwan_policy_object_tloc_list_profile_parcel_test.go new file mode 100644 index 00000000..e6aeab12 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_tloc_list_profile_parcel_test.go @@ -0,0 +1,94 @@ +// 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 TestAccSdwanPolicyObjectTLOCListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" && os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012 or POLICY_OBJECT_FEATURE_TEMPLATE_ID") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.tloc_ip", "10.0.0.0")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.color", "3g")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.encapsulation", "gre")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_tloc_list_profile_parcel.test", "entries.0.preference", "33")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccSdwanPolicyObjectTLOCListProfileParcelConfig_minimum(), + }, + { + Config: testAccSdwanPolicyObjectTLOCListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum +func testAccSdwanPolicyObjectTLOCListProfileParcelConfig_minimum() string { + config := `resource "sdwan_policy_object_tloc_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_MIN"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` tloc_ip = "10.0.0.0"` + "\n" + config += ` color = "3g"` + "\n" + config += ` encapsulation = "gre"` + "\n" + config += ` preference = "33"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectTLOCListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_tloc_list_profile_parcel" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = ` + "\"" + os.Getenv("POLICY_OBJECT_FEATURE_TEMPLATE_ID") + "\"" + `` + "\n" + config += ` entries = [{` + "\n" + config += ` tloc_ip = "10.0.0.0"` + "\n" + config += ` color = "3g"` + "\n" + config += ` encapsulation = "gre"` + "\n" + config += ` preference = "33"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll