diff --git a/CHANGELOG.md b/CHANGELOG.md index 524fe6630..f8bbe1ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ - Add `sdwan_policy_object_application_list` resource and data source - Add `sdwan_policy_object_sla_class_list` resource and data source +- Add `sdwan_policy_object_app_probe_class` resource and data source +- Add `sdwan_policy_object_as_path_list` resource and data source +- Add `sdwan_policy_object_vpn_group` resource and data source +- Add `sdwan_policy_object_security_data_ipv4_prefix_list` resource and data source +- Add `sdwan_policy_object_security_fqdn_list` resource and data source +- Add `sdwan_policy_object_security_geolocation_list` resource and data source +- Add `sdwan_policy_object_security_ips_signature` resource and data source +- Add `sdwan_policy_object_security_local_domain_list` resource and data source +- Add `sdwan_policy_object_security_port_list` resource and data source +- Add `sdwan_policy_object_security_scalable_group_tag_list` resource and data source +- Add `sdwan_policy_object_security_url_list` resource and data source +- Add `sdwan_policy_object_preferred_color_group` resource and data source +- Add `sdwan_policy_object_security_identity_list` resource and data source +- Add `sdwan_policy_object_security_local_application_list` resource and data source +- Add `sdwan_policy_object_standard_community_list` resource and data source ## 0.4.1 diff --git a/docs/data-sources/policy_object_app_probe_class.md b/docs/data-sources/policy_object_app_probe_class.md new file mode 100644 index 000000000..a4aa2ba6c --- /dev/null +++ b/docs/data-sources/policy_object_app_probe_class.md @@ -0,0 +1,51 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_app_probe_class Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object App Probe Class Policy_object. +--- + +# sdwan_policy_object_app_probe_class (Data Source) + +This data source can read the Policy Object App Probe Class Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_app_probe_class" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) App Probe List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `forwarding_class` (String) Forwarding Class Name +- `map` (Attributes List) Map (see [below for nested schema](#nestedatt--entries--map)) + + +### Nested Schema for `entries.map` + +Read-Only: + +- `color` (String) Color +- `dscp` (Number) DSCP number diff --git a/docs/data-sources/policy_object_as_path_list.md b/docs/data-sources/policy_object_as_path_list.md new file mode 100644 index 000000000..d41d05cce --- /dev/null +++ b/docs/data-sources/policy_object_as_path_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_as_path_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object AS Path List Policy_object. +--- + +# sdwan_policy_object_as_path_list (Data Source) + +This data source can read the Policy Object AS Path List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_as_path_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `as_path_list_id` (Number) As path List Number +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) AS Path List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `as_path_list` (String) diff --git a/docs/data-sources/policy_object_feature_profile.md b/docs/data-sources/policy_object_feature_profile.md index 302f195ba..12a6b1e57 100644 --- a/docs/data-sources/policy_object_feature_profile.md +++ b/docs/data-sources/policy_object_feature_profile.md @@ -21,8 +21,11 @@ data "sdwan_policy_object_feature_profile" "example" { ## Schema +### Required + +- `id` (String) The id of the object + ### Read-Only - `description` (String) Description -- `id` (String) The id of the object - `name` (String) The name of the policy object feature profile diff --git a/docs/data-sources/policy_object_preferred_color_group.md b/docs/data-sources/policy_object_preferred_color_group.md new file mode 100644 index 000000000..f91fe05f9 --- /dev/null +++ b/docs/data-sources/policy_object_preferred_color_group.md @@ -0,0 +1,47 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_preferred_color_group Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Preferred Color Group Policy_object. +--- + +# sdwan_policy_object_preferred_color_group (Data Source) + +This data source can read the Policy Object Preferred Color Group Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_preferred_color_group" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Preferred Color Group List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `primary_color_preference` (Set of String) +- `primary_path_preference` (String) +- `secondary_color_preference` (Set of String) +- `secondary_path_preference` (String) +- `tertiary_color_preference` (Set of String) +- `tertiary_path_preference` (String) diff --git a/docs/data-sources/policy_object_security_data_ipv4_prefix_list.md b/docs/data-sources/policy_object_security_data_ipv4_prefix_list.md new file mode 100644 index 000000000..5615d1533 --- /dev/null +++ b/docs/data-sources/policy_object_security_data_ipv4_prefix_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_data_ipv4_prefix_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Data IPv4 Prefix List Policy_object. +--- + +# sdwan_policy_object_security_data_ipv4_prefix_list (Data Source) + +This data source can read the Policy Object Security Data IPv4 Prefix List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_data_ipv4_prefix_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `ip_prefix` (String) +- `ip_prefix_variable` (String) Variable name diff --git a/docs/data-sources/policy_object_security_fqdn_list.md b/docs/data-sources/policy_object_security_fqdn_list.md new file mode 100644 index 000000000..0c765096d --- /dev/null +++ b/docs/data-sources/policy_object_security_fqdn_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_fqdn_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security FQDN List Policy_object. +--- + +# sdwan_policy_object_security_fqdn_list (Data Source) + +This data source can read the Policy Object Security FQDN List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_fqdn_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `pattern` (String) diff --git a/docs/data-sources/policy_object_security_geolocation_list.md b/docs/data-sources/policy_object_security_geolocation_list.md new file mode 100644 index 000000000..784d89999 --- /dev/null +++ b/docs/data-sources/policy_object_security_geolocation_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_geolocation_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Geolocation List Policy_object. +--- + +# sdwan_policy_object_security_geolocation_list (Data Source) + +This data source can read the Policy Object Security Geolocation List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_geolocation_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Geolocation List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `continent` (String) continent name +- `country` (String) country names diff --git a/docs/data-sources/policy_object_security_identity_list.md b/docs/data-sources/policy_object_security_identity_list.md new file mode 100644 index 000000000..352b21b15 --- /dev/null +++ b/docs/data-sources/policy_object_security_identity_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_identity_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Identity List Policy_object. +--- + +# sdwan_policy_object_security_identity_list (Data Source) + +This data source can read the Policy Object Security Identity List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_identity_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Array of Users and User Groups (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `user` (String) +- `user_group` (String) diff --git a/docs/data-sources/policy_object_security_ips_signature.md b/docs/data-sources/policy_object_security_ips_signature.md new file mode 100644 index 000000000..2dcb5706d --- /dev/null +++ b/docs/data-sources/policy_object_security_ips_signature.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_ips_signature Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security IPS Signature Policy_object. +--- + +# sdwan_policy_object_security_ips_signature (Data Source) + +This data source can read the Policy Object Security IPS Signature Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_ips_signature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Ips Signature (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `generator_id` (String) +- `signature_id` (String) diff --git a/docs/data-sources/policy_object_security_local_application_list.md b/docs/data-sources/policy_object_security_local_application_list.md new file mode 100644 index 000000000..c1802d21b --- /dev/null +++ b/docs/data-sources/policy_object_security_local_application_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_local_application_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Local Application List Policy_object. +--- + +# sdwan_policy_object_security_local_application_list (Data Source) + +This data source can read the Policy Object Security Local Application List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_local_application_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Localapp list (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `app` (String) +- `app_family` (String) diff --git a/docs/data-sources/policy_object_security_local_domain_list.md b/docs/data-sources/policy_object_security_local_domain_list.md new file mode 100644 index 000000000..3a5f79b02 --- /dev/null +++ b/docs/data-sources/policy_object_security_local_domain_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_local_domain_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Local Domain List Policy_object. +--- + +# sdwan_policy_object_security_local_domain_list (Data Source) + +This data source can read the Policy Object Security Local Domain List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_local_domain_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `local_domain` (String) diff --git a/docs/data-sources/policy_object_security_port_list.md b/docs/data-sources/policy_object_security_port_list.md new file mode 100644 index 000000000..ca2f79436 --- /dev/null +++ b/docs/data-sources/policy_object_security_port_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_port_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Port List Policy_object. +--- + +# sdwan_policy_object_security_port_list (Data Source) + +This data source can read the Policy Object Security Port List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_port_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Port List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `port` (String) can be single port or port range diff --git a/docs/data-sources/policy_object_security_scalable_group_tag_list.md b/docs/data-sources/policy_object_security_scalable_group_tag_list.md new file mode 100644 index 000000000..61e1b035b --- /dev/null +++ b/docs/data-sources/policy_object_security_scalable_group_tag_list.md @@ -0,0 +1,43 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_scalable_group_tag_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security Scalable Group Tag List Policy_object. +--- + +# sdwan_policy_object_security_scalable_group_tag_list (Data Source) + +This data source can read the Policy Object Security Scalable Group Tag List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_scalable_group_tag_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `sgt_name` (String) +- `tag` (String) diff --git a/docs/data-sources/policy_object_security_url_list.md b/docs/data-sources/policy_object_security_url_list.md new file mode 100644 index 000000000..f5365f1ef --- /dev/null +++ b/docs/data-sources/policy_object_security_url_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_url_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Security URL List Policy_object. +--- + +# sdwan_policy_object_security_url_list (Data Source) + +This data source can read the Policy Object Security URL List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_security_url_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) URL List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `pattern` (String) valid url pattern diff --git a/docs/data-sources/policy_object_standard_community_list.md b/docs/data-sources/policy_object_standard_community_list.md new file mode 100644 index 000000000..fac069aac --- /dev/null +++ b/docs/data-sources/policy_object_standard_community_list.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_standard_community_list Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object Standard Community List Policy_object. +--- + +# sdwan_policy_object_standard_community_list (Data Source) + +This data source can read the Policy Object Standard Community List Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_standard_community_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Standard Community List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `standard_community` (String) Standard Community diff --git a/docs/data-sources/policy_object_vpn_group.md b/docs/data-sources/policy_object_vpn_group.md new file mode 100644 index 000000000..dfb06adb9 --- /dev/null +++ b/docs/data-sources/policy_object_vpn_group.md @@ -0,0 +1,42 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_vpn_group Data Source - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This data source can read the Policy Object VPN Group Policy_object. +--- + +# sdwan_policy_object_vpn_group (Data Source) + +This data source can read the Policy Object VPN Group Policy_object. + +## Example Usage + +```terraform +data "sdwan_policy_object_vpn_group" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `id` (String) The id of the Policy_object + +### Read-Only + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) VPN List (see [below for nested schema](#nestedatt--entries)) +- `name` (String) The name of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Read-Only: + +- `vpn` (Number) can be single vpn id or vpn id range diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index aed0b4675..aa381ced9 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -11,6 +11,21 @@ description: |- - Add `sdwan_policy_object_application_list` resource and data source - Add `sdwan_policy_object_sla_class_list` resource and data source +- Add `sdwan_policy_object_app_probe_class` resource and data source +- Add `sdwan_policy_object_as_path_list` resource and data source +- Add `sdwan_policy_object_vpn_group` resource and data source +- Add `sdwan_policy_object_security_data_ipv4_prefix_list` resource and data source +- Add `sdwan_policy_object_security_fqdn_list` resource and data source +- Add `sdwan_policy_object_security_geolocation_list` resource and data source +- Add `sdwan_policy_object_security_ips_signature` resource and data source +- Add `sdwan_policy_object_security_local_domain_list` resource and data source +- Add `sdwan_policy_object_security_port_list` resource and data source +- Add `sdwan_policy_object_security_scalable_group_tag_list` resource and data source +- Add `sdwan_policy_object_security_url_list` resource and data source +- Add `sdwan_policy_object_preferred_color_group` resource and data source +- Add `sdwan_policy_object_security_identity_list` resource and data source +- Add `sdwan_policy_object_security_local_application_list` resource and data source +- Add `sdwan_policy_object_standard_community_list` resource and data source ## 0.4.1 diff --git a/docs/resources/policy_object_app_probe_class.md b/docs/resources/policy_object_app_probe_class.md new file mode 100644 index 000000000..96c29af52 --- /dev/null +++ b/docs/resources/policy_object_app_probe_class.md @@ -0,0 +1,78 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_app_probe_class Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object App Probe Class Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_app_probe_class (Resource) + +This resource can manage a Policy Object App Probe Class Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_app_probe_class" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + map = [ + { + color = "3g" + dscp = 45 + } + ] + forwarding_class = "classlist1" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) App Probe List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `forwarding_class` (String) Forwarding Class Name +- `map` (Attributes List) Map (see [below for nested schema](#nestedatt--entries--map)) + + +### Nested Schema for `entries.map` + +Optional: + +- `color` (String) Color + - Choices: `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` +- `dscp` (Number) DSCP number + - Range: `0`-`63` + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_app_probe_class.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_as_path_list.md b/docs/resources/policy_object_as_path_list.md new file mode 100644 index 000000000..e9d690532 --- /dev/null +++ b/docs/resources/policy_object_as_path_list.md @@ -0,0 +1,64 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_as_path_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object AS Path List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_as_path_list (Resource) + +This resource can manage a Policy Object AS Path List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_as_path_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + as_path_list_id = 1 + entries = [ + { + as_path_list = "110" + } + ] +} +``` + + +## Schema + +### Required + +- `as_path_list_id` (Number) As path List Number + - Range: `1`-`500` +- `entries` (Attributes List) AS Path List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `as_path_list` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_as_path_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_preferred_color_group.md b/docs/resources/policy_object_preferred_color_group.md new file mode 100644 index 000000000..df1f86625 --- /dev/null +++ b/docs/resources/policy_object_preferred_color_group.md @@ -0,0 +1,71 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_preferred_color_group Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Preferred Color Group Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_preferred_color_group (Resource) + +This resource can manage a Policy Object Preferred Color Group Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_preferred_color_group" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + primary_color_preference = ["default"] + primary_path_preference = "direct-path" + secondary_color_preference = ["bronze"] + secondary_path_preference = "all-paths" + tertiary_color_preference = ["blue"] + tertiary_path_preference = "all-paths" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) Preferred Color Group List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `primary_color_preference` (Set of String) +- `primary_path_preference` (String) - Choices: `all-paths`, `direct-path`, `multi-hop-path` +- `secondary_color_preference` (Set of String) +- `secondary_path_preference` (String) - Choices: `all-paths`, `direct-path`, `multi-hop-path` +- `tertiary_color_preference` (Set of String) +- `tertiary_path_preference` (String) - Choices: `all-paths`, `direct-path`, `multi-hop-path` + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_preferred_color_group.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_data_ipv4_prefix_list.md b/docs/resources/policy_object_security_data_ipv4_prefix_list.md new file mode 100644 index 000000000..f0dc96199 --- /dev/null +++ b/docs/resources/policy_object_security_data_ipv4_prefix_list.md @@ -0,0 +1,62 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_data_ipv4_prefix_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Data IPv4 Prefix List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_data_ipv4_prefix_list (Resource) + +This resource can manage a Policy Object Security Data IPv4 Prefix List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_data_ipv4_prefix_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ip_prefix = "10.0.0.0/12" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `ip_prefix` (String) +- `ip_prefix_variable` (String) Variable name + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_data_ipv4_prefix_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_fqdn_list.md b/docs/resources/policy_object_security_fqdn_list.md new file mode 100644 index 000000000..c19f6b342 --- /dev/null +++ b/docs/resources/policy_object_security_fqdn_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_fqdn_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security FQDN List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_fqdn_list (Resource) + +This resource can manage a Policy Object Security FQDN List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_fqdn_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + pattern = "cisco.com" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `pattern` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_fqdn_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_geolocation_list.md b/docs/resources/policy_object_security_geolocation_list.md new file mode 100644 index 000000000..5afe89ad3 --- /dev/null +++ b/docs/resources/policy_object_security_geolocation_list.md @@ -0,0 +1,64 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_geolocation_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Geolocation List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_geolocation_list (Resource) + +This resource can manage a Policy Object Security Geolocation List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_geolocation_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + country = "DZA" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) Geolocation List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `continent` (String) continent name + - Choices: `AF`, `AN`, `AS`, `EU`, `NA`, `OC`, `SA` +- `country` (String) country names + - Choices: `AFG`, `ALB`, `ATA`, `DZA`, `ASM`, `AND`, `AGO`, `ATG`, `AZE`, `ARG`, `AUS`, `AUT`, `BHS`, `BHR`, `BGD`, `ARM`, `BRB`, `BEL`, `BMU`, `BTN`, `BOL`, `BIH`, `BWA`, `BVT`, `BRA`, `BLZ`, `IOT`, `SLB`, `VGB`, `BRN`, `BGR`, `MMR`, `BDI`, `BLR`, `KHM`, `CMR`, `CAN`, `CPV`, `CYM`, `CAF`, `LKA`, `TCD`, `CHL`, `CHN`, `TWN`, `CXR`, `CCK`, `COL`, `COM`, `MYT`, `COG`, `COD`, `COK`, `CRI`, `HRV`, `CUB`, `CYP`, `CZE`, `BEN`, `DNK`, `DMA`, `DOM`, `ECU`, `SLV`, `GNQ`, `ETH`, `ERI`, `EST`, `FRO`, `FLK`, `SGS`, `FJI`, `FIN`, `ALA`, `FRA`, `GUF`, `PYF`, `ATF`, `DJI`, `GAB`, `GEO`, `GMB`, `PSE`, `DEU`, `GHA`, `GIB`, `KIR`, `GRC`, `GRL`, `GRD`, `GLP`, `GUM`, `GTM`, `GIN`, `GUY`, `HTI`, `HMD`, `VAT`, `HND`, `HKG`, `HUN`, `ISL`, `IND`, `IDN`, `IRN`, `IRQ`, `IRL`, `ISR`, `ITA`, `CIV`, `JAM`, `JPN`, `KAZ`, `JOR`, `KEN`, `PRK`, `KOR`, `KWT`, `KGZ`, `LAO`, `LBN`, `LSO`, `LVA`, `LBR`, `LBY`, `LIE`, `LTU`, `LUX`, `MAC`, `MDG`, `MWI`, `MYS`, `MDV`, `MLI`, `MLT`, `MTQ`, `MRT`, `MUS`, `MEX`, `MCO`, `MNG`, `MDA`, `MNE`, `MSR`, `MAR`, `MOZ`, `OMN`, `NAM`, `NRU`, `NPL`, `NLD`, `ANT`, `CUW`, `ABW`, `SXM`, `BES`, `NCL`, `VUT`, `NZL`, `NIC`, `NER`, `NGA`, `NIU`, `NFK`, `NOR`, `MNP`, `UMI`, `FSM`, `MHL`, `PLW`, `PAK`, `PAN`, `PNG`, `PRY`, `PER`, `PHL`, `PCN`, `POL`, `PRT`, `GNB`, `TLS`, `PRI`, `QAT`, `REU`, `ROU`, `RUS`, `RWA`, `BLM`, `SHN`, `KNA`, `AIA`, `LCA`, `MAF`, `SPM`, `VCT`, `SMR`, `STP`, `SAU`, `SEN`, `SRB`, `SYC`, `SLE`, `SGP`, `SVK`, `VNM`, `SVN`, `SOM`, `ZAF`, `ZWE`, `ESP`, `SSD`, `ESH`, `SDN`, `SUR`, `SJM`, `SWZ`, `SWE`, `CHE`, `SYR`, `TJK`, `THA`, `TGO`, `TKL`, `TON`, `TTO`, `ARE`, `TUN`, `TUR`, `TKM`, `TCA`, `TUV`, `UGA`, `UKR`, `MKD`, `EGY`, `GBR`, `GGY`, `JEY`, `IMN`, `TZA`, `USA`, `VIR`, `BFA`, `URY`, `UZB`, `VEN`, `WLF`, `WSM`, `YEM`, `ZMB` + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_geolocation_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_identity_list.md b/docs/resources/policy_object_security_identity_list.md new file mode 100644 index 000000000..f4885b9ce --- /dev/null +++ b/docs/resources/policy_object_security_identity_list.md @@ -0,0 +1,62 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_identity_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Identity List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_identity_list (Resource) + +This resource can manage a Policy Object Security Identity List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_identity_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + user = "administrator" + } + ] +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Array of Users and User Groups (see [below for nested schema](#nestedatt--entries)) + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `user` (String) +- `user_group` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_identity_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_ips_signature.md b/docs/resources/policy_object_security_ips_signature.md new file mode 100644 index 000000000..fce9a641e --- /dev/null +++ b/docs/resources/policy_object_security_ips_signature.md @@ -0,0 +1,63 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_ips_signature Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security IPS Signature Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_ips_signature (Resource) + +This resource can manage a Policy Object Security IPS Signature Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_ips_signature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + generator_id = "1234" + signature_id = "5678" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) Ips Signature (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `generator_id` (String) +- `signature_id` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_ips_signature.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_local_application_list.md b/docs/resources/policy_object_security_local_application_list.md new file mode 100644 index 000000000..606a9a922 --- /dev/null +++ b/docs/resources/policy_object_security_local_application_list.md @@ -0,0 +1,62 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_local_application_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Local Application List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_local_application_list (Resource) + +This resource can manage a Policy Object Security Local Application List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_local_application_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + app = "audible-com" + } + ] +} +``` + + +## Schema + +### Required + +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object +- `entries` (Attributes List) Localapp list (see [below for nested schema](#nestedatt--entries)) + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `app` (String) +- `app_family` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_local_application_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_local_domain_list.md b/docs/resources/policy_object_security_local_domain_list.md new file mode 100644 index 000000000..4ed91f923 --- /dev/null +++ b/docs/resources/policy_object_security_local_domain_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_local_domain_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Local Domain List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_local_domain_list (Resource) + +This resource can manage a Policy Object Security Local Domain List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_local_domain_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + local_domain = "hello.com" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `local_domain` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_local_domain_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_port_list.md b/docs/resources/policy_object_security_port_list.md new file mode 100644 index 000000000..65b0bcc23 --- /dev/null +++ b/docs/resources/policy_object_security_port_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_port_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Port List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_port_list (Resource) + +This resource can manage a Policy Object Security Port List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_port_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + port = "100" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) Port List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `port` (String) can be single port or port range + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_port_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_scalable_group_tag_list.md b/docs/resources/policy_object_security_scalable_group_tag_list.md new file mode 100644 index 000000000..c97ede113 --- /dev/null +++ b/docs/resources/policy_object_security_scalable_group_tag_list.md @@ -0,0 +1,63 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_scalable_group_tag_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security Scalable Group Tag List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_scalable_group_tag_list (Resource) + +This resource can manage a Policy Object Security Scalable Group Tag List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_scalable_group_tag_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "" + entries = [ + { + sgt_name = "ANY" + tag = "65535" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `sgt_name` (String) +- `tag` (String) + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_scalable_group_tag_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_security_url_list.md b/docs/resources/policy_object_security_url_list.md new file mode 100644 index 000000000..53162beca --- /dev/null +++ b/docs/resources/policy_object_security_url_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_security_url_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Security URL List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_security_url_list (Resource) + +This resource can manage a Policy Object Security URL List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_security_url_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + pattern = "www.cisco.com" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) URL List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `pattern` (String) valid url pattern + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_security_url_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_standard_community_list.md b/docs/resources/policy_object_standard_community_list.md new file mode 100644 index 000000000..fcf9ec091 --- /dev/null +++ b/docs/resources/policy_object_standard_community_list.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_standard_community_list Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object Standard Community List Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_standard_community_list (Resource) + +This resource can manage a Policy Object Standard Community List Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_standard_community_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + standard_community = "1000:10000" + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) Standard Community List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `standard_community` (String) Standard Community + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_standard_community_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/docs/resources/policy_object_vpn_group.md b/docs/resources/policy_object_vpn_group.md new file mode 100644 index 000000000..175f433db --- /dev/null +++ b/docs/resources/policy_object_vpn_group.md @@ -0,0 +1,61 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "sdwan_policy_object_vpn_group Resource - terraform-provider-sdwan" +subcategory: "Policy Objects" +description: |- + This resource can manage a Policy Object VPN Group Policy_object. + Minimum SD-WAN Manager version: 20.12.0 +--- + +# sdwan_policy_object_vpn_group (Resource) + +This resource can manage a Policy Object VPN Group Policy_object. + - Minimum SD-WAN Manager version: `20.12.0` + +## Example Usage + +```terraform +resource "sdwan_policy_object_vpn_group" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + vpn = 100 + } + ] +} +``` + + +## Schema + +### Required + +- `entries` (Attributes List) VPN List (see [below for nested schema](#nestedatt--entries)) +- `feature_profile_id` (String) Feature Profile ID +- `name` (String) The name of the Policy_object + +### Optional + +- `description` (String) The description of the Policy_object + +### Read-Only + +- `id` (String) The id of the Policy_object +- `version` (Number) The version of the Policy_object + + +### Nested Schema for `entries` + +Optional: + +- `vpn` (Number) can be single vpn id or vpn id range + +## Import + +Import is supported using the following syntax: + +```shell +terraform import sdwan_policy_object_vpn_group.example "f6b2c44c-693c-4763-b010-895aa3d236bd" +``` diff --git a/examples/data-sources/sdwan_policy_object_app_probe_class/data-source.tf b/examples/data-sources/sdwan_policy_object_app_probe_class/data-source.tf new file mode 100644 index 000000000..644c90010 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_app_probe_class/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_app_probe_class" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_as_path_list/data-source.tf b/examples/data-sources/sdwan_policy_object_as_path_list/data-source.tf new file mode 100644 index 000000000..3afbcc2b4 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_as_path_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_as_path_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_preferred_color_group/data-source.tf b/examples/data-sources/sdwan_policy_object_preferred_color_group/data-source.tf new file mode 100644 index 000000000..9d9abb0b6 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_preferred_color_group/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_preferred_color_group" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_data_ipv4_prefix_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_data_ipv4_prefix_list/data-source.tf new file mode 100644 index 000000000..eed34281a --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_data_ipv4_prefix_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_data_ipv4_prefix_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_fqdn_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_fqdn_list/data-source.tf new file mode 100644 index 000000000..aeac8b930 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_fqdn_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_fqdn_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_geolocation_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_geolocation_list/data-source.tf new file mode 100644 index 000000000..e24422cc8 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_geolocation_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_geolocation_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_identity_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_identity_list/data-source.tf new file mode 100644 index 000000000..0acf77060 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_identity_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_identity_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_ips_signature/data-source.tf b/examples/data-sources/sdwan_policy_object_security_ips_signature/data-source.tf new file mode 100644 index 000000000..4cde1be9e --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_ips_signature/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_ips_signature" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_local_application_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_local_application_list/data-source.tf new file mode 100644 index 000000000..f1ead41ba --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_local_application_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_local_application_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_local_domain_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_local_domain_list/data-source.tf new file mode 100644 index 000000000..917e2a95e --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_local_domain_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_local_domain_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_port_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_port_list/data-source.tf new file mode 100644 index 000000000..44318b2ea --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_port_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_port_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_security_scalable_group_tag_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_scalable_group_tag_list/data-source.tf new file mode 100644 index 000000000..4d8aa7cd2 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_scalable_group_tag_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_scalable_group_tag_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "" +} diff --git a/examples/data-sources/sdwan_policy_object_security_url_list/data-source.tf b/examples/data-sources/sdwan_policy_object_security_url_list/data-source.tf new file mode 100644 index 000000000..b1c7e1fab --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_security_url_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_security_url_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_standard_community_list/data-source.tf b/examples/data-sources/sdwan_policy_object_standard_community_list/data-source.tf new file mode 100644 index 000000000..5490c951a --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_standard_community_list/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_standard_community_list" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/data-sources/sdwan_policy_object_vpn_group/data-source.tf b/examples/data-sources/sdwan_policy_object_vpn_group/data-source.tf new file mode 100644 index 000000000..5f6f7e9f0 --- /dev/null +++ b/examples/data-sources/sdwan_policy_object_vpn_group/data-source.tf @@ -0,0 +1,4 @@ +data "sdwan_policy_object_vpn_group" "example" { + id = "f6b2c44c-693c-4763-b010-895aa3d236bd" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" +} diff --git a/examples/resources/sdwan_policy_object_app_probe_class/import.sh b/examples/resources/sdwan_policy_object_app_probe_class/import.sh new file mode 100644 index 000000000..bdffae31e --- /dev/null +++ b/examples/resources/sdwan_policy_object_app_probe_class/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_app_probe_class.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_app_probe_class/resource.tf b/examples/resources/sdwan_policy_object_app_probe_class/resource.tf new file mode 100644 index 000000000..fcf1aa030 --- /dev/null +++ b/examples/resources/sdwan_policy_object_app_probe_class/resource.tf @@ -0,0 +1,16 @@ +resource "sdwan_policy_object_app_probe_class" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + map = [ + { + color = "3g" + dscp = 45 + } + ] + forwarding_class = "classlist1" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_as_path_list/import.sh b/examples/resources/sdwan_policy_object_as_path_list/import.sh new file mode 100644 index 000000000..644d52273 --- /dev/null +++ b/examples/resources/sdwan_policy_object_as_path_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_as_path_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_as_path_list/resource.tf b/examples/resources/sdwan_policy_object_as_path_list/resource.tf new file mode 100644 index 000000000..2bba15ef9 --- /dev/null +++ b/examples/resources/sdwan_policy_object_as_path_list/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_policy_object_as_path_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + as_path_list_id = 1 + entries = [ + { + as_path_list = "110" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_preferred_color_group/import.sh b/examples/resources/sdwan_policy_object_preferred_color_group/import.sh new file mode 100644 index 000000000..1f8914fd8 --- /dev/null +++ b/examples/resources/sdwan_policy_object_preferred_color_group/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_preferred_color_group.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_preferred_color_group/resource.tf b/examples/resources/sdwan_policy_object_preferred_color_group/resource.tf new file mode 100644 index 000000000..407c71c45 --- /dev/null +++ b/examples/resources/sdwan_policy_object_preferred_color_group/resource.tf @@ -0,0 +1,15 @@ +resource "sdwan_policy_object_preferred_color_group" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + primary_color_preference = ["default"] + primary_path_preference = "direct-path" + secondary_color_preference = ["bronze"] + secondary_path_preference = "all-paths" + tertiary_color_preference = ["blue"] + tertiary_path_preference = "all-paths" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/import.sh b/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/import.sh new file mode 100644 index 000000000..28998eea0 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_data_ipv4_prefix_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/resource.tf b/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/resource.tf new file mode 100644 index 000000000..6cfd38d43 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_data_ipv4_prefix_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_data_ipv4_prefix_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + ip_prefix = "10.0.0.0/12" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_fqdn_list/import.sh b/examples/resources/sdwan_policy_object_security_fqdn_list/import.sh new file mode 100644 index 000000000..2996ad5c5 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_fqdn_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_fqdn_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_fqdn_list/resource.tf b/examples/resources/sdwan_policy_object_security_fqdn_list/resource.tf new file mode 100644 index 000000000..19d6576ef --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_fqdn_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_fqdn_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + pattern = "cisco.com" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_geolocation_list/import.sh b/examples/resources/sdwan_policy_object_security_geolocation_list/import.sh new file mode 100644 index 000000000..6fbf478dc --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_geolocation_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_geolocation_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_geolocation_list/resource.tf b/examples/resources/sdwan_policy_object_security_geolocation_list/resource.tf new file mode 100644 index 000000000..3a4a050f5 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_geolocation_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_geolocation_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + country = "DZA" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_identity_list/import.sh b/examples/resources/sdwan_policy_object_security_identity_list/import.sh new file mode 100644 index 000000000..69b628a91 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_identity_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_identity_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_identity_list/resource.tf b/examples/resources/sdwan_policy_object_security_identity_list/resource.tf new file mode 100644 index 000000000..93e68f035 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_identity_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_identity_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + user = "administrator" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_ips_signature/import.sh b/examples/resources/sdwan_policy_object_security_ips_signature/import.sh new file mode 100644 index 000000000..9aa08eb5c --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_ips_signature/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_ips_signature.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_ips_signature/resource.tf b/examples/resources/sdwan_policy_object_security_ips_signature/resource.tf new file mode 100644 index 000000000..d6a18fb88 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_ips_signature/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_policy_object_security_ips_signature" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + generator_id = "1234" + signature_id = "5678" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_local_application_list/import.sh b/examples/resources/sdwan_policy_object_security_local_application_list/import.sh new file mode 100644 index 000000000..6b50af297 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_local_application_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_local_application_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_local_application_list/resource.tf b/examples/resources/sdwan_policy_object_security_local_application_list/resource.tf new file mode 100644 index 000000000..ba4373eab --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_local_application_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_local_application_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + app = "audible-com" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_local_domain_list/import.sh b/examples/resources/sdwan_policy_object_security_local_domain_list/import.sh new file mode 100644 index 000000000..3b07d7d4a --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_local_domain_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_local_domain_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_local_domain_list/resource.tf b/examples/resources/sdwan_policy_object_security_local_domain_list/resource.tf new file mode 100644 index 000000000..744e33ed3 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_local_domain_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_local_domain_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + local_domain = "hello.com" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_port_list/import.sh b/examples/resources/sdwan_policy_object_security_port_list/import.sh new file mode 100644 index 000000000..8360c0763 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_port_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_port_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_port_list/resource.tf b/examples/resources/sdwan_policy_object_security_port_list/resource.tf new file mode 100644 index 000000000..c020e1649 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_port_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_port_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + port = "100" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/import.sh b/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/import.sh new file mode 100644 index 000000000..6f5af2caf --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_scalable_group_tag_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/resource.tf b/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/resource.tf new file mode 100644 index 000000000..b7bc19d67 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_scalable_group_tag_list/resource.tf @@ -0,0 +1,11 @@ +resource "sdwan_policy_object_security_scalable_group_tag_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "" + entries = [ + { + sgt_name = "ANY" + tag = "65535" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_security_url_list/import.sh b/examples/resources/sdwan_policy_object_security_url_list/import.sh new file mode 100644 index 000000000..d3c7e0c61 --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_url_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_security_url_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_security_url_list/resource.tf b/examples/resources/sdwan_policy_object_security_url_list/resource.tf new file mode 100644 index 000000000..7dafae6ed --- /dev/null +++ b/examples/resources/sdwan_policy_object_security_url_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_security_url_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + pattern = "www.cisco.com" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_standard_community_list/import.sh b/examples/resources/sdwan_policy_object_standard_community_list/import.sh new file mode 100644 index 000000000..72e834627 --- /dev/null +++ b/examples/resources/sdwan_policy_object_standard_community_list/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_standard_community_list.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_standard_community_list/resource.tf b/examples/resources/sdwan_policy_object_standard_community_list/resource.tf new file mode 100644 index 000000000..c17c61c1a --- /dev/null +++ b/examples/resources/sdwan_policy_object_standard_community_list/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_standard_community_list" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + standard_community = "1000:10000" + } + ] +} diff --git a/examples/resources/sdwan_policy_object_vpn_group/import.sh b/examples/resources/sdwan_policy_object_vpn_group/import.sh new file mode 100644 index 000000000..3e0d3b280 --- /dev/null +++ b/examples/resources/sdwan_policy_object_vpn_group/import.sh @@ -0,0 +1 @@ +terraform import sdwan_policy_object_vpn_group.example "f6b2c44c-693c-4763-b010-895aa3d236bd" diff --git a/examples/resources/sdwan_policy_object_vpn_group/resource.tf b/examples/resources/sdwan_policy_object_vpn_group/resource.tf new file mode 100644 index 000000000..2ca0377ad --- /dev/null +++ b/examples/resources/sdwan_policy_object_vpn_group/resource.tf @@ -0,0 +1,10 @@ +resource "sdwan_policy_object_vpn_group" "example" { + name = "Example" + description = "My Example" + feature_profile_id = "f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac" + entries = [ + { + vpn = 100 + } + ] +} diff --git a/gen/definitions/profile_parcels/policy_object_app_probe_class.yaml b/gen/definitions/profile_parcels/policy_object_app_probe_class.yaml new file mode 100644 index 000000000..20f0b300b --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_app_probe_class.yaml @@ -0,0 +1,37 @@ +--- +name: Policy Object App Probe Class +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/app-probe +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: map + mandatory: true + attributes: + - model_name: color + id: true + mandatory: true + example: 3g + - model_name: dscp + example: 45 + - model_name: forwardingClass + id: true + mandatory: true + example: classlist1 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_as_path_list.yaml b/gen/definitions/profile_parcels/policy_object_as_path_list.yaml new file mode 100644 index 000000000..80e6e2faf --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_as_path_list.yaml @@ -0,0 +1,33 @@ +--- +name: Policy Object AS Path List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/as-path +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: asPathListNum + tf_name: as_path_list_id + mandatory: true + example: 1 + - model_name: entries + mandatory: true + attributes: + - model_name: asPath + tf_name: as_path_list + id: true + mandatory: true + example: 110 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_preferred_color_group.yaml b/gen/definitions/profile_parcels/policy_object_preferred_color_group.yaml new file mode 100644 index 000000000..a3f612b89 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_preferred_color_group.yaml @@ -0,0 +1,50 @@ +--- +name: Policy Object Preferred Color Group +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/preferred-color-group +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: colorPreference + tf_name: primary_color_preference + data_path: [primaryPreference] + mandatory: true + example: default + - model_name: pathPreference + tf_name: primary_path_preference + data_path: [primaryPreference] + mandatory: true + example: direct-path + - model_name: colorPreference + tf_name: secondary_color_preference + data_path: [secondaryPreference] + example: bronze + - model_name: pathPreference + tf_name: secondary_path_preference + data_path: [secondaryPreference] + example: all-paths + - model_name: colorPreference + tf_name: tertiary_color_preference + data_path: [tertiaryPreference] + example: blue + - model_name: pathPreference + tf_name: tertiary_path_preference + data_path: [tertiaryPreference] + example: all-paths + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_data_ipv4_prefix_list.yaml b/gen/definitions/profile_parcels/policy_object_security_data_ipv4_prefix_list.yaml new file mode 100644 index 000000000..4cb3bf6af --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_data_ipv4_prefix_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security Data IPv4 Prefix List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-data-ip-prefix +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: ipPrefix + id: true + mandatory: true + example: 10.0.0.0/12 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_fqdn_list.yaml b/gen/definitions/profile_parcels/policy_object_security_fqdn_list.yaml new file mode 100644 index 000000000..500ce9333 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_fqdn_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security FQDN List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-fqdn +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: pattern + id: true + mandatory: true + example: cisco.com + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_geolocation_list.yaml b/gen/definitions/profile_parcels/policy_object_security_geolocation_list.yaml new file mode 100644 index 000000000..d85937024 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_geolocation_list.yaml @@ -0,0 +1,29 @@ +--- +name: Policy Object Security Geolocation List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-geolocation +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: country + example: DZA + - model_name: continent + example: AF + exclude_test: true + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_identity_list.yaml b/gen/definitions/profile_parcels/policy_object_security_identity_list.yaml new file mode 100644 index 000000000..67d8f9993 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_identity_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security Identity List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-identity +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + attributes: + - model_name: user + example: administrator + - model_name: userGroup + exclude_test: true + example: "SDWAN-IDENTITY.CISCO.COM/Users/Domain" + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_ips_signature.yaml b/gen/definitions/profile_parcels/policy_object_security_ips_signature.yaml new file mode 100644 index 000000000..2388f6d69 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_ips_signature.yaml @@ -0,0 +1,32 @@ +--- +name: Policy Object Security IPS Signature +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-ipssignature +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +parcel_type: policy_object +skip_minimum_test: true +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: generatorId + id: true + mandatory: true + example: 1234 + - model_name: signatureId + id: true + mandatory: true + example: 5678 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_local_application_list.yaml b/gen/definitions/profile_parcels/policy_object_security_local_application_list.yaml new file mode 100644 index 000000000..ef6e50a80 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_local_application_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security Local Application List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-localapp +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + attributes: + - model_name: app + example: audible-com + - model_name: appFamily + example: web + exclude_test: true + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_local_domain_list.yaml b/gen/definitions/profile_parcels/policy_object_security_local_domain_list.yaml new file mode 100644 index 000000000..b67b9dbe4 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_local_domain_list.yaml @@ -0,0 +1,29 @@ +--- +name: Policy Object Security Local Domain List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-localdomain +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: nameServer + tf_name: local_domain + id: true + mandatory: true + example: hello.com + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_port_list.yaml b/gen/definitions/profile_parcels/policy_object_security_port_list.yaml new file mode 100644 index 000000000..200cdc252 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_port_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security Port List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-port +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: port + id: true + mandatory: true + example: 100 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_scalable_group_tag_list.yaml b/gen/definitions/profile_parcels/policy_object_security_scalable_group_tag_list.yaml new file mode 100644 index 000000000..3d753e81a --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_scalable_group_tag_list.yaml @@ -0,0 +1,31 @@ +--- +name: Policy Object Security Scalable Group Tag List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-scalablegrouptag +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: sgtName + id: true + mandatory: true + example: ANY + - model_name: tag + id: true + mandatory: true + example: 65535 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_security_url_list.yaml b/gen/definitions/profile_parcels/policy_object_security_url_list.yaml new file mode 100644 index 000000000..7ca29746a --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_security_url_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Security URL List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/security-urllist +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: pattern + id: true + mandatory: true + example: www.cisco.com + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_standard_community_list.yaml b/gen/definitions/profile_parcels/policy_object_standard_community_list.yaml new file mode 100644 index 000000000..9970b9965 --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_standard_community_list.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object Standard Community List +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/standard-community +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: standardCommunity + id: true + mandatory: true + example: 1000:10000 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/definitions/profile_parcels/policy_object_vpn_group.yaml b/gen/definitions/profile_parcels/policy_object_vpn_group.yaml new file mode 100644 index 000000000..27887d7bb --- /dev/null +++ b/gen/definitions/profile_parcels/policy_object_vpn_group.yaml @@ -0,0 +1,28 @@ +--- +name: Policy Object VPN Group +rest_endpoint: /v1/feature-profile/sdwan/policy-object/%v/vpn-group +minimum_version: 20.12.0 +test_tags: [SDWAN_2012] +skip_minimum_test: true +parcel_type: policy_object +attributes: + - tf_name: feature_profile_id + reference: true + type: String + mandatory: true + description: Feature Profile ID + example: f6dd22c8-0b4f-496c-9a0b-6813d1f8b8ac + test_value: sdwan_policy_object_feature_profile.test.id + - model_name: entries + mandatory: true + attributes: + - model_name: vpn + id: true + mandatory: true + example: 100 + +test_prerequisites: | + resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" + } \ No newline at end of file diff --git a/gen/models/profile_parcels/policy_object_app_probe.json b/gen/models/profile_parcels/policy_object_app_probe_class.json similarity index 100% rename from gen/models/profile_parcels/policy_object_app_probe.json rename to gen/models/profile_parcels/policy_object_app_probe_class.json diff --git a/gen/models/profile_parcels/policy_object_as_path.json b/gen/models/profile_parcels/policy_object_as_path_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_as_path.json rename to gen/models/profile_parcels/policy_object_as_path_list.json diff --git a/gen/models/profile_parcels/policy_object_security_data_ip_prefix.json b/gen/models/profile_parcels/policy_object_security_data_ipv4_prefix_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_data_ip_prefix.json rename to gen/models/profile_parcels/policy_object_security_data_ipv4_prefix_list.json diff --git a/gen/models/profile_parcels/policy_object_security_fqdn.json b/gen/models/profile_parcels/policy_object_security_fqdn_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_fqdn.json rename to gen/models/profile_parcels/policy_object_security_fqdn_list.json diff --git a/gen/models/profile_parcels/policy_object_security_geolocation.json b/gen/models/profile_parcels/policy_object_security_geolocation_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_geolocation.json rename to gen/models/profile_parcels/policy_object_security_geolocation_list.json diff --git a/gen/models/profile_parcels/policy_object_security_identity.json b/gen/models/profile_parcels/policy_object_security_identity_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_identity.json rename to gen/models/profile_parcels/policy_object_security_identity_list.json diff --git a/gen/models/profile_parcels/policy_object_security_ips_signature.json b/gen/models/profile_parcels/policy_object_security_ips_signature.json new file mode 100644 index 000000000..15985616d --- /dev/null +++ b/gen/models/profile_parcels/policy_object_security_ips_signature.json @@ -0,0 +1,131 @@ +{ + "request": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "https://cisco.com/schema/profileparcel/sdwan/policy-object/security-ipssignature/post/request_schema.json", + "title": "security-ipssignature Parcel Schema", + "description": "security-ipssignature profile parcel schema for POST request", + "type": "object", + "properties": { + "name": { + "type": "string", + "pattern": "^[^&<>! \"]+$", + "minLength": 1, + "maxLength": 32 + }, + "description": { + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "entries": { + "description": "Ips Signature", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "properties": { + "generatorId": { + "description": "", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "pattern": "^(429496729[0-5]|42949672[0-8]\\d|4294967[01]\\d{2}|429496[0-6]\\d{3}|42949[0-5]\\d{4}|4294[0-8]\\d{5}|429[0-3]\\d{6}|42[0-8]\\d{7}|4[01]\\d{8}|[1-3]\\d{9}|[1-9]\\d{8}|[1-9]\\d{7}|[1-9]\\d{6}|[1-9]\\d{5}|[1-9]\\d{4}|[1-9]\\d{3}|[1-9]\\d{2}|[1-9]\\d|\\d)$" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + }, + "signatureId": { + "description": "", + "type": "object", + "oneOf": [ + { + "properties": { + "optionType": { + "type": "string", + "enum": [ + "global" + ] + }, + "value": { + "type": "string", + "pattern": "^(429496729[0-5]|42949672[0-8]\\d|4294967[01]\\d{2}|429496[0-6]\\d{3}|42949[0-5]\\d{4}|4294[0-8]\\d{5}|429[0-3]\\d{6}|42[0-8]\\d{7}|4[01]\\d{8}|[1-3]\\d{9}|[1-9]\\d{8}|[1-9]\\d{7}|[1-9]\\d{6}|[1-9]\\d{5}|[1-9]\\d{4}|[1-9]\\d{3}|[1-9]\\d{2}|[1-9]\\d|\\d)$" + } + }, + "required": [ + "optionType", + "value" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "generatorId", + "signatureId" + ], + "additionalProperties": false + } + } + }, + "required": [ + "entries" + ], + "additionalProperties": false + }, + "documentation": { + "description": "This is the documentation for POST request schema for security-ipssignature profile parcel", + "details-1": "variable name should be present with given format as specified in schema if optionType value is variable", + "details-2": "variable name should not be present if optionType value is NOT variable", + "details-3": "when option Type is global, value should be present with given format/restrictions as specified in schema", + "details-4": "when option Type is default, value should be present with given default value as specified in schema", + "examples": [ + { + "data": { + "entries": [ + { + "generatorId": { + "optionType": "global", + "value": "1234" + }, + "signatureId": { + "optionType": "global", + "value": "5678" + } + } + ] + }, + "name": "security-ipssignatureParcelGlobalDefault" + } + ] + } + }, + "required": [ + "data", + "name" + ], + "not": { + "required": [ + "documentation" + ] + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/gen/models/profile_parcels/policy_object_security_localapp.json b/gen/models/profile_parcels/policy_object_security_local_application_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_localapp.json rename to gen/models/profile_parcels/policy_object_security_local_application_list.json diff --git a/gen/models/profile_parcels/policy_object_security_localdomain.json b/gen/models/profile_parcels/policy_object_security_local_domain_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_localdomain.json rename to gen/models/profile_parcels/policy_object_security_local_domain_list.json diff --git a/gen/models/profile_parcels/policy_object_security_port.json b/gen/models/profile_parcels/policy_object_security_port_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_port.json rename to gen/models/profile_parcels/policy_object_security_port_list.json diff --git a/gen/models/profile_parcels/policy_object_security_scalablegrouptag.json b/gen/models/profile_parcels/policy_object_security_scalable_group_tag_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_scalablegrouptag.json rename to gen/models/profile_parcels/policy_object_security_scalable_group_tag_list.json diff --git a/gen/models/profile_parcels/policy_object_security_urllist.json b/gen/models/profile_parcels/policy_object_security_url_list.json similarity index 100% rename from gen/models/profile_parcels/policy_object_security_urllist.json rename to gen/models/profile_parcels/policy_object_security_url_list.json diff --git a/gen/models/profile_parcels/policy_object_standard_community.json b/gen/models/profile_parcels/policy_object_standard_community.json deleted file mode 100644 index 20b00a800..000000000 --- a/gen/models/profile_parcels/policy_object_standard_community.json +++ /dev/null @@ -1,119 +0,0 @@ -{ - "request": { - "$schema": "http://json-schema.org/draft/2019-09/schema", - "$id": "https://cisco.com/schema/profileparcel/sdwan/policy-object/standard-community/common/request_schema.json", - "title": "Standard Community List Parcel Schema", - "description": "standard Community list profile parcel schema", - "type": "object", - "properties": { - "name": { - "type": "string", - "pattern": "^[^&<>! \"]+$", - "minLength": 1, - "maxLength": 32 - }, - "description": { - "type": "string" - }, - "data": { - "type": "object", - "properties": { - "entries": { - "oneOf": [ - { - "description": "Standard Community List", - "type": "array", - "minItems": 1, - "uniqueItems": true, - "items": { - "properties": { - "standardCommunity": { - "type": "object", - "description": "Standard Community", - "properties": { - "optionType": { - "type": "string", - "enum": [ - "global" - ] - }, - "value": { - "oneOf": [ - { - "enum": [ - "internet", - "local-AS", - "no-advertise", - "no-export" - ], - "type": "string" - }, - { - "type": "string", - "pattern": "^(0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]):(0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$" - } - ] - } - }, - "required": [ - "optionType", - "value" - ], - "additionalProperties": false - } - }, - "required": [ - "standardCommunity" - ], - "additionalProperties": false - } - } - ] - } - }, - "required": [ - "entries" - ], - "additionalProperties": false - }, - "documentation": { - "description": "This is the documentation for standard community profile parcel", - "details-1": "variable name should be present with given format as specified in schema if optionType value is variable", - "details-2": "variable name should not be present if optionType value is NOT variable", - "details-3": "when option Type is global, value should be present with given format/restrictions as specified in schema", - "details-4": "when option Type is default, value should be present with given default value as specified in schema", - "examples": [ - { - "data": { - "entries": [ - { - "standardCommunity": { - "optionType": "global", - "value": "1000:10000" - } - }, - { - "standardCommunity": { - "optionType": "global", - "value": "internet" - } - } - ] - }, - "name": "standardCommunityList1" - } - ] - } - }, - "required": [ - "name", - "data" - ], - "not": { - "required": [ - "documentation" - ] - }, - "additionalProperties": false - } -} \ No newline at end of file diff --git a/gen/models/profile_parcels/policy_object_standard_community_list.json b/gen/models/profile_parcels/policy_object_standard_community_list.json new file mode 100644 index 000000000..8424af8f0 --- /dev/null +++ b/gen/models/profile_parcels/policy_object_standard_community_list.json @@ -0,0 +1,102 @@ +{ + "request": { + "$schema": "http://json-schema.org/draft/2019-09/schema", + "$id": "https://cisco.com/schema/profileparcel/sdwan/policy-object/standard-community/common/request_schema.json", + "title": "Standard Community List Parcel Schema", + "description": "standard Community list profile parcel schema", + "type": "object", + "properties": { + "name": { + "type": "string", + "pattern": "^[^&<>! \"]+$", + "minLength": 1, + "maxLength": 32 + }, + "description": { + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "entries": { + "description": "Standard Community List", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "object", + "properties": { + "standardCommunity": { + "type": "object", + "description": "Standard Community", + "properties": { + "optionType": { + "type": "string", + "enum": ["global"] + }, + "value": { + "oneOf": [ + { + "enum": [ + "internet", + "local-AS", + "no-advertise", + "no-export" + ], + "type": "string" + }, + { + "type": "string", + "pattern": "^(0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]):(0|[1-9]\\d{0,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$" + } + ] + } + }, + "required": ["optionType", "value"], + "additionalProperties": false + } + }, + "required": ["standardCommunity"], + "additionalProperties": false + } + } + }, + "required": ["entries"], + "additionalProperties": false + }, + "documentation": { + "description": "This is the documentation for standard community profile parcel", + "details-1": "variable name should be present with given format as specified in schema if optionType value is variable", + "details-2": "variable name should not be present if optionType value is NOT variable", + "details-3": "when option Type is global, value should be present with given format/restrictions as specified in schema", + "details-4": "when option Type is default, value should be present with given default value as specified in schema", + "examples": [ + { + "data": { + "entries": [ + { + "standardCommunity": { + "optionType": "global", + "value": "1000:10000" + } + }, + { + "standardCommunity": { + "optionType": "global", + "value": "internet" + } + } + ] + }, + "name": "standardCommunityList1" + } + ] + } + }, + "required": ["name", "data"], + "not": { + "required": ["documentation"] + }, + "additionalProperties": false + } +} \ No newline at end of file diff --git a/internal/provider/data_source_sdwan_policy_object_app_probe_class.go b/internal/provider/data_source_sdwan_policy_object_app_probe_class.go new file mode 100644 index 000000000..146db62f5 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_app_probe_class.go @@ -0,0 +1,149 @@ +// 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 = &PolicyObjectAppProbeClassProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectAppProbeClassProfileParcelDataSource{} +) + +func NewPolicyObjectAppProbeClassProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectAppProbeClassProfileParcelDataSource{} +} + +type PolicyObjectAppProbeClassProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectAppProbeClassProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_app_probe_class" +} + +func (d *PolicyObjectAppProbeClassProfileParcelDataSource) 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 App Probe Class Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "App Probe List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "map": schema.ListNestedAttribute{ + MarkdownDescription: "Map", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "color": schema.StringAttribute{ + MarkdownDescription: "Color", + Computed: true, + }, + "dscp": schema.Int64Attribute{ + MarkdownDescription: "DSCP number", + Computed: true, + }, + }, + }, + }, + "forwarding_class": schema.StringAttribute{ + MarkdownDescription: "Forwarding Class Name", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectAppProbeClassProfileParcelDataSource) 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 *PolicyObjectAppProbeClassProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectAppProbeClass + + // 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_app_probe_class_test.go b/internal/provider/data_source_sdwan_policy_object_app_probe_class_test.go new file mode 100644 index 000000000..f574c08a3 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_app_probe_class_test.go @@ -0,0 +1,87 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSource +func TestAccDataSourceSdwanPolicyObjectAppProbeClassProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_app_probe_class.test", "entries.0.map.0.color", "3g")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_app_probe_class.test", "entries.0.map.0.dscp", "45")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_app_probe_class.test", "entries.0.forwarding_class", "classlist1")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectAppProbeClassPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectAppProbeClassProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectAppProbeClassPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectAppProbeClassProfileParcelConfig() string { + config := `resource "sdwan_policy_object_app_probe_class" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` map = [{` + "\n" + config += ` color = "3g"` + "\n" + config += ` dscp = 45` + "\n" + config += ` }]` + "\n" + config += ` forwarding_class = "classlist1"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_app_probe_class" "test" { + id = sdwan_policy_object_app_probe_class.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_as_path_list.go b/internal/provider/data_source_sdwan_policy_object_as_path_list.go new file mode 100644 index 000000000..a66700d91 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_as_path_list.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 = &PolicyObjectASPathListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectASPathListProfileParcelDataSource{} +) + +func NewPolicyObjectASPathListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectASPathListProfileParcelDataSource{} +} + +type PolicyObjectASPathListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectASPathListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_as_path_list" +} + +func (d *PolicyObjectASPathListProfileParcelDataSource) 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 AS Path List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "as_path_list_id": schema.Int64Attribute{ + MarkdownDescription: "As path List Number", + Computed: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "AS Path List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "as_path_list": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectASPathListProfileParcelDataSource) 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 *PolicyObjectASPathListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectASPathList + + // 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_as_path_list_test.go b/internal/provider/data_source_sdwan_policy_object_as_path_list_test.go new file mode 100644 index 000000000..c06251379 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_as_path_list_test.go @@ -0,0 +1,83 @@ +// 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 TestAccDataSourceSdwanPolicyObjectASPathListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_as_path_list.test", "as_path_list_id", "1")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_as_path_list.test", "entries.0.as_path_list", "110")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectASPathListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectASPathListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectASPathListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectASPathListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_as_path_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` as_path_list_id = 1` + "\n" + config += ` entries = [{` + "\n" + config += ` as_path_list = "110"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_as_path_list" "test" { + id = sdwan_policy_object_as_path_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_feature_profile.go b/internal/provider/data_source_sdwan_policy_object_feature_profile.go index 458b4062f..2ee7d13a9 100644 --- a/internal/provider/data_source_sdwan_policy_object_feature_profile.go +++ b/internal/provider/data_source_sdwan_policy_object_feature_profile.go @@ -21,16 +21,18 @@ package provider 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-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 = &PolicyObjectFeatureProfileDataSource{} @@ -57,7 +59,7 @@ func (d *PolicyObjectFeatureProfileDataSource) Schema(ctx context.Context, req d Attributes: map[string]schema.Attribute{ "id": schema.StringAttribute{ MarkdownDescription: "The id of the object", - Computed: true, + Required: true, }, "name": schema.StringAttribute{ MarkdownDescription: "The name of the policy object feature profile", @@ -79,6 +81,9 @@ func (d *PolicyObjectFeatureProfileDataSource) Configure(_ context.Context, req 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 *PolicyObjectFeatureProfileDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { var config PolicyObjectFeatureProfile @@ -89,21 +94,20 @@ func (d *PolicyObjectFeatureProfileDataSource) Read(ctx context.Context, req dat return } - tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", "Policy object feature profile")) + tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.Id.String())) - res, err := d.client.Get(config.getPath()) + 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 } - if len(res.Array()) > 0 { - config.fromBody(ctx, res.Array()[0]) - config.Id = types.StringValue(res.Array()[0].Get("profileId").String()) - } + config.fromBody(ctx, res) - tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", "Policy object feature profile")) + tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.Id.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_feature_profile_test.go b/internal/provider/data_source_sdwan_policy_object_feature_profile_test.go index 91ff8f5d4..1497a2a26 100644 --- a/internal/provider/data_source_sdwan_policy_object_feature_profile_test.go +++ b/internal/provider/data_source_sdwan_policy_object_feature_profile_test.go @@ -52,6 +52,7 @@ func TestAccDataSourceSdwanPolicyObjectFeatureProfile(t *testing.T) { // 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 testAccDataSourceSdwanPolicyObjectFeatureProfileConfig() string { config := "" config += `resource "sdwan_policy_object_feature_profile" "test" {` + "\n" @@ -61,8 +62,10 @@ func testAccDataSourceSdwanPolicyObjectFeatureProfileConfig() string { config += ` data "sdwan_policy_object_feature_profile" "test" { - depends_on = [sdwan_policy_object_feature_profile.test] + id = sdwan_policy_object_feature_profile.test.id } ` return config } + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_preferred_color_group.go b/internal/provider/data_source_sdwan_policy_object_preferred_color_group.go new file mode 100644 index 000000000..f7bb35e88 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_preferred_color_group.go @@ -0,0 +1,157 @@ +// 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-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 = &PolicyObjectPreferredColorGroupProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectPreferredColorGroupProfileParcelDataSource{} +) + +func NewPolicyObjectPreferredColorGroupProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectPreferredColorGroupProfileParcelDataSource{} +} + +type PolicyObjectPreferredColorGroupProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectPreferredColorGroupProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_preferred_color_group" +} + +func (d *PolicyObjectPreferredColorGroupProfileParcelDataSource) 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 Preferred Color Group Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Preferred Color Group List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "primary_color_preference": schema.SetAttribute{ + MarkdownDescription: "", + ElementType: types.StringType, + Computed: true, + }, + "primary_path_preference": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "secondary_color_preference": schema.SetAttribute{ + MarkdownDescription: "", + ElementType: types.StringType, + Computed: true, + }, + "secondary_path_preference": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "tertiary_color_preference": schema.SetAttribute{ + MarkdownDescription: "", + ElementType: types.StringType, + Computed: true, + }, + "tertiary_path_preference": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectPreferredColorGroupProfileParcelDataSource) 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 *PolicyObjectPreferredColorGroupProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectPreferredColorGroup + + // 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_preferred_color_group_test.go b/internal/provider/data_source_sdwan_policy_object_preferred_color_group_test.go new file mode 100644 index 000000000..9684c1202 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_preferred_color_group_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 testAccDataSource +func TestAccDataSourceSdwanPolicyObjectPreferredColorGroupProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_preferred_color_group.test", "entries.0.primary_path_preference", "direct-path")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_preferred_color_group.test", "entries.0.secondary_path_preference", "all-paths")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_preferred_color_group.test", "entries.0.tertiary_path_preference", "all-paths")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectPreferredColorGroupPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectPreferredColorGroupProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectPreferredColorGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectPreferredColorGroupProfileParcelConfig() string { + config := `resource "sdwan_policy_object_preferred_color_group" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` primary_color_preference = ["default"]` + "\n" + config += ` primary_path_preference = "direct-path"` + "\n" + config += ` secondary_color_preference = ["bronze"]` + "\n" + config += ` secondary_path_preference = "all-paths"` + "\n" + config += ` tertiary_color_preference = ["blue"]` + "\n" + config += ` tertiary_path_preference = "all-paths"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_preferred_color_group" "test" { + id = sdwan_policy_object_preferred_color_group.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_data_ipv4_prefix_list.go b/internal/provider/data_source_sdwan_policy_object_security_data_ipv4_prefix_list.go new file mode 100644 index 000000000..e66f1a08e --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_data_ipv4_prefix_list.go @@ -0,0 +1,138 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Mozilla Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://mozilla.org/MPL/2.0/ +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: MPL-2.0 + +package provider + +// Section below is generated&owned by "gen/generator.go". //template:begin imports +import ( + "context" + "fmt" + "net/url" + + "github.com/CiscoDevNet/terraform-provider-sdwan/internal/provider/helpers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource{} +} + +type PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_data_ipv4_prefix_list" +} + +func (d *PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource) 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 Security Data IPv4 Prefix List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ip_prefix": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "ip_prefix_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource) 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityDataIPv4PrefixList + + // 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_security_data_ipv4_prefix_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_data_ipv4_prefix_list_test.go new file mode 100644 index 000000000..6daf0faec --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_data_ipv4_prefix_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_data_ipv4_prefix_list.test", "entries.0.ip_prefix", "10.0.0.0/12")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityDataIPv4PrefixListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityDataIPv4PrefixListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_data_ipv4_prefix_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` ip_prefix = "10.0.0.0/12"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_data_ipv4_prefix_list" "test" { + id = sdwan_policy_object_security_data_ipv4_prefix_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_fqdn_list.go b/internal/provider/data_source_sdwan_policy_object_security_fqdn_list.go new file mode 100644 index 000000000..191932a81 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_fqdn_list.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 = &PolicyObjectSecurityFQDNListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityFQDNListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityFQDNListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityFQDNListProfileParcelDataSource{} +} + +type PolicyObjectSecurityFQDNListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityFQDNListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_fqdn_list" +} + +func (d *PolicyObjectSecurityFQDNListProfileParcelDataSource) 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 Security FQDN List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "pattern": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityFQDNListProfileParcelDataSource) 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 *PolicyObjectSecurityFQDNListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityFQDNList + + // 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_security_fqdn_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_fqdn_list_test.go new file mode 100644 index 000000000..6e89be64f --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_fqdn_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityFQDNListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_fqdn_list.test", "entries.0.pattern", "cisco.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityFQDNListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityFQDNListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityFQDNListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityFQDNListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_fqdn_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` pattern = "cisco.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_fqdn_list" "test" { + id = sdwan_policy_object_security_fqdn_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_geolocation_list.go b/internal/provider/data_source_sdwan_policy_object_security_geolocation_list.go new file mode 100644 index 000000000..0bb11f4a3 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_geolocation_list.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 = &PolicyObjectSecurityGeolocationListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityGeolocationListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityGeolocationListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityGeolocationListProfileParcelDataSource{} +} + +type PolicyObjectSecurityGeolocationListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityGeolocationListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_geolocation_list" +} + +func (d *PolicyObjectSecurityGeolocationListProfileParcelDataSource) 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 Security Geolocation List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Geolocation List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "country": schema.StringAttribute{ + MarkdownDescription: "country names", + Computed: true, + }, + "continent": schema.StringAttribute{ + MarkdownDescription: "continent name", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityGeolocationListProfileParcelDataSource) 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 *PolicyObjectSecurityGeolocationListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityGeolocationList + + // 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_security_geolocation_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_geolocation_list_test.go new file mode 100644 index 000000000..267bfac4b --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_geolocation_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityGeolocationListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_geolocation_list.test", "entries.0.country", "DZA")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityGeolocationListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityGeolocationListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityGeolocationListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityGeolocationListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_geolocation_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` country = "DZA"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_geolocation_list" "test" { + id = sdwan_policy_object_security_geolocation_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_identity_list.go b/internal/provider/data_source_sdwan_policy_object_security_identity_list.go new file mode 100644 index 000000000..8096a2ce8 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_identity_list.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 = &PolicyObjectSecurityIdentityListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityIdentityListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityIdentityListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityIdentityListProfileParcelDataSource{} +} + +type PolicyObjectSecurityIdentityListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityIdentityListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_identity_list" +} + +func (d *PolicyObjectSecurityIdentityListProfileParcelDataSource) 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 Security Identity List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Array of Users and User Groups", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "user": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "user_group": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityIdentityListProfileParcelDataSource) 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 *PolicyObjectSecurityIdentityListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityIdentityList + + // 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_security_identity_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_identity_list_test.go new file mode 100644 index 000000000..95e55995c --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_identity_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityIdentityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_identity_list.test", "entries.0.user", "administrator")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityIdentityListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityIdentityListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityIdentityListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityIdentityListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_identity_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` user = "administrator"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_identity_list" "test" { + id = sdwan_policy_object_security_identity_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_ips_signature.go b/internal/provider/data_source_sdwan_policy_object_security_ips_signature.go new file mode 100644 index 000000000..b3fec340a --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_ips_signature.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 = &PolicyObjectSecurityIPSSignatureProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityIPSSignatureProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityIPSSignatureProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityIPSSignatureProfileParcelDataSource{} +} + +type PolicyObjectSecurityIPSSignatureProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityIPSSignatureProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_ips_signature" +} + +func (d *PolicyObjectSecurityIPSSignatureProfileParcelDataSource) 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 Security IPS Signature Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Ips Signature", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "generator_id": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "signature_id": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityIPSSignatureProfileParcelDataSource) 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 *PolicyObjectSecurityIPSSignatureProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityIPSSignature + + // 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_security_ips_signature_test.go b/internal/provider/data_source_sdwan_policy_object_security_ips_signature_test.go new file mode 100644 index 000000000..a9538768e --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_ips_signature_test.go @@ -0,0 +1,83 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityIPSSignatureProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_ips_signature.test", "entries.0.generator_id", "1234")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_ips_signature.test", "entries.0.signature_id", "5678")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityIPSSignaturePrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityIPSSignatureProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityIPSSignaturePrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityIPSSignatureProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_ips_signature" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` generator_id = "1234"` + "\n" + config += ` signature_id = "5678"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_ips_signature" "test" { + id = sdwan_policy_object_security_ips_signature.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_local_application_list.go b/internal/provider/data_source_sdwan_policy_object_security_local_application_list.go new file mode 100644 index 000000000..d276664a4 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_local_application_list.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 = &PolicyObjectSecurityLocalApplicationListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityLocalApplicationListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityLocalApplicationListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityLocalApplicationListProfileParcelDataSource{} +} + +type PolicyObjectSecurityLocalApplicationListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityLocalApplicationListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_local_application_list" +} + +func (d *PolicyObjectSecurityLocalApplicationListProfileParcelDataSource) 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 Security Local Application List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Localapp list", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "app": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "app_family": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityLocalApplicationListProfileParcelDataSource) 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 *PolicyObjectSecurityLocalApplicationListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityLocalApplicationList + + // 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_security_local_application_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_local_application_list_test.go new file mode 100644 index 000000000..b03bde68b --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_local_application_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityLocalApplicationListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_local_application_list.test", "entries.0.app", "audible-com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityLocalApplicationListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityLocalApplicationListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityLocalApplicationListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityLocalApplicationListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_local_application_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` app = "audible-com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_local_application_list" "test" { + id = sdwan_policy_object_security_local_application_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_local_domain_list.go b/internal/provider/data_source_sdwan_policy_object_security_local_domain_list.go new file mode 100644 index 000000000..13f7c9c4f --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_local_domain_list.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 = &PolicyObjectSecurityLocalDomainListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityLocalDomainListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityLocalDomainListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityLocalDomainListProfileParcelDataSource{} +} + +type PolicyObjectSecurityLocalDomainListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityLocalDomainListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_local_domain_list" +} + +func (d *PolicyObjectSecurityLocalDomainListProfileParcelDataSource) 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 Security Local Domain List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "local_domain": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityLocalDomainListProfileParcelDataSource) 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 *PolicyObjectSecurityLocalDomainListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityLocalDomainList + + // 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_security_local_domain_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_local_domain_list_test.go new file mode 100644 index 000000000..3cc674abd --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_local_domain_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityLocalDomainListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_local_domain_list.test", "entries.0.local_domain", "hello.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityLocalDomainListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityLocalDomainListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityLocalDomainListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityLocalDomainListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_local_domain_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` local_domain = "hello.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_local_domain_list" "test" { + id = sdwan_policy_object_security_local_domain_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_port_list.go b/internal/provider/data_source_sdwan_policy_object_security_port_list.go new file mode 100644 index 000000000..3586a41f4 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_port_list.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 = &PolicyObjectSecurityPortListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityPortListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityPortListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityPortListProfileParcelDataSource{} +} + +type PolicyObjectSecurityPortListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityPortListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_port_list" +} + +func (d *PolicyObjectSecurityPortListProfileParcelDataSource) 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 Security Port List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Port List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "port": schema.StringAttribute{ + MarkdownDescription: "can be single port or port range", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityPortListProfileParcelDataSource) 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 *PolicyObjectSecurityPortListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityPortList + + // 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_security_port_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_port_list_test.go new file mode 100644 index 000000000..6ef5b1f88 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_port_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityPortListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_port_list.test", "entries.0.port", "100")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityPortListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityPortListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityPortListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityPortListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_port_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` port = "100"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_port_list" "test" { + id = sdwan_policy_object_security_port_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_scalable_group_tag_list.go b/internal/provider/data_source_sdwan_policy_object_security_scalable_group_tag_list.go new file mode 100644 index 000000000..0517bb78f --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_scalable_group_tag_list.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 = &PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityScalableGroupTagListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource{} +} + +type PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_scalable_group_tag_list" +} + +func (d *PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource) 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 Security Scalable Group Tag List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "sgt_name": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + "tag": schema.StringAttribute{ + MarkdownDescription: "", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource) 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityScalableGroupTagList + + // 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_security_scalable_group_tag_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_scalable_group_tag_list_test.go new file mode 100644 index 000000000..f5325d012 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_scalable_group_tag_list_test.go @@ -0,0 +1,83 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityScalableGroupTagListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_scalable_group_tag_list.test", "entries.0.sgt_name", "ANY")) + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_scalable_group_tag_list.test", "entries.0.tag", "65535")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityScalableGroupTagListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityScalableGroupTagListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityScalableGroupTagListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityScalableGroupTagListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_scalable_group_tag_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` sgt_name = "ANY"` + "\n" + config += ` tag = "65535"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_scalable_group_tag_list" "test" { + id = sdwan_policy_object_security_scalable_group_tag_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_security_url_list.go b/internal/provider/data_source_sdwan_policy_object_security_url_list.go new file mode 100644 index 000000000..ba55a2231 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_url_list.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 = &PolicyObjectSecurityURLListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectSecurityURLListProfileParcelDataSource{} +) + +func NewPolicyObjectSecurityURLListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectSecurityURLListProfileParcelDataSource{} +} + +type PolicyObjectSecurityURLListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectSecurityURLListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_url_list" +} + +func (d *PolicyObjectSecurityURLListProfileParcelDataSource) 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 Security URL List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "URL List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "pattern": schema.StringAttribute{ + MarkdownDescription: "valid url pattern", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectSecurityURLListProfileParcelDataSource) 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 *PolicyObjectSecurityURLListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectSecurityURLList + + // 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_security_url_list_test.go b/internal/provider/data_source_sdwan_policy_object_security_url_list_test.go new file mode 100644 index 000000000..69e21ba5a --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_security_url_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectSecurityURLListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_security_url_list.test", "entries.0.pattern", "www.cisco.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectSecurityURLListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectSecurityURLListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectSecurityURLListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectSecurityURLListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_security_url_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` pattern = "www.cisco.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_security_url_list" "test" { + id = sdwan_policy_object_security_url_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_standard_community_list.go b/internal/provider/data_source_sdwan_policy_object_standard_community_list.go new file mode 100644 index 000000000..738793fdd --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_standard_community_list.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 = &PolicyObjectStandardCommunityListProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectStandardCommunityListProfileParcelDataSource{} +) + +func NewPolicyObjectStandardCommunityListProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectStandardCommunityListProfileParcelDataSource{} +} + +type PolicyObjectStandardCommunityListProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectStandardCommunityListProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_standard_community_list" +} + +func (d *PolicyObjectStandardCommunityListProfileParcelDataSource) 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 Standard Community List Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "Standard Community List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "standard_community": schema.StringAttribute{ + MarkdownDescription: "Standard Community", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectStandardCommunityListProfileParcelDataSource) 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 *PolicyObjectStandardCommunityListProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectStandardCommunityList + + // 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_standard_community_list_test.go b/internal/provider/data_source_sdwan_policy_object_standard_community_list_test.go new file mode 100644 index 000000000..e5b764d29 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_standard_community_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectStandardCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_standard_community_list.test", "entries.0.standard_community", "1000:10000")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectStandardCommunityListPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectStandardCommunityListProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectStandardCommunityListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectStandardCommunityListProfileParcelConfig() string { + config := `resource "sdwan_policy_object_standard_community_list" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` standard_community = "1000:10000"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_standard_community_list" "test" { + id = sdwan_policy_object_standard_community_list.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/data_source_sdwan_policy_object_vpn_group.go b/internal/provider/data_source_sdwan_policy_object_vpn_group.go new file mode 100644 index 000000000..608f44f5f --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_vpn_group.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 = &PolicyObjectVPNGroupProfileParcelDataSource{} + _ datasource.DataSourceWithConfigure = &PolicyObjectVPNGroupProfileParcelDataSource{} +) + +func NewPolicyObjectVPNGroupProfileParcelDataSource() datasource.DataSource { + return &PolicyObjectVPNGroupProfileParcelDataSource{} +} + +type PolicyObjectVPNGroupProfileParcelDataSource struct { + client *sdwan.Client +} + +func (d *PolicyObjectVPNGroupProfileParcelDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_vpn_group" +} + +func (d *PolicyObjectVPNGroupProfileParcelDataSource) 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 VPN Group Policy_object.", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Required: true, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Computed: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Computed: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: "Feature Profile ID", + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: "VPN List", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "vpn": schema.Int64Attribute{ + MarkdownDescription: "can be single vpn id or vpn id range", + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *PolicyObjectVPNGroupProfileParcelDataSource) 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 *PolicyObjectVPNGroupProfileParcelDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config PolicyObjectVPNGroup + + // 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_vpn_group_test.go b/internal/provider/data_source_sdwan_policy_object_vpn_group_test.go new file mode 100644 index 000000000..0dc8acb36 --- /dev/null +++ b/internal/provider/data_source_sdwan_policy_object_vpn_group_test.go @@ -0,0 +1,81 @@ +// 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 TestAccDataSourceSdwanPolicyObjectVPNGroupProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("data.sdwan_policy_object_vpn_group.test", "entries.0.vpn", "100")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceSdwanPolicyObjectVPNGroupPrerequisitesProfileParcelConfig + testAccDataSourceSdwanPolicyObjectVPNGroupProfileParcelConfig(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAccDataSource + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccDataSourceSdwanPolicyObjectVPNGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccDataSourceConfig +func testAccDataSourceSdwanPolicyObjectVPNGroupProfileParcelConfig() string { + config := `resource "sdwan_policy_object_vpn_group" "test" {` + "\n" + config += ` name = "TF_TEST"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` vpn = 100` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + + config += ` + data "sdwan_policy_object_vpn_group" "test" { + id = sdwan_policy_object_vpn_group.test.id + feature_profile_id = sdwan_policy_object_feature_profile.test.id + } + ` + return config +} + +// End of section. //template:end testAccDataSourceConfig diff --git a/internal/provider/model_sdwan_policy_object_app_probe_class.go b/internal/provider/model_sdwan_policy_object_app_probe_class.go new file mode 100644 index 000000000..4ae2ec03a --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_app_probe_class.go @@ -0,0 +1,273 @@ +// 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 PolicyObjectAppProbeClass 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 []PolicyObjectAppProbeClassEntries `tfsdk:"entries"` +} + +type PolicyObjectAppProbeClassEntries struct { + Map []PolicyObjectAppProbeClassEntriesMap `tfsdk:"map"` + ForwardingClass types.String `tfsdk:"forwarding_class"` +} + +type PolicyObjectAppProbeClassEntriesMap struct { + Color types.String `tfsdk:"color"` + Dscp types.Int64 `tfsdk:"dscp"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectAppProbeClass) getModel() string { + return "policy_object_app_probe_class" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectAppProbeClass) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/app-probe", 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 PolicyObjectAppProbeClass) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if true { + itemBody, _ = sjson.Set(itemBody, "map", []interface{}{}) + for _, childItem := range item.Map { + itemChildBody := "" + if !childItem.Color.IsNull() { + if true { + itemChildBody, _ = sjson.Set(itemChildBody, "color.optionType", "global") + itemChildBody, _ = sjson.Set(itemChildBody, "color.value", childItem.Color.ValueString()) + } + } + if !childItem.Dscp.IsNull() { + if true { + itemChildBody, _ = sjson.Set(itemChildBody, "dscp.optionType", "global") + itemChildBody, _ = sjson.Set(itemChildBody, "dscp.value", childItem.Dscp.ValueInt64()) + } + } + itemBody, _ = sjson.SetRaw(itemBody, "map.-1", itemChildBody) + } + } + if !item.ForwardingClass.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "forwardingClass.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "forwardingClass.value", item.ForwardingClass.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 *PolicyObjectAppProbeClass) 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([]PolicyObjectAppProbeClassEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectAppProbeClassEntries{} + if cValue := v.Get("map"); cValue.Exists() { + item.Map = make([]PolicyObjectAppProbeClassEntriesMap, 0) + cValue.ForEach(func(ck, cv gjson.Result) bool { + cItem := PolicyObjectAppProbeClassEntriesMap{} + cItem.Color = types.StringNull() + + if t := cv.Get("color.optionType"); t.Exists() { + va := cv.Get("color.value") + if t.String() == "global" { + cItem.Color = types.StringValue(va.String()) + } + } + cItem.Dscp = types.Int64Null() + + if t := cv.Get("dscp.optionType"); t.Exists() { + va := cv.Get("dscp.value") + if t.String() == "global" { + cItem.Dscp = types.Int64Value(va.Int()) + } + } + item.Map = append(item.Map, cItem) + return true + }) + } + item.ForwardingClass = types.StringNull() + + if t := v.Get("forwardingClass.optionType"); t.Exists() { + va := v.Get("forwardingClass.value") + if t.String() == "global" { + item.ForwardingClass = 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 *PolicyObjectAppProbeClass) 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{"forwardingClass"} + keyValues := [...]string{data.Entries[i].ForwardingClass.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + for ci := range data.Entries[i].Map { + keys := [...]string{"color"} + keyValues := [...]string{data.Entries[i].Map[ci].Color.ValueString()} + keyValuesVariables := [...]string{""} + + var cr gjson.Result + r.Get("map").ForEach( + func(_, v gjson.Result) bool { + found := false + for ik := range keys { + tt := v.Get(keys[ik] + ".optionType") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + cr = v + return false + } + return true + }, + ) + data.Entries[i].Map[ci].Color = types.StringNull() + + if t := cr.Get("color.optionType"); t.Exists() { + va := cr.Get("color.value") + if t.String() == "global" { + data.Entries[i].Map[ci].Color = types.StringValue(va.String()) + } + } + data.Entries[i].Map[ci].Dscp = types.Int64Null() + + if t := cr.Get("dscp.optionType"); t.Exists() { + va := cr.Get("dscp.value") + if t.String() == "global" { + data.Entries[i].Map[ci].Dscp = types.Int64Value(va.Int()) + } + } + } + data.Entries[i].ForwardingClass = types.StringNull() + + if t := r.Get("forwardingClass.optionType"); t.Exists() { + va := r.Get("forwardingClass.value") + if t.String() == "global" { + data.Entries[i].ForwardingClass = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectAppProbeClass) 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_as_path_list.go b/internal/provider/model_sdwan_policy_object_as_path_list.go new file mode 100644 index 000000000..936f3d632 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_as_path_list.go @@ -0,0 +1,204 @@ +// 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 PolicyObjectASPathList 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"` + AsPathListId types.Int64 `tfsdk:"as_path_list_id"` + Entries []PolicyObjectASPathListEntries `tfsdk:"entries"` +} + +type PolicyObjectASPathListEntries struct { + AsPathList types.String `tfsdk:"as_path_list"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectASPathList) getModel() string { + return "policy_object_as_path_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectASPathList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/as-path", 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 PolicyObjectASPathList) 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.AsPathListId.IsNull() { + if true { + body, _ = sjson.Set(body, path+"asPathListNum.optionType", "global") + body, _ = sjson.Set(body, path+"asPathListNum.value", data.AsPathListId.ValueInt64()) + } + } + if true { + body, _ = sjson.Set(body, path+"entries", []interface{}{}) + for _, item := range data.Entries { + itemBody := "" + if !item.AsPathList.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "asPath.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "asPath.value", item.AsPathList.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 *PolicyObjectASPathList) 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.AsPathListId = types.Int64Null() + + if t := res.Get(path + "asPathListNum.optionType"); t.Exists() { + va := res.Get(path + "asPathListNum.value") + if t.String() == "global" { + data.AsPathListId = types.Int64Value(va.Int()) + } + } + if value := res.Get(path + "entries"); value.Exists() { + data.Entries = make([]PolicyObjectASPathListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectASPathListEntries{} + item.AsPathList = types.StringNull() + + if t := v.Get("asPath.optionType"); t.Exists() { + va := v.Get("asPath.value") + if t.String() == "global" { + item.AsPathList = 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 *PolicyObjectASPathList) 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.AsPathListId = types.Int64Null() + + if t := res.Get(path + "asPathListNum.optionType"); t.Exists() { + va := res.Get(path + "asPathListNum.value") + if t.String() == "global" { + data.AsPathListId = types.Int64Value(va.Int()) + } + } + for i := range data.Entries { + keys := [...]string{"asPath"} + keyValues := [...]string{data.Entries[i].AsPathList.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].AsPathList = types.StringNull() + + if t := r.Get("asPath.optionType"); t.Exists() { + va := r.Get("asPath.value") + if t.String() == "global" { + data.Entries[i].AsPathList = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectASPathList) isNull(ctx context.Context, res gjson.Result) bool { + if !data.FeatureProfileId.IsNull() { + return false + } + if !data.AsPathListId.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_preferred_color_group.go b/internal/provider/model_sdwan_policy_object_preferred_color_group.go new file mode 100644 index 000000000..f1078fc78 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_preferred_color_group.go @@ -0,0 +1,300 @@ +// 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 PolicyObjectPreferredColorGroup 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 []PolicyObjectPreferredColorGroupEntries `tfsdk:"entries"` +} + +type PolicyObjectPreferredColorGroupEntries struct { + PrimaryColorPreference types.Set `tfsdk:"primary_color_preference"` + PrimaryPathPreference types.String `tfsdk:"primary_path_preference"` + SecondaryColorPreference types.Set `tfsdk:"secondary_color_preference"` + SecondaryPathPreference types.String `tfsdk:"secondary_path_preference"` + TertiaryColorPreference types.Set `tfsdk:"tertiary_color_preference"` + TertiaryPathPreference types.String `tfsdk:"tertiary_path_preference"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectPreferredColorGroup) getModel() string { + return "policy_object_preferred_color_group" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectPreferredColorGroup) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/preferred-color-group", 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 PolicyObjectPreferredColorGroup) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.PrimaryColorPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "primaryPreference.colorPreference.optionType", "global") + var values []string + item.PrimaryColorPreference.ElementsAs(ctx, &values, false) + itemBody, _ = sjson.Set(itemBody, "primaryPreference.colorPreference.value", values) + } + } + if !item.PrimaryPathPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "primaryPreference.pathPreference.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "primaryPreference.pathPreference.value", item.PrimaryPathPreference.ValueString()) + } + } + if !item.SecondaryColorPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "secondaryPreference.colorPreference.optionType", "global") + var values []string + item.SecondaryColorPreference.ElementsAs(ctx, &values, false) + itemBody, _ = sjson.Set(itemBody, "secondaryPreference.colorPreference.value", values) + } + } + if !item.SecondaryPathPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "secondaryPreference.pathPreference.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "secondaryPreference.pathPreference.value", item.SecondaryPathPreference.ValueString()) + } + } + if !item.TertiaryColorPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.colorPreference.optionType", "global") + var values []string + item.TertiaryColorPreference.ElementsAs(ctx, &values, false) + itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.colorPreference.value", values) + } + } + if !item.TertiaryPathPreference.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.pathPreference.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "tertiaryPreference.pathPreference.value", item.TertiaryPathPreference.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 *PolicyObjectPreferredColorGroup) 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([]PolicyObjectPreferredColorGroupEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectPreferredColorGroupEntries{} + item.PrimaryColorPreference = types.SetNull(types.StringType) + + if t := v.Get("primaryPreference.colorPreference.optionType"); t.Exists() { + va := v.Get("primaryPreference.colorPreference.value") + if t.String() == "global" { + item.PrimaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + item.PrimaryPathPreference = types.StringNull() + + if t := v.Get("primaryPreference.pathPreference.optionType"); t.Exists() { + va := v.Get("primaryPreference.pathPreference.value") + if t.String() == "global" { + item.PrimaryPathPreference = types.StringValue(va.String()) + } + } + item.SecondaryColorPreference = types.SetNull(types.StringType) + + if t := v.Get("secondaryPreference.colorPreference.optionType"); t.Exists() { + va := v.Get("secondaryPreference.colorPreference.value") + if t.String() == "global" { + item.SecondaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + item.SecondaryPathPreference = types.StringNull() + + if t := v.Get("secondaryPreference.pathPreference.optionType"); t.Exists() { + va := v.Get("secondaryPreference.pathPreference.value") + if t.String() == "global" { + item.SecondaryPathPreference = types.StringValue(va.String()) + } + } + item.TertiaryColorPreference = types.SetNull(types.StringType) + + if t := v.Get("tertiaryPreference.colorPreference.optionType"); t.Exists() { + va := v.Get("tertiaryPreference.colorPreference.value") + if t.String() == "global" { + item.TertiaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + item.TertiaryPathPreference = types.StringNull() + + if t := v.Get("tertiaryPreference.pathPreference.optionType"); t.Exists() { + va := v.Get("tertiaryPreference.pathPreference.value") + if t.String() == "global" { + item.TertiaryPathPreference = 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 *PolicyObjectPreferredColorGroup) 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{"primaryPreference.pathPreference", "secondaryPreference.pathPreference", "tertiaryPreference.pathPreference"} + keyValues := [...]string{data.Entries[i].PrimaryPathPreference.ValueString(), data.Entries[i].SecondaryPathPreference.ValueString(), data.Entries[i].TertiaryPathPreference.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].PrimaryColorPreference = types.SetNull(types.StringType) + + if t := r.Get("primaryPreference.colorPreference.optionType"); t.Exists() { + va := r.Get("primaryPreference.colorPreference.value") + if t.String() == "global" { + data.Entries[i].PrimaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + data.Entries[i].PrimaryPathPreference = types.StringNull() + + if t := r.Get("primaryPreference.pathPreference.optionType"); t.Exists() { + va := r.Get("primaryPreference.pathPreference.value") + if t.String() == "global" { + data.Entries[i].PrimaryPathPreference = types.StringValue(va.String()) + } + } + data.Entries[i].SecondaryColorPreference = types.SetNull(types.StringType) + + if t := r.Get("secondaryPreference.colorPreference.optionType"); t.Exists() { + va := r.Get("secondaryPreference.colorPreference.value") + if t.String() == "global" { + data.Entries[i].SecondaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + data.Entries[i].SecondaryPathPreference = types.StringNull() + + if t := r.Get("secondaryPreference.pathPreference.optionType"); t.Exists() { + va := r.Get("secondaryPreference.pathPreference.value") + if t.String() == "global" { + data.Entries[i].SecondaryPathPreference = types.StringValue(va.String()) + } + } + data.Entries[i].TertiaryColorPreference = types.SetNull(types.StringType) + + if t := r.Get("tertiaryPreference.colorPreference.optionType"); t.Exists() { + va := r.Get("tertiaryPreference.colorPreference.value") + if t.String() == "global" { + data.Entries[i].TertiaryColorPreference = helpers.GetStringSet(va.Array()) + } + } + data.Entries[i].TertiaryPathPreference = types.StringNull() + + if t := r.Get("tertiaryPreference.pathPreference.optionType"); t.Exists() { + va := r.Get("tertiaryPreference.pathPreference.value") + if t.String() == "global" { + data.Entries[i].TertiaryPathPreference = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectPreferredColorGroup) 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_security_data_ipv4_prefix_list.go b/internal/provider/model_sdwan_policy_object_security_data_ipv4_prefix_list.go new file mode 100644 index 000000000..db1739136 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_data_ipv4_prefix_list.go @@ -0,0 +1,189 @@ +// 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 PolicyObjectSecurityDataIPv4PrefixList 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 []PolicyObjectSecurityDataIPv4PrefixListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityDataIPv4PrefixListEntries struct { + IpPrefix types.String `tfsdk:"ip_prefix"` + IpPrefixVariable types.String `tfsdk:"ip_prefix_variable"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityDataIPv4PrefixList) getModel() string { + return "policy_object_security_data_ipv4_prefix_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityDataIPv4PrefixList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-data-ip-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 PolicyObjectSecurityDataIPv4PrefixList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + + if !item.IpPrefixVariable.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "ipPrefix.optionType", "variable") + itemBody, _ = sjson.Set(itemBody, "ipPrefix.value", item.IpPrefixVariable.ValueString()) + } + } else if !item.IpPrefix.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "ipPrefix.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "ipPrefix.value", item.IpPrefix.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 *PolicyObjectSecurityDataIPv4PrefixList) 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([]PolicyObjectSecurityDataIPv4PrefixListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityDataIPv4PrefixListEntries{} + item.IpPrefix = types.StringNull() + item.IpPrefixVariable = types.StringNull() + if t := v.Get("ipPrefix.optionType"); t.Exists() { + va := v.Get("ipPrefix.value") + if t.String() == "variable" { + item.IpPrefixVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + item.IpPrefix = 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 *PolicyObjectSecurityDataIPv4PrefixList) 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{"ipPrefix"} + keyValues := [...]string{data.Entries[i].IpPrefix.ValueString()} + keyValuesVariables := [...]string{data.Entries[i].IpPrefixVariable.ValueString()} + + 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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].IpPrefix = types.StringNull() + data.Entries[i].IpPrefixVariable = types.StringNull() + if t := r.Get("ipPrefix.optionType"); t.Exists() { + va := r.Get("ipPrefix.value") + if t.String() == "variable" { + data.Entries[i].IpPrefixVariable = types.StringValue(va.String()) + } else if t.String() == "global" { + data.Entries[i].IpPrefix = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityDataIPv4PrefixList) 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_security_fqdn_list.go b/internal/provider/model_sdwan_policy_object_security_fqdn_list.go new file mode 100644 index 000000000..ff8c2fb5c --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_fqdn_list.go @@ -0,0 +1,178 @@ +// 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 PolicyObjectSecurityFQDNList 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 []PolicyObjectSecurityFQDNListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityFQDNListEntries struct { + Pattern types.String `tfsdk:"pattern"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityFQDNList) getModel() string { + return "policy_object_security_fqdn_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityFQDNList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-fqdn", 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 PolicyObjectSecurityFQDNList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.Pattern.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "pattern.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "pattern.value", item.Pattern.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 *PolicyObjectSecurityFQDNList) 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([]PolicyObjectSecurityFQDNListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityFQDNListEntries{} + item.Pattern = types.StringNull() + + if t := v.Get("pattern.optionType"); t.Exists() { + va := v.Get("pattern.value") + if t.String() == "global" { + item.Pattern = 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 *PolicyObjectSecurityFQDNList) 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{"pattern"} + keyValues := [...]string{data.Entries[i].Pattern.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].Pattern = types.StringNull() + + if t := r.Get("pattern.optionType"); t.Exists() { + va := r.Get("pattern.value") + if t.String() == "global" { + data.Entries[i].Pattern = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityFQDNList) 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_security_geolocation_list.go b/internal/provider/model_sdwan_policy_object_security_geolocation_list.go new file mode 100644 index 000000000..036e36390 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_geolocation_list.go @@ -0,0 +1,201 @@ +// 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 PolicyObjectSecurityGeolocationList 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 []PolicyObjectSecurityGeolocationListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityGeolocationListEntries struct { + Country types.String `tfsdk:"country"` + Continent types.String `tfsdk:"continent"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityGeolocationList) getModel() string { + return "policy_object_security_geolocation_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityGeolocationList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-geolocation", 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 PolicyObjectSecurityGeolocationList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.Country.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "country.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "country.value", item.Country.ValueString()) + } + } + if !item.Continent.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "continent.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "continent.value", item.Continent.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 *PolicyObjectSecurityGeolocationList) 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([]PolicyObjectSecurityGeolocationListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityGeolocationListEntries{} + item.Country = types.StringNull() + + if t := v.Get("country.optionType"); t.Exists() { + va := v.Get("country.value") + if t.String() == "global" { + item.Country = types.StringValue(va.String()) + } + } + item.Continent = types.StringNull() + + if t := v.Get("continent.optionType"); t.Exists() { + va := v.Get("continent.value") + if t.String() == "global" { + item.Continent = 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 *PolicyObjectSecurityGeolocationList) 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{"country", "continent"} + keyValues := [...]string{data.Entries[i].Country.ValueString(), data.Entries[i].Continent.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].Country = types.StringNull() + + if t := r.Get("country.optionType"); t.Exists() { + va := r.Get("country.value") + if t.String() == "global" { + data.Entries[i].Country = types.StringValue(va.String()) + } + } + data.Entries[i].Continent = types.StringNull() + + if t := r.Get("continent.optionType"); t.Exists() { + va := r.Get("continent.value") + if t.String() == "global" { + data.Entries[i].Continent = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityGeolocationList) 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_security_identity_list.go b/internal/provider/model_sdwan_policy_object_security_identity_list.go new file mode 100644 index 000000000..2e206d59c --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_identity_list.go @@ -0,0 +1,201 @@ +// 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 PolicyObjectSecurityIdentityList 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 []PolicyObjectSecurityIdentityListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityIdentityListEntries struct { + User types.String `tfsdk:"user"` + UserGroup types.String `tfsdk:"user_group"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityIdentityList) getModel() string { + return "policy_object_security_identity_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityIdentityList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-identity", 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 PolicyObjectSecurityIdentityList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.User.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "user.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "user.value", item.User.ValueString()) + } + } + if !item.UserGroup.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "userGroup.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "userGroup.value", item.UserGroup.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 *PolicyObjectSecurityIdentityList) 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([]PolicyObjectSecurityIdentityListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityIdentityListEntries{} + item.User = types.StringNull() + + if t := v.Get("user.optionType"); t.Exists() { + va := v.Get("user.value") + if t.String() == "global" { + item.User = types.StringValue(va.String()) + } + } + item.UserGroup = types.StringNull() + + if t := v.Get("userGroup.optionType"); t.Exists() { + va := v.Get("userGroup.value") + if t.String() == "global" { + item.UserGroup = 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 *PolicyObjectSecurityIdentityList) 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{"user", "userGroup"} + keyValues := [...]string{data.Entries[i].User.ValueString(), data.Entries[i].UserGroup.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].User = types.StringNull() + + if t := r.Get("user.optionType"); t.Exists() { + va := r.Get("user.value") + if t.String() == "global" { + data.Entries[i].User = types.StringValue(va.String()) + } + } + data.Entries[i].UserGroup = types.StringNull() + + if t := r.Get("userGroup.optionType"); t.Exists() { + va := r.Get("userGroup.value") + if t.String() == "global" { + data.Entries[i].UserGroup = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityIdentityList) 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_security_ips_signature.go b/internal/provider/model_sdwan_policy_object_security_ips_signature.go new file mode 100644 index 000000000..979af2783 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_ips_signature.go @@ -0,0 +1,201 @@ +// 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 PolicyObjectSecurityIPSSignature 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 []PolicyObjectSecurityIPSSignatureEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityIPSSignatureEntries struct { + GeneratorId types.String `tfsdk:"generator_id"` + SignatureId types.String `tfsdk:"signature_id"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityIPSSignature) getModel() string { + return "policy_object_security_ips_signature" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityIPSSignature) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-ipssignature", 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 PolicyObjectSecurityIPSSignature) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.GeneratorId.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "generatorId.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "generatorId.value", item.GeneratorId.ValueString()) + } + } + if !item.SignatureId.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "signatureId.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "signatureId.value", item.SignatureId.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 *PolicyObjectSecurityIPSSignature) 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([]PolicyObjectSecurityIPSSignatureEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityIPSSignatureEntries{} + item.GeneratorId = types.StringNull() + + if t := v.Get("generatorId.optionType"); t.Exists() { + va := v.Get("generatorId.value") + if t.String() == "global" { + item.GeneratorId = types.StringValue(va.String()) + } + } + item.SignatureId = types.StringNull() + + if t := v.Get("signatureId.optionType"); t.Exists() { + va := v.Get("signatureId.value") + if t.String() == "global" { + item.SignatureId = 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 *PolicyObjectSecurityIPSSignature) 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{"generatorId", "signatureId"} + keyValues := [...]string{data.Entries[i].GeneratorId.ValueString(), data.Entries[i].SignatureId.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].GeneratorId = types.StringNull() + + if t := r.Get("generatorId.optionType"); t.Exists() { + va := r.Get("generatorId.value") + if t.String() == "global" { + data.Entries[i].GeneratorId = types.StringValue(va.String()) + } + } + data.Entries[i].SignatureId = types.StringNull() + + if t := r.Get("signatureId.optionType"); t.Exists() { + va := r.Get("signatureId.value") + if t.String() == "global" { + data.Entries[i].SignatureId = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityIPSSignature) 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_security_local_application_list.go b/internal/provider/model_sdwan_policy_object_security_local_application_list.go new file mode 100644 index 000000000..5696df6fb --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_local_application_list.go @@ -0,0 +1,201 @@ +// 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 PolicyObjectSecurityLocalApplicationList 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 []PolicyObjectSecurityLocalApplicationListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityLocalApplicationListEntries struct { + App types.String `tfsdk:"app"` + AppFamily types.String `tfsdk:"app_family"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityLocalApplicationList) getModel() string { + return "policy_object_security_local_application_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityLocalApplicationList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-localapp", 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 PolicyObjectSecurityLocalApplicationList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.App.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "app.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "app.value", item.App.ValueString()) + } + } + if !item.AppFamily.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "appFamily.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "appFamily.value", item.AppFamily.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 *PolicyObjectSecurityLocalApplicationList) 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([]PolicyObjectSecurityLocalApplicationListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityLocalApplicationListEntries{} + item.App = types.StringNull() + + if t := v.Get("app.optionType"); t.Exists() { + va := v.Get("app.value") + if t.String() == "global" { + item.App = types.StringValue(va.String()) + } + } + item.AppFamily = types.StringNull() + + if t := v.Get("appFamily.optionType"); t.Exists() { + va := v.Get("appFamily.value") + if t.String() == "global" { + item.AppFamily = 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 *PolicyObjectSecurityLocalApplicationList) 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{"app", "appFamily"} + keyValues := [...]string{data.Entries[i].App.ValueString(), data.Entries[i].AppFamily.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].App = types.StringNull() + + if t := r.Get("app.optionType"); t.Exists() { + va := r.Get("app.value") + if t.String() == "global" { + data.Entries[i].App = types.StringValue(va.String()) + } + } + data.Entries[i].AppFamily = types.StringNull() + + if t := r.Get("appFamily.optionType"); t.Exists() { + va := r.Get("appFamily.value") + if t.String() == "global" { + data.Entries[i].AppFamily = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityLocalApplicationList) 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_security_local_domain_list.go b/internal/provider/model_sdwan_policy_object_security_local_domain_list.go new file mode 100644 index 000000000..a0fd93d91 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_local_domain_list.go @@ -0,0 +1,178 @@ +// 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 PolicyObjectSecurityLocalDomainList 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 []PolicyObjectSecurityLocalDomainListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityLocalDomainListEntries struct { + LocalDomain types.String `tfsdk:"local_domain"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityLocalDomainList) getModel() string { + return "policy_object_security_local_domain_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityLocalDomainList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-localdomain", 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 PolicyObjectSecurityLocalDomainList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.LocalDomain.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "nameServer.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "nameServer.value", item.LocalDomain.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 *PolicyObjectSecurityLocalDomainList) 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([]PolicyObjectSecurityLocalDomainListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityLocalDomainListEntries{} + item.LocalDomain = types.StringNull() + + if t := v.Get("nameServer.optionType"); t.Exists() { + va := v.Get("nameServer.value") + if t.String() == "global" { + item.LocalDomain = 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 *PolicyObjectSecurityLocalDomainList) 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{"nameServer"} + keyValues := [...]string{data.Entries[i].LocalDomain.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].LocalDomain = types.StringNull() + + if t := r.Get("nameServer.optionType"); t.Exists() { + va := r.Get("nameServer.value") + if t.String() == "global" { + data.Entries[i].LocalDomain = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityLocalDomainList) 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_security_port_list.go b/internal/provider/model_sdwan_policy_object_security_port_list.go new file mode 100644 index 000000000..d63a92a47 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_port_list.go @@ -0,0 +1,178 @@ +// 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 PolicyObjectSecurityPortList 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 []PolicyObjectSecurityPortListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityPortListEntries struct { + Port types.String `tfsdk:"port"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityPortList) getModel() string { + return "policy_object_security_port_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityPortList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-port", 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 PolicyObjectSecurityPortList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.Port.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "port.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "port.value", item.Port.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 *PolicyObjectSecurityPortList) 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([]PolicyObjectSecurityPortListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityPortListEntries{} + item.Port = types.StringNull() + + if t := v.Get("port.optionType"); t.Exists() { + va := v.Get("port.value") + if t.String() == "global" { + item.Port = 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 *PolicyObjectSecurityPortList) 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{"port"} + keyValues := [...]string{data.Entries[i].Port.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].Port = types.StringNull() + + if t := r.Get("port.optionType"); t.Exists() { + va := r.Get("port.value") + if t.String() == "global" { + data.Entries[i].Port = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityPortList) 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_security_scalable_group_tag_list.go b/internal/provider/model_sdwan_policy_object_security_scalable_group_tag_list.go new file mode 100644 index 000000000..6aecc5bd3 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_scalable_group_tag_list.go @@ -0,0 +1,201 @@ +// 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 PolicyObjectSecurityScalableGroupTagList 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 []PolicyObjectSecurityScalableGroupTagListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityScalableGroupTagListEntries struct { + SgtName types.String `tfsdk:"sgt_name"` + Tag types.String `tfsdk:"tag"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityScalableGroupTagList) getModel() string { + return "policy_object_security_scalable_group_tag_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityScalableGroupTagList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-scalablegrouptag", 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 PolicyObjectSecurityScalableGroupTagList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.SgtName.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "sgtName.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "sgtName.value", item.SgtName.ValueString()) + } + } + if !item.Tag.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "tag.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "tag.value", item.Tag.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 *PolicyObjectSecurityScalableGroupTagList) 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([]PolicyObjectSecurityScalableGroupTagListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityScalableGroupTagListEntries{} + item.SgtName = types.StringNull() + + if t := v.Get("sgtName.optionType"); t.Exists() { + va := v.Get("sgtName.value") + if t.String() == "global" { + item.SgtName = types.StringValue(va.String()) + } + } + item.Tag = types.StringNull() + + if t := v.Get("tag.optionType"); t.Exists() { + va := v.Get("tag.value") + if t.String() == "global" { + item.Tag = 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 *PolicyObjectSecurityScalableGroupTagList) 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{"sgtName", "tag"} + keyValues := [...]string{data.Entries[i].SgtName.ValueString(), data.Entries[i].Tag.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].SgtName = types.StringNull() + + if t := r.Get("sgtName.optionType"); t.Exists() { + va := r.Get("sgtName.value") + if t.String() == "global" { + data.Entries[i].SgtName = types.StringValue(va.String()) + } + } + data.Entries[i].Tag = types.StringNull() + + if t := r.Get("tag.optionType"); t.Exists() { + va := r.Get("tag.value") + if t.String() == "global" { + data.Entries[i].Tag = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityScalableGroupTagList) 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_security_url_list.go b/internal/provider/model_sdwan_policy_object_security_url_list.go new file mode 100644 index 000000000..fbeec73d3 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_security_url_list.go @@ -0,0 +1,178 @@ +// 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 PolicyObjectSecurityURLList 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 []PolicyObjectSecurityURLListEntries `tfsdk:"entries"` +} + +type PolicyObjectSecurityURLListEntries struct { + Pattern types.String `tfsdk:"pattern"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectSecurityURLList) getModel() string { + return "policy_object_security_url_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectSecurityURLList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/security-urllist", 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 PolicyObjectSecurityURLList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.Pattern.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "pattern.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "pattern.value", item.Pattern.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 *PolicyObjectSecurityURLList) 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([]PolicyObjectSecurityURLListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectSecurityURLListEntries{} + item.Pattern = types.StringNull() + + if t := v.Get("pattern.optionType"); t.Exists() { + va := v.Get("pattern.value") + if t.String() == "global" { + item.Pattern = 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 *PolicyObjectSecurityURLList) 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{"pattern"} + keyValues := [...]string{data.Entries[i].Pattern.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].Pattern = types.StringNull() + + if t := r.Get("pattern.optionType"); t.Exists() { + va := r.Get("pattern.value") + if t.String() == "global" { + data.Entries[i].Pattern = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectSecurityURLList) 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_standard_community_list.go b/internal/provider/model_sdwan_policy_object_standard_community_list.go new file mode 100644 index 000000000..c80a5eaae --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_standard_community_list.go @@ -0,0 +1,178 @@ +// 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 PolicyObjectStandardCommunityList 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 []PolicyObjectStandardCommunityListEntries `tfsdk:"entries"` +} + +type PolicyObjectStandardCommunityListEntries struct { + StandardCommunity types.String `tfsdk:"standard_community"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectStandardCommunityList) getModel() string { + return "policy_object_standard_community_list" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectStandardCommunityList) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/standard-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 PolicyObjectStandardCommunityList) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + + for _, item := range data.Entries { + itemBody := "" + if !item.StandardCommunity.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "standardCommunity.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "standardCommunity.value", item.StandardCommunity.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 *PolicyObjectStandardCommunityList) 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([]PolicyObjectStandardCommunityListEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectStandardCommunityListEntries{} + item.StandardCommunity = types.StringNull() + + if t := v.Get("standardCommunity.optionType"); t.Exists() { + va := v.Get("standardCommunity.value") + if t.String() == "global" { + item.StandardCommunity = 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 *PolicyObjectStandardCommunityList) 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{"standardCommunity"} + keyValues := [...]string{data.Entries[i].StandardCommunity.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].StandardCommunity = types.StringNull() + + if t := r.Get("standardCommunity.optionType"); t.Exists() { + va := r.Get("standardCommunity.value") + if t.String() == "global" { + data.Entries[i].StandardCommunity = types.StringValue(va.String()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectStandardCommunityList) 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_vpn_group.go b/internal/provider/model_sdwan_policy_object_vpn_group.go new file mode 100644 index 000000000..023c4cfc7 --- /dev/null +++ b/internal/provider/model_sdwan_policy_object_vpn_group.go @@ -0,0 +1,179 @@ +// 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 PolicyObjectVPNGroup 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 []PolicyObjectVPNGroupEntries `tfsdk:"entries"` +} + +type PolicyObjectVPNGroupEntries struct { + Vpn types.Int64 `tfsdk:"vpn"` +} + +// End of section. //template:end types + +// Section below is generated&owned by "gen/generator.go". //template:begin getModel +func (data PolicyObjectVPNGroup) getModel() string { + return "policy_object_vpn_group" +} + +// End of section. //template:end getModel + +// Section below is generated&owned by "gen/generator.go". //template:begin getPath +func (data PolicyObjectVPNGroup) getPath() string { + return fmt.Sprintf("/v1/feature-profile/sdwan/policy-object/%v/vpn-group", 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 PolicyObjectVPNGroup) toBody(ctx context.Context) string { + body := "" + body, _ = sjson.Set(body, "name", data.Name.ValueString()) + body, _ = sjson.Set(body, "description", data.Description.ValueString()) + path := "data." + if true { + body, _ = sjson.Set(body, path+"entries", []interface{}{}) + for _, item := range data.Entries { + itemBody := "" + if !item.Vpn.IsNull() { + if true { + itemBody, _ = sjson.Set(itemBody, "vpn.optionType", "global") + itemBody, _ = sjson.Set(itemBody, "vpn.value", item.Vpn.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 *PolicyObjectVPNGroup) 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([]PolicyObjectVPNGroupEntries, 0) + value.ForEach(func(k, v gjson.Result) bool { + item := PolicyObjectVPNGroupEntries{} + item.Vpn = types.Int64Null() + + if t := v.Get("vpn.optionType"); t.Exists() { + va := v.Get("vpn.value") + if t.String() == "global" { + item.Vpn = 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 *PolicyObjectVPNGroup) 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{"vpn"} + keyValues := [...]string{strconv.FormatInt(data.Entries[i].Vpn.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") + vv := v.Get(keys[ik] + ".value") + if tt.Exists() && vv.Exists() { + if (tt.String() == "variable" && vv.String() == keyValuesVariables[ik]) || (tt.String() == "global" && vv.String() == keyValues[ik]) { + found = true + continue + } + found = false + break + } + continue + } + if found { + r = v + return false + } + return true + }, + ) + data.Entries[i].Vpn = types.Int64Null() + + if t := r.Get("vpn.optionType"); t.Exists() { + va := r.Get("vpn.value") + if t.String() == "global" { + data.Entries[i].Vpn = types.Int64Value(va.Int()) + } + } + } +} + +// End of section. //template:end updateFromBody + +// Section below is generated&owned by "gen/generator.go". //template:begin isNull +func (data *PolicyObjectVPNGroup) 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 845eb8326..65d2ef335 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -285,7 +285,9 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewApplicationPriorityQoSProfileParcelResource, NewOtherThousandEyesProfileParcelResource, NewOtherUCSEProfileParcelResource, + NewPolicyObjectAppProbeClassProfileParcelResource, NewPolicyObjectApplicationListProfileParcelResource, + NewPolicyObjectASPathListProfileParcelResource, NewPolicyObjectClassMapProfileParcelResource, NewPolicyObjectColorListProfileParcelResource, NewPolicyObjectDataIPv4PrefixListProfileParcelResource, @@ -296,8 +298,21 @@ func (p *SdwanProvider) Resources(ctx context.Context) []func() resource.Resourc NewPolicyObjectIPv6PrefixListProfileParcelResource, NewPolicyObjectMirrorProfileParcelResource, NewPolicyObjectPolicerProfileParcelResource, + NewPolicyObjectPreferredColorGroupProfileParcelResource, + NewPolicyObjectSecurityDataIPv4PrefixListProfileParcelResource, + NewPolicyObjectSecurityFQDNListProfileParcelResource, + NewPolicyObjectSecurityGeolocationListProfileParcelResource, + NewPolicyObjectSecurityIdentityListProfileParcelResource, + NewPolicyObjectSecurityIPSSignatureProfileParcelResource, + NewPolicyObjectSecurityLocalApplicationListProfileParcelResource, + NewPolicyObjectSecurityLocalDomainListProfileParcelResource, + NewPolicyObjectSecurityPortListProfileParcelResource, + NewPolicyObjectSecurityScalableGroupTagListProfileParcelResource, + NewPolicyObjectSecurityURLListProfileParcelResource, NewPolicyObjectSLAClassListProfileParcelResource, + NewPolicyObjectStandardCommunityListProfileParcelResource, NewPolicyObjectTLOCListProfileParcelResource, + NewPolicyObjectVPNGroupProfileParcelResource, NewServiceLANVPNProfileParcelResource, NewServiceLANVPNInterfaceEthernetProfileParcelResource, NewServiceLANVPNInterfaceGREProfileParcelResource, @@ -467,7 +482,9 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewApplicationPriorityQoSProfileParcelDataSource, NewOtherThousandEyesProfileParcelDataSource, NewOtherUCSEProfileParcelDataSource, + NewPolicyObjectAppProbeClassProfileParcelDataSource, NewPolicyObjectApplicationListProfileParcelDataSource, + NewPolicyObjectASPathListProfileParcelDataSource, NewPolicyObjectClassMapProfileParcelDataSource, NewPolicyObjectColorListProfileParcelDataSource, NewPolicyObjectDataIPv4PrefixListProfileParcelDataSource, @@ -478,8 +495,21 @@ func (p *SdwanProvider) DataSources(ctx context.Context) []func() datasource.Dat NewPolicyObjectIPv6PrefixListProfileParcelDataSource, NewPolicyObjectMirrorProfileParcelDataSource, NewPolicyObjectPolicerProfileParcelDataSource, + NewPolicyObjectPreferredColorGroupProfileParcelDataSource, + NewPolicyObjectSecurityDataIPv4PrefixListProfileParcelDataSource, + NewPolicyObjectSecurityFQDNListProfileParcelDataSource, + NewPolicyObjectSecurityGeolocationListProfileParcelDataSource, + NewPolicyObjectSecurityIdentityListProfileParcelDataSource, + NewPolicyObjectSecurityIPSSignatureProfileParcelDataSource, + NewPolicyObjectSecurityLocalApplicationListProfileParcelDataSource, + NewPolicyObjectSecurityLocalDomainListProfileParcelDataSource, + NewPolicyObjectSecurityPortListProfileParcelDataSource, + NewPolicyObjectSecurityScalableGroupTagListProfileParcelDataSource, + NewPolicyObjectSecurityURLListProfileParcelDataSource, NewPolicyObjectSLAClassListProfileParcelDataSource, + NewPolicyObjectStandardCommunityListProfileParcelDataSource, NewPolicyObjectTLOCListProfileParcelDataSource, + NewPolicyObjectVPNGroupProfileParcelDataSource, NewServiceLANVPNProfileParcelDataSource, NewServiceLANVPNInterfaceEthernetProfileParcelDataSource, NewServiceLANVPNInterfaceGREProfileParcelDataSource, diff --git a/internal/provider/resource_sdwan_policy_object_app_probe_class.go b/internal/provider/resource_sdwan_policy_object_app_probe_class.go new file mode 100644 index 000000000..25a402d26 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_app_probe_class.go @@ -0,0 +1,277 @@ +// 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-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 = &PolicyObjectAppProbeClassProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectAppProbeClassProfileParcelResource{} + +func NewPolicyObjectAppProbeClassProfileParcelResource() resource.Resource { + return &PolicyObjectAppProbeClassProfileParcelResource{} +} + +type PolicyObjectAppProbeClassProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectAppProbeClassProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_app_probe_class" +} + +func (r *PolicyObjectAppProbeClassProfileParcelResource) 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 App Probe Class Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("App Probe List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "map": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Map").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "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"), + }, + }, + "dscp": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("DSCP number").AddIntegerRangeDescription(0, 63).String, + Optional: true, + Validators: []validator.Int64{ + int64validator.AtMost(63), + }, + }, + }, + }, + }, + "forwarding_class": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Forwarding Class Name").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectAppProbeClassProfileParcelResource) 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 *PolicyObjectAppProbeClassProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectAppProbeClass + + // 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 *PolicyObjectAppProbeClassProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectAppProbeClass + + // 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 *PolicyObjectAppProbeClassProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectAppProbeClass + + // 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 *PolicyObjectAppProbeClassProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectAppProbeClass + + // 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 *PolicyObjectAppProbeClassProfileParcelResource) 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_app_probe_class_test.go b/internal/provider/resource_sdwan_policy_object_app_probe_class_test.go new file mode 100644 index 000000000..cd28fc88f --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_app_probe_class_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 TestAccSdwanPolicyObjectAppProbeClassProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_app_probe_class.test", "entries.0.map.0.color", "3g")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_app_probe_class.test", "entries.0.map.0.dscp", "45")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_app_probe_class.test", "entries.0.forwarding_class", "classlist1")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectAppProbeClassPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectAppProbeClassProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectAppProbeClassPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectAppProbeClassProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_app_probe_class" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` map = [{` + "\n" + config += ` color = "3g"` + "\n" + config += ` dscp = 45` + "\n" + config += ` }]` + "\n" + config += ` forwarding_class = "classlist1"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_as_path_list.go b/internal/provider/resource_sdwan_policy_object_as_path_list.go new file mode 100644 index 000000000..d37ba1003 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_as_path_list.go @@ -0,0 +1,266 @@ +// 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/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/netascode/go-sdwan" +) + +// End of section. //template:end imports + +// Section below is generated&owned by "gen/generator.go". //template:begin model + +// Ensure provider defined types fully satisfy framework interfaces +var _ resource.Resource = &PolicyObjectASPathListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectASPathListProfileParcelResource{} + +func NewPolicyObjectASPathListProfileParcelResource() resource.Resource { + return &PolicyObjectASPathListProfileParcelResource{} +} + +type PolicyObjectASPathListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectASPathListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_as_path_list" +} + +func (r *PolicyObjectASPathListProfileParcelResource) 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 AS Path List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "as_path_list_id": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("As path List Number").AddIntegerRangeDescription(1, 500).String, + Required: true, + Validators: []validator.Int64{ + int64validator.Between(1, 500), + }, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("AS Path List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "as_path_list": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`[^<>]*`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectASPathListProfileParcelResource) 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 *PolicyObjectASPathListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectASPathList + + // 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 *PolicyObjectASPathListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectASPathList + + // 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 *PolicyObjectASPathListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectASPathList + + // 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 *PolicyObjectASPathListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectASPathList + + // 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 *PolicyObjectASPathListProfileParcelResource) 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_as_path_list_test.go b/internal/provider/resource_sdwan_policy_object_as_path_list_test.go new file mode 100644 index 000000000..27888d543 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_as_path_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccSdwanPolicyObjectASPathListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_as_path_list.test", "as_path_list_id", "1")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_as_path_list.test", "entries.0.as_path_list", "110")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectASPathListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectASPathListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectASPathListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectASPathListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_as_path_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` as_path_list_id = 1` + "\n" + config += ` entries = [{` + "\n" + config += ` as_path_list = "110"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_preferred_color_group.go b/internal/provider/resource_sdwan_policy_object_preferred_color_group.go new file mode 100644 index 000000000..43be0a927 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_preferred_color_group.go @@ -0,0 +1,286 @@ +// 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 = &PolicyObjectPreferredColorGroupProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectPreferredColorGroupProfileParcelResource{} + +func NewPolicyObjectPreferredColorGroupProfileParcelResource() resource.Resource { + return &PolicyObjectPreferredColorGroupProfileParcelResource{} +} + +type PolicyObjectPreferredColorGroupProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectPreferredColorGroupProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_preferred_color_group" +} + +func (r *PolicyObjectPreferredColorGroupProfileParcelResource) 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 Preferred Color Group Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Preferred Color Group List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "primary_color_preference": schema.SetAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + ElementType: types.StringType, + Optional: true, + }, + "primary_path_preference": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").AddStringEnumDescription("all-paths", "direct-path", "multi-hop-path").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("all-paths", "direct-path", "multi-hop-path"), + }, + }, + "secondary_color_preference": schema.SetAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + ElementType: types.StringType, + Optional: true, + }, + "secondary_path_preference": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").AddStringEnumDescription("all-paths", "direct-path", "multi-hop-path").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("all-paths", "direct-path", "multi-hop-path"), + }, + }, + "tertiary_color_preference": schema.SetAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + ElementType: types.StringType, + Optional: true, + }, + "tertiary_path_preference": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").AddStringEnumDescription("all-paths", "direct-path", "multi-hop-path").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("all-paths", "direct-path", "multi-hop-path"), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectPreferredColorGroupProfileParcelResource) 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 *PolicyObjectPreferredColorGroupProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectPreferredColorGroup + + // 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 *PolicyObjectPreferredColorGroupProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectPreferredColorGroup + + // 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 *PolicyObjectPreferredColorGroupProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectPreferredColorGroup + + // 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 *PolicyObjectPreferredColorGroupProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectPreferredColorGroup + + // 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 *PolicyObjectPreferredColorGroupProfileParcelResource) 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_preferred_color_group_test.go b/internal/provider/resource_sdwan_policy_object_preferred_color_group_test.go new file mode 100644 index 000000000..5890e0ad6 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_preferred_color_group_test.go @@ -0,0 +1,86 @@ +// 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 TestAccSdwanPolicyObjectPreferredColorGroupProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_preferred_color_group.test", "entries.0.primary_path_preference", "direct-path")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_preferred_color_group.test", "entries.0.secondary_path_preference", "all-paths")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_preferred_color_group.test", "entries.0.tertiary_path_preference", "all-paths")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectPreferredColorGroupPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectPreferredColorGroupProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectPreferredColorGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectPreferredColorGroupProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_preferred_color_group" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` primary_color_preference = ["default"]` + "\n" + config += ` primary_path_preference = "direct-path"` + "\n" + config += ` secondary_color_preference = ["bronze"]` + "\n" + config += ` secondary_path_preference = "all-paths"` + "\n" + config += ` tertiary_color_preference = ["blue"]` + "\n" + config += ` tertiary_path_preference = "all-paths"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_data_ipv4_prefix_list.go b/internal/provider/resource_sdwan_policy_object_security_data_ipv4_prefix_list.go new file mode 100644 index 000000000..95aa64a96 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_data_ipv4_prefix_list.go @@ -0,0 +1,262 @@ +// 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 = &PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource{} + +func NewPolicyObjectSecurityDataIPv4PrefixListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource{} +} + +type PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_data_ipv4_prefix_list" +} + +func (r *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) 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 Security Data IPv4 Prefix List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "ip_prefix": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/)([0-2]?[0-9]$|[3]?[0-2])`), ""), + }, + }, + "ip_prefix_variable": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Variable name").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityDataIPv4PrefixList + + // 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityDataIPv4PrefixList + + // 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityDataIPv4PrefixList + + // 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityDataIPv4PrefixList + + // 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 *PolicyObjectSecurityDataIPv4PrefixListProfileParcelResource) 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_security_data_ipv4_prefix_list_test.go b/internal/provider/resource_sdwan_policy_object_security_data_ipv4_prefix_list_test.go new file mode 100644 index 000000000..90a590128 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_data_ipv4_prefix_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_data_ipv4_prefix_list.test", "entries.0.ip_prefix", "10.0.0.0/12")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityDataIPv4PrefixListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityDataIPv4PrefixListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityDataIPv4PrefixListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_data_ipv4_prefix_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` ip_prefix = "10.0.0.0/12"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_fqdn_list.go b/internal/provider/resource_sdwan_policy_object_security_fqdn_list.go new file mode 100644 index 000000000..7a80296d0 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_fqdn_list.go @@ -0,0 +1,259 @@ +// 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 = &PolicyObjectSecurityFQDNListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityFQDNListProfileParcelResource{} + +func NewPolicyObjectSecurityFQDNListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityFQDNListProfileParcelResource{} +} + +type PolicyObjectSecurityFQDNListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityFQDNListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_fqdn_list" +} + +func (r *PolicyObjectSecurityFQDNListProfileParcelResource) 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 Security FQDN List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "pattern": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 120), + stringvalidator.RegexMatches(regexp.MustCompile(`^([*][.])?(([a-zA-Z0-9-]+.)+)?([a-zA-Z0-9-])+$`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityFQDNListProfileParcelResource) 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 *PolicyObjectSecurityFQDNListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityFQDNList + + // 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 *PolicyObjectSecurityFQDNListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityFQDNList + + // 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 *PolicyObjectSecurityFQDNListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityFQDNList + + // 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 *PolicyObjectSecurityFQDNListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityFQDNList + + // 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 *PolicyObjectSecurityFQDNListProfileParcelResource) 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_security_fqdn_list_test.go b/internal/provider/resource_sdwan_policy_object_security_fqdn_list_test.go new file mode 100644 index 000000000..2b68cd2b9 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_fqdn_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityFQDNListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_fqdn_list.test", "entries.0.pattern", "cisco.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityFQDNListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityFQDNListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityFQDNListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityFQDNListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_fqdn_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` pattern = "cisco.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_geolocation_list.go b/internal/provider/resource_sdwan_policy_object_security_geolocation_list.go new file mode 100644 index 000000000..a3e1f7986 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_geolocation_list.go @@ -0,0 +1,264 @@ +// 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 = &PolicyObjectSecurityGeolocationListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityGeolocationListProfileParcelResource{} + +func NewPolicyObjectSecurityGeolocationListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityGeolocationListProfileParcelResource{} +} + +type PolicyObjectSecurityGeolocationListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityGeolocationListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_geolocation_list" +} + +func (r *PolicyObjectSecurityGeolocationListProfileParcelResource) 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 Security Geolocation List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Geolocation List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "country": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("country names").AddStringEnumDescription("AFG", "ALB", "ATA", "DZA", "ASM", "AND", "AGO", "ATG", "AZE", "ARG", "AUS", "AUT", "BHS", "BHR", "BGD", "ARM", "BRB", "BEL", "BMU", "BTN", "BOL", "BIH", "BWA", "BVT", "BRA", "BLZ", "IOT", "SLB", "VGB", "BRN", "BGR", "MMR", "BDI", "BLR", "KHM", "CMR", "CAN", "CPV", "CYM", "CAF", "LKA", "TCD", "CHL", "CHN", "TWN", "CXR", "CCK", "COL", "COM", "MYT", "COG", "COD", "COK", "CRI", "HRV", "CUB", "CYP", "CZE", "BEN", "DNK", "DMA", "DOM", "ECU", "SLV", "GNQ", "ETH", "ERI", "EST", "FRO", "FLK", "SGS", "FJI", "FIN", "ALA", "FRA", "GUF", "PYF", "ATF", "DJI", "GAB", "GEO", "GMB", "PSE", "DEU", "GHA", "GIB", "KIR", "GRC", "GRL", "GRD", "GLP", "GUM", "GTM", "GIN", "GUY", "HTI", "HMD", "VAT", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "ISR", "ITA", "CIV", "JAM", "JPN", "KAZ", "JOR", "KEN", "PRK", "KOR", "KWT", "KGZ", "LAO", "LBN", "LSO", "LVA", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MTQ", "MRT", "MUS", "MEX", "MCO", "MNG", "MDA", "MNE", "MSR", "MAR", "MOZ", "OMN", "NAM", "NRU", "NPL", "NLD", "ANT", "CUW", "ABW", "SXM", "BES", "NCL", "VUT", "NZL", "NIC", "NER", "NGA", "NIU", "NFK", "NOR", "MNP", "UMI", "FSM", "MHL", "PLW", "PAK", "PAN", "PNG", "PRY", "PER", "PHL", "PCN", "POL", "PRT", "GNB", "TLS", "PRI", "QAT", "REU", "ROU", "RUS", "RWA", "BLM", "SHN", "KNA", "AIA", "LCA", "MAF", "SPM", "VCT", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SVK", "VNM", "SVN", "SOM", "ZAF", "ZWE", "ESP", "SSD", "ESH", "SDN", "SUR", "SJM", "SWZ", "SWE", "CHE", "SYR", "TJK", "THA", "TGO", "TKL", "TON", "TTO", "ARE", "TUN", "TUR", "TKM", "TCA", "TUV", "UGA", "UKR", "MKD", "EGY", "GBR", "GGY", "JEY", "IMN", "TZA", "USA", "VIR", "BFA", "URY", "UZB", "VEN", "WLF", "WSM", "YEM", "ZMB").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("AFG", "ALB", "ATA", "DZA", "ASM", "AND", "AGO", "ATG", "AZE", "ARG", "AUS", "AUT", "BHS", "BHR", "BGD", "ARM", "BRB", "BEL", "BMU", "BTN", "BOL", "BIH", "BWA", "BVT", "BRA", "BLZ", "IOT", "SLB", "VGB", "BRN", "BGR", "MMR", "BDI", "BLR", "KHM", "CMR", "CAN", "CPV", "CYM", "CAF", "LKA", "TCD", "CHL", "CHN", "TWN", "CXR", "CCK", "COL", "COM", "MYT", "COG", "COD", "COK", "CRI", "HRV", "CUB", "CYP", "CZE", "BEN", "DNK", "DMA", "DOM", "ECU", "SLV", "GNQ", "ETH", "ERI", "EST", "FRO", "FLK", "SGS", "FJI", "FIN", "ALA", "FRA", "GUF", "PYF", "ATF", "DJI", "GAB", "GEO", "GMB", "PSE", "DEU", "GHA", "GIB", "KIR", "GRC", "GRL", "GRD", "GLP", "GUM", "GTM", "GIN", "GUY", "HTI", "HMD", "VAT", "HND", "HKG", "HUN", "ISL", "IND", "IDN", "IRN", "IRQ", "IRL", "ISR", "ITA", "CIV", "JAM", "JPN", "KAZ", "JOR", "KEN", "PRK", "KOR", "KWT", "KGZ", "LAO", "LBN", "LSO", "LVA", "LBR", "LBY", "LIE", "LTU", "LUX", "MAC", "MDG", "MWI", "MYS", "MDV", "MLI", "MLT", "MTQ", "MRT", "MUS", "MEX", "MCO", "MNG", "MDA", "MNE", "MSR", "MAR", "MOZ", "OMN", "NAM", "NRU", "NPL", "NLD", "ANT", "CUW", "ABW", "SXM", "BES", "NCL", "VUT", "NZL", "NIC", "NER", "NGA", "NIU", "NFK", "NOR", "MNP", "UMI", "FSM", "MHL", "PLW", "PAK", "PAN", "PNG", "PRY", "PER", "PHL", "PCN", "POL", "PRT", "GNB", "TLS", "PRI", "QAT", "REU", "ROU", "RUS", "RWA", "BLM", "SHN", "KNA", "AIA", "LCA", "MAF", "SPM", "VCT", "SMR", "STP", "SAU", "SEN", "SRB", "SYC", "SLE", "SGP", "SVK", "VNM", "SVN", "SOM", "ZAF", "ZWE", "ESP", "SSD", "ESH", "SDN", "SUR", "SJM", "SWZ", "SWE", "CHE", "SYR", "TJK", "THA", "TGO", "TKL", "TON", "TTO", "ARE", "TUN", "TUR", "TKM", "TCA", "TUV", "UGA", "UKR", "MKD", "EGY", "GBR", "GGY", "JEY", "IMN", "TZA", "USA", "VIR", "BFA", "URY", "UZB", "VEN", "WLF", "WSM", "YEM", "ZMB"), + }, + }, + "continent": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("continent name").AddStringEnumDescription("AF", "AN", "AS", "EU", "NA", "OC", "SA").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.OneOf("AF", "AN", "AS", "EU", "NA", "OC", "SA"), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityGeolocationListProfileParcelResource) 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 *PolicyObjectSecurityGeolocationListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityGeolocationList + + // 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 *PolicyObjectSecurityGeolocationListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityGeolocationList + + // 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 *PolicyObjectSecurityGeolocationListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityGeolocationList + + // 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 *PolicyObjectSecurityGeolocationListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityGeolocationList + + // 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 *PolicyObjectSecurityGeolocationListProfileParcelResource) 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_security_geolocation_list_test.go b/internal/provider/resource_sdwan_policy_object_security_geolocation_list_test.go new file mode 100644 index 000000000..b4097a9c6 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_geolocation_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityGeolocationListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_geolocation_list.test", "entries.0.country", "DZA")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityGeolocationListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityGeolocationListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityGeolocationListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityGeolocationListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_geolocation_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` country = "DZA"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_identity_list.go b/internal/provider/resource_sdwan_policy_object_security_identity_list.go new file mode 100644 index 000000000..cc21ec482 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_identity_list.go @@ -0,0 +1,267 @@ +// 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 = &PolicyObjectSecurityIdentityListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityIdentityListProfileParcelResource{} + +func NewPolicyObjectSecurityIdentityListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityIdentityListProfileParcelResource{} +} + +type PolicyObjectSecurityIdentityListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityIdentityListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_identity_list" +} + +func (r *PolicyObjectSecurityIdentityListProfileParcelResource) 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 Security Identity List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Array of Users and User Groups").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "user": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 64), + stringvalidator.RegexMatches(regexp.MustCompile(`^.*[a-zA-Z0-9]+.*$`), ""), + }, + }, + "user_group": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 96), + stringvalidator.RegexMatches(regexp.MustCompile(`^.*[a-zA-Z0-9]+.*$`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityIdentityListProfileParcelResource) 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 *PolicyObjectSecurityIdentityListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityIdentityList + + // 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 *PolicyObjectSecurityIdentityListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityIdentityList + + // 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 *PolicyObjectSecurityIdentityListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityIdentityList + + // 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 *PolicyObjectSecurityIdentityListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityIdentityList + + // 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 *PolicyObjectSecurityIdentityListProfileParcelResource) 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_security_identity_list_test.go b/internal/provider/resource_sdwan_policy_object_security_identity_list_test.go new file mode 100644 index 000000000..b64414b7b --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_identity_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityIdentityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_identity_list.test", "entries.0.user", "administrator")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityIdentityListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityIdentityListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityIdentityListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityIdentityListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_identity_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` user = "administrator"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_ips_signature.go b/internal/provider/resource_sdwan_policy_object_security_ips_signature.go new file mode 100644 index 000000000..9ad7a8e11 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_ips_signature.go @@ -0,0 +1,265 @@ +// 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 = &PolicyObjectSecurityIPSSignatureProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityIPSSignatureProfileParcelResource{} + +func NewPolicyObjectSecurityIPSSignatureProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityIPSSignatureProfileParcelResource{} +} + +type PolicyObjectSecurityIPSSignatureProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityIPSSignatureProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_ips_signature" +} + +func (r *PolicyObjectSecurityIPSSignatureProfileParcelResource) 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 Security IPS Signature Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Ips Signature").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "generator_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`^(429496729[0-5]|42949672[0-8]\d|4294967[01]\d{2}|429496[0-6]\d{3}|42949[0-5]\d{4}|4294[0-8]\d{5}|429[0-3]\d{6}|42[0-8]\d{7}|4[01]\d{8}|[1-3]\d{9}|[1-9]\d{8}|[1-9]\d{7}|[1-9]\d{6}|[1-9]\d{5}|[1-9]\d{4}|[1-9]\d{3}|[1-9]\d{2}|[1-9]\d|\d)$`), ""), + }, + }, + "signature_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexp.MustCompile(`^(429496729[0-5]|42949672[0-8]\d|4294967[01]\d{2}|429496[0-6]\d{3}|42949[0-5]\d{4}|4294[0-8]\d{5}|429[0-3]\d{6}|42[0-8]\d{7}|4[01]\d{8}|[1-3]\d{9}|[1-9]\d{8}|[1-9]\d{7}|[1-9]\d{6}|[1-9]\d{5}|[1-9]\d{4}|[1-9]\d{3}|[1-9]\d{2}|[1-9]\d|\d)$`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityIPSSignatureProfileParcelResource) 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 *PolicyObjectSecurityIPSSignatureProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityIPSSignature + + // 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 *PolicyObjectSecurityIPSSignatureProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityIPSSignature + + // 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 *PolicyObjectSecurityIPSSignatureProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityIPSSignature + + // 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 *PolicyObjectSecurityIPSSignatureProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityIPSSignature + + // 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 *PolicyObjectSecurityIPSSignatureProfileParcelResource) 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_security_ips_signature_test.go b/internal/provider/resource_sdwan_policy_object_security_ips_signature_test.go new file mode 100644 index 000000000..596fc1a47 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_ips_signature_test.go @@ -0,0 +1,81 @@ +// 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 TestAccSdwanPolicyObjectSecurityIPSSignatureProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_ips_signature.test", "entries.0.generator_id", "1234")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_ips_signature.test", "entries.0.signature_id", "5678")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityIPSSignaturePrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityIPSSignatureProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityIPSSignaturePrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityIPSSignatureProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_ips_signature" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` generator_id = "1234"` + "\n" + config += ` signature_id = "5678"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_local_application_list.go b/internal/provider/resource_sdwan_policy_object_security_local_application_list.go new file mode 100644 index 000000000..67e54c2bc --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_local_application_list.go @@ -0,0 +1,256 @@ +// 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 = &PolicyObjectSecurityLocalApplicationListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityLocalApplicationListProfileParcelResource{} + +func NewPolicyObjectSecurityLocalApplicationListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityLocalApplicationListProfileParcelResource{} +} + +type PolicyObjectSecurityLocalApplicationListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityLocalApplicationListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_local_application_list" +} + +func (r *PolicyObjectSecurityLocalApplicationListProfileParcelResource) 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 Security Local Application List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Localapp list").String, + Optional: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "app": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + }, + "app_family": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityLocalApplicationListProfileParcelResource) 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 *PolicyObjectSecurityLocalApplicationListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityLocalApplicationList + + // 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 *PolicyObjectSecurityLocalApplicationListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityLocalApplicationList + + // 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 *PolicyObjectSecurityLocalApplicationListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityLocalApplicationList + + // 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 *PolicyObjectSecurityLocalApplicationListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityLocalApplicationList + + // 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 *PolicyObjectSecurityLocalApplicationListProfileParcelResource) 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_security_local_application_list_test.go b/internal/provider/resource_sdwan_policy_object_security_local_application_list_test.go new file mode 100644 index 000000000..ecea7a89d --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_local_application_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityLocalApplicationListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_local_application_list.test", "entries.0.app", "audible-com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityLocalApplicationListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityLocalApplicationListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityLocalApplicationListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityLocalApplicationListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_local_application_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` app = "audible-com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_local_domain_list.go b/internal/provider/resource_sdwan_policy_object_security_local_domain_list.go new file mode 100644 index 000000000..5977b34aa --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_local_domain_list.go @@ -0,0 +1,259 @@ +// 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 = &PolicyObjectSecurityLocalDomainListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityLocalDomainListProfileParcelResource{} + +func NewPolicyObjectSecurityLocalDomainListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityLocalDomainListProfileParcelResource{} +} + +type PolicyObjectSecurityLocalDomainListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityLocalDomainListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_local_domain_list" +} + +func (r *PolicyObjectSecurityLocalDomainListProfileParcelResource) 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 Security Local Domain List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "local_domain": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 240), + stringvalidator.RegexMatches(regexp.MustCompile(`^[^*+].*`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityLocalDomainListProfileParcelResource) 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 *PolicyObjectSecurityLocalDomainListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityLocalDomainList + + // 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 *PolicyObjectSecurityLocalDomainListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityLocalDomainList + + // 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 *PolicyObjectSecurityLocalDomainListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityLocalDomainList + + // 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 *PolicyObjectSecurityLocalDomainListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityLocalDomainList + + // 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 *PolicyObjectSecurityLocalDomainListProfileParcelResource) 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_security_local_domain_list_test.go b/internal/provider/resource_sdwan_policy_object_security_local_domain_list_test.go new file mode 100644 index 000000000..53c372dfa --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_local_domain_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityLocalDomainListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_local_domain_list.test", "entries.0.local_domain", "hello.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityLocalDomainListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityLocalDomainListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityLocalDomainListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityLocalDomainListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_local_domain_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` local_domain = "hello.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_port_list.go b/internal/provider/resource_sdwan_policy_object_security_port_list.go new file mode 100644 index 000000000..81dc7594f --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_port_list.go @@ -0,0 +1,252 @@ +// 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 = &PolicyObjectSecurityPortListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityPortListProfileParcelResource{} + +func NewPolicyObjectSecurityPortListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityPortListProfileParcelResource{} +} + +type PolicyObjectSecurityPortListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityPortListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_port_list" +} + +func (r *PolicyObjectSecurityPortListProfileParcelResource) 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 Security Port List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Port List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "port": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("can be single port or port range").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityPortListProfileParcelResource) 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 *PolicyObjectSecurityPortListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityPortList + + // 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 *PolicyObjectSecurityPortListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityPortList + + // 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 *PolicyObjectSecurityPortListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityPortList + + // 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 *PolicyObjectSecurityPortListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityPortList + + // 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 *PolicyObjectSecurityPortListProfileParcelResource) 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_security_port_list_test.go b/internal/provider/resource_sdwan_policy_object_security_port_list_test.go new file mode 100644 index 000000000..a4c370a88 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_port_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityPortListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_port_list.test", "entries.0.port", "100")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityPortListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityPortListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityPortListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityPortListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_port_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` port = "100"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_scalable_group_tag_list.go b/internal/provider/resource_sdwan_policy_object_security_scalable_group_tag_list.go new file mode 100644 index 000000000..25e499a65 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_scalable_group_tag_list.go @@ -0,0 +1,264 @@ +// 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 = &PolicyObjectSecurityScalableGroupTagListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityScalableGroupTagListProfileParcelResource{} + +func NewPolicyObjectSecurityScalableGroupTagListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityScalableGroupTagListProfileParcelResource{} +} + +type PolicyObjectSecurityScalableGroupTagListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_scalable_group_tag_list" +} + +func (r *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) 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 Security Scalable Group Tag List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "sgt_name": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "tag": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityScalableGroupTagList + + // 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityScalableGroupTagList + + // 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityScalableGroupTagList + + // 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityScalableGroupTagList + + // 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 *PolicyObjectSecurityScalableGroupTagListProfileParcelResource) 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_security_scalable_group_tag_list_test.go b/internal/provider/resource_sdwan_policy_object_security_scalable_group_tag_list_test.go new file mode 100644 index 000000000..d89dcd525 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_scalable_group_tag_list_test.go @@ -0,0 +1,81 @@ +// 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 TestAccSdwanPolicyObjectSecurityScalableGroupTagListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_scalable_group_tag_list.test", "entries.0.sgt_name", "ANY")) + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_scalable_group_tag_list.test", "entries.0.tag", "65535")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityScalableGroupTagListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityScalableGroupTagListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityScalableGroupTagListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityScalableGroupTagListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_scalable_group_tag_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` sgt_name = "ANY"` + "\n" + config += ` tag = "65535"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_security_url_list.go b/internal/provider/resource_sdwan_policy_object_security_url_list.go new file mode 100644 index 000000000..bebe8cd20 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_url_list.go @@ -0,0 +1,259 @@ +// 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 = &PolicyObjectSecurityURLListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectSecurityURLListProfileParcelResource{} + +func NewPolicyObjectSecurityURLListProfileParcelResource() resource.Resource { + return &PolicyObjectSecurityURLListProfileParcelResource{} +} + +type PolicyObjectSecurityURLListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectSecurityURLListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_security_url_list" +} + +func (r *PolicyObjectSecurityURLListProfileParcelResource) 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 Security URL List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("URL List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "pattern": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("valid url pattern").String, + Optional: true, + Validators: []validator.String{ + stringvalidator.LengthBetween(1, 240), + stringvalidator.RegexMatches(regexp.MustCompile(`^[^*+].*`), ""), + }, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectSecurityURLListProfileParcelResource) 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 *PolicyObjectSecurityURLListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectSecurityURLList + + // 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 *PolicyObjectSecurityURLListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectSecurityURLList + + // 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 *PolicyObjectSecurityURLListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectSecurityURLList + + // 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 *PolicyObjectSecurityURLListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectSecurityURLList + + // 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 *PolicyObjectSecurityURLListProfileParcelResource) 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_security_url_list_test.go b/internal/provider/resource_sdwan_policy_object_security_url_list_test.go new file mode 100644 index 000000000..e27fdccd1 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_security_url_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectSecurityURLListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_security_url_list.test", "entries.0.pattern", "www.cisco.com")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectSecurityURLListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectSecurityURLListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectSecurityURLListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectSecurityURLListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_security_url_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` pattern = "www.cisco.com"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_standard_community_list.go b/internal/provider/resource_sdwan_policy_object_standard_community_list.go new file mode 100644 index 000000000..943a4fab3 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_standard_community_list.go @@ -0,0 +1,252 @@ +// 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 = &PolicyObjectStandardCommunityListProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectStandardCommunityListProfileParcelResource{} + +func NewPolicyObjectStandardCommunityListProfileParcelResource() resource.Resource { + return &PolicyObjectStandardCommunityListProfileParcelResource{} +} + +type PolicyObjectStandardCommunityListProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectStandardCommunityListProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_standard_community_list" +} + +func (r *PolicyObjectStandardCommunityListProfileParcelResource) 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 Standard Community List Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Standard Community List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "standard_community": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Standard Community").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectStandardCommunityListProfileParcelResource) 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 *PolicyObjectStandardCommunityListProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectStandardCommunityList + + // 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 *PolicyObjectStandardCommunityListProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectStandardCommunityList + + // 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 *PolicyObjectStandardCommunityListProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectStandardCommunityList + + // 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 *PolicyObjectStandardCommunityListProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectStandardCommunityList + + // 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 *PolicyObjectStandardCommunityListProfileParcelResource) 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_standard_community_list_test.go b/internal/provider/resource_sdwan_policy_object_standard_community_list_test.go new file mode 100644 index 000000000..61593f9d3 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_standard_community_list_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectStandardCommunityListProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_standard_community_list.test", "entries.0.standard_community", "1000:10000")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectStandardCommunityListPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectStandardCommunityListProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectStandardCommunityListPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectStandardCommunityListProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_standard_community_list" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` standard_community = "1000:10000"` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/internal/provider/resource_sdwan_policy_object_vpn_group.go b/internal/provider/resource_sdwan_policy_object_vpn_group.go new file mode 100644 index 000000000..52a9bf3ea --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_vpn_group.go @@ -0,0 +1,252 @@ +// 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 = &PolicyObjectVPNGroupProfileParcelResource{} +var _ resource.ResourceWithImportState = &PolicyObjectVPNGroupProfileParcelResource{} + +func NewPolicyObjectVPNGroupProfileParcelResource() resource.Resource { + return &PolicyObjectVPNGroupProfileParcelResource{} +} + +type PolicyObjectVPNGroupProfileParcelResource struct { + client *sdwan.Client + updateMutex *sync.Mutex +} + +func (r *PolicyObjectVPNGroupProfileParcelResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_policy_object_vpn_group" +} + +func (r *PolicyObjectVPNGroupProfileParcelResource) 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 VPN Group Policy_object.").AddMinimumVersionDescription("20.12.0").String, + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + MarkdownDescription: "The id of the Policy_object", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "version": schema.Int64Attribute{ + MarkdownDescription: "The version of the Policy_object", + Computed: true, + }, + "name": schema.StringAttribute{ + MarkdownDescription: "The name of the Policy_object", + Required: true, + }, + "description": schema.StringAttribute{ + MarkdownDescription: "The description of the Policy_object", + Optional: true, + }, + "feature_profile_id": schema.StringAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("Feature Profile ID").String, + Required: true, + }, + "entries": schema.ListNestedAttribute{ + MarkdownDescription: helpers.NewAttributeDescription("VPN List").String, + Required: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "vpn": schema.Int64Attribute{ + MarkdownDescription: helpers.NewAttributeDescription("can be single vpn id or vpn id range").String, + Optional: true, + }, + }, + }, + }, + }, + } +} + +func (r *PolicyObjectVPNGroupProfileParcelResource) 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 *PolicyObjectVPNGroupProfileParcelResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan PolicyObjectVPNGroup + + // 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 *PolicyObjectVPNGroupProfileParcelResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state PolicyObjectVPNGroup + + // 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 *PolicyObjectVPNGroupProfileParcelResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan, state PolicyObjectVPNGroup + + // 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 *PolicyObjectVPNGroupProfileParcelResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state PolicyObjectVPNGroup + + // 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 *PolicyObjectVPNGroupProfileParcelResource) 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_vpn_group_test.go b/internal/provider/resource_sdwan_policy_object_vpn_group_test.go new file mode 100644 index 000000000..48944c5c7 --- /dev/null +++ b/internal/provider/resource_sdwan_policy_object_vpn_group_test.go @@ -0,0 +1,79 @@ +// 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 TestAccSdwanPolicyObjectVPNGroupProfileParcel(t *testing.T) { + if os.Getenv("SDWAN_2012") == "" { + t.Skip("skipping test, set environment variable SDWAN_2012") + } + var checks []resource.TestCheckFunc + checks = append(checks, resource.TestCheckResourceAttr("sdwan_policy_object_vpn_group.test", "entries.0.vpn", "100")) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + + { + Config: testAccSdwanPolicyObjectVPNGroupPrerequisitesProfileParcelConfig + testAccSdwanPolicyObjectVPNGroupProfileParcelConfig_all(), + Check: resource.ComposeTestCheckFunc(checks...), + }, + }, + }) +} + +// End of section. //template:end testAcc + +// Section below is generated&owned by "gen/generator.go". //template:begin testPrerequisites +const testAccSdwanPolicyObjectVPNGroupPrerequisitesProfileParcelConfig = ` +resource "sdwan_policy_object_feature_profile" "test" { + name = "POLICY_OBJECT_FP_1" + description = "My policy object feature profile 1" +} +` + +// End of section. //template:end testPrerequisites + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigMinimum + +// End of section. //template:end testAccConfigMinimum + +// Section below is generated&owned by "gen/generator.go". //template:begin testAccConfigAll +func testAccSdwanPolicyObjectVPNGroupProfileParcelConfig_all() string { + config := `resource "sdwan_policy_object_vpn_group" "test" {` + "\n" + config += ` name = "TF_TEST_ALL"` + "\n" + config += ` description = "Terraform integration test"` + "\n" + config += ` feature_profile_id = sdwan_policy_object_feature_profile.test.id` + "\n" + config += ` entries = [{` + "\n" + config += ` vpn = 100` + "\n" + config += ` }]` + "\n" + config += `}` + "\n" + return config +} + +// End of section. //template:end testAccConfigAll diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index aed0b4675..aa381ced9 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -11,6 +11,21 @@ description: |- - Add `sdwan_policy_object_application_list` resource and data source - Add `sdwan_policy_object_sla_class_list` resource and data source +- Add `sdwan_policy_object_app_probe_class` resource and data source +- Add `sdwan_policy_object_as_path_list` resource and data source +- Add `sdwan_policy_object_vpn_group` resource and data source +- Add `sdwan_policy_object_security_data_ipv4_prefix_list` resource and data source +- Add `sdwan_policy_object_security_fqdn_list` resource and data source +- Add `sdwan_policy_object_security_geolocation_list` resource and data source +- Add `sdwan_policy_object_security_ips_signature` resource and data source +- Add `sdwan_policy_object_security_local_domain_list` resource and data source +- Add `sdwan_policy_object_security_port_list` resource and data source +- Add `sdwan_policy_object_security_scalable_group_tag_list` resource and data source +- Add `sdwan_policy_object_security_url_list` resource and data source +- Add `sdwan_policy_object_preferred_color_group` resource and data source +- Add `sdwan_policy_object_security_identity_list` resource and data source +- Add `sdwan_policy_object_security_local_application_list` resource and data source +- Add `sdwan_policy_object_standard_community_list` resource and data source ## 0.4.1