diff --git a/docs/data-sources/annotation.md b/docs/data-sources/annotation.md index eb9424eeb..75c405ff1 100644 --- a/docs/data-sources/annotation.md +++ b/docs/data-sources/annotation.md @@ -53,6 +53,7 @@ data "aci_annotation" "example_application_epg" { ### Required ### * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - Too many parent DNs to display, see model documentation for all possible parents of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview). - [aci_application_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/application_epg) ([fvAEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvAEPg/overview)) - [aci_vrf](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/vrf) ([fvCtx](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvCtx/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) @@ -68,12 +69,11 @@ data "aci_annotation" "example_application_epg" { - [aci_external_management_network_instance_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_instance_profile) ([mgmtInstP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtInstP/overview)) - [aci_relation_to_consumed_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_consumed_out_of_band_contract) ([mgmtRsOoBCons](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtRsOoBCons/overview)) - [aci_external_management_network_subnet](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_subnet) ([mgmtSubnet](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtSubnet/overview)) - - [aci_pim_route_map_entry](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_entry) ([pimRouteMapEntry](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapEntry/overview)) - - [aci_pim_route_map_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_policy) ([pimRouteMapPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapPol/overview)) - - [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview)) - - [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview)) - - [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview)) - - Too many classes to display, see model documentation for all possible classes of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview). + - [aci_netflow_exporter_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) ([netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)) + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) + - [aci_netflow_record_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_record_policy) ([netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)) + - [aci_relation_to_netflow_exporter](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_exporter) ([netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) + - [aci_relation_to_netflow_record](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_record) ([netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. ### Read-Only ### diff --git a/docs/data-sources/netflow_monitor_policy.md b/docs/data-sources/netflow_monitor_policy.md new file mode 100644 index 000000000..78b8ac47f --- /dev/null +++ b/docs/data-sources/netflow_monitor_policy.md @@ -0,0 +1,79 @@ +--- +# Documentation generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). +subcategory: "Tenant Policies" +layout: "aci" +page_title: "ACI: aci_netflow_monitor_policy" +sidebar_current: "docs-aci-data-source-aci_netflow_monitor_policy" +description: |- + Data source for Netflow Monitor Policy +--- + +# aci_netflow_monitor_policy # + +Data source for Netflow Monitor Policy + +## API Information ## + +* Class: [netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview) + + +* Distinguished Name Formats: + - `uni/infra/monitorpol-{name}` + - `uni/tn-{name}/monitorpol-{name}` + +## GUI Information ## + +* Locations: + - `Tenants -> Policies -> NetFlow -> NetFlow Monitors` + - `Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors` + +## Example Usage ## + +```hcl + +data "aci_netflow_monitor_policy" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "netfow_monitor" +} + +``` + +## Schema ## + +### Required ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/tenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview)) + - The distinquised name (DN) of classes below can be used but currently there is no available resource for it: + - [infraInfra](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraInfra/overview) + + - Default: `uni/infra` + +* `name` (name) - (string) The name of the Netflow Monitor Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Netflow Monitor Policy object. +* `annotation` (annotation) - (string) The annotation of the Netflow Monitor Policy object. +* `description` (descr) - (string) The description of the Netflow Monitor Policy object. +* `name_alias` (nameAlias) - (string) The name alias of the Netflow Monitor Policy object. +* `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. +* `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. + +* `relation_to_netflow_exporters` - (list) A list of Relation To Netflow Exporters (ACI object [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) pointing to Netflow Exporter Policy (ACI Object [netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)). + * `annotation` (annotation) - (string) The annotation of the Relation To Netflow Exporter object. + * `netflow_exporter_policy_name` (tnNetflowExporterPolName) - (string) Name. + +* `relation_to_netflow_record` - (list) A list of Relation To Netflow Record (ACI object [netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) pointing to Netflow Record Policy (ACI Object [netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)). + * `annotation` (annotation) - (string) The annotation of the Relation To Netflow Record object. + * `netflow_record_policy_name` (tnNetflowRecordPolName) - (string) Name. + +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. diff --git a/docs/data-sources/relation_to_netflow_exporter.md b/docs/data-sources/relation_to_netflow_exporter.md new file mode 100644 index 000000000..9e4f25730 --- /dev/null +++ b/docs/data-sources/relation_to_netflow_exporter.md @@ -0,0 +1,62 @@ +--- +# Documentation generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). +subcategory: "Tenant Policies" +layout: "aci" +page_title: "ACI: aci_relation_to_netflow_exporter" +sidebar_current: "docs-aci-data-source-aci_relation_to_netflow_exporter" +description: |- + Data source for Relation To Netflow Exporter +--- + +# aci_relation_to_netflow_exporter # + +Data source for Relation To Netflow Exporter + +## API Information ## + +* Class: [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview) + + +* Distinguished Name Formats: + - `uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}` + - `uni/tn-{name}/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}` + +## GUI Information ## + +* Locations: + - `Tenants -> Policies -> NetFlow -> NetFlow Monitors` + - `Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors` + +## Example Usage ## + +```hcl + +data "aci_relation_to_netflow_exporter" "example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name +} + +``` + +## Schema ## + +### Required ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) +* `netflow_exporter_policy_name` (tnNetflowExporterPolName) - (string) Name. This attribute can be referenced from a [resource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) with `aci_netflow_exporter_policy.example.name` or from a [datasource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/data-sources/netflow_exporter_policy) with `data.aci_netflow_exporter_policy.example.name`. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Relation To Netflow Exporter object. +* `annotation` (annotation) - (string) The annotation of the Relation To Netflow Exporter object. + +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). This attribute is supported in ACI versions: 3.2(1l) and later. + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. diff --git a/docs/data-sources/tag.md b/docs/data-sources/tag.md index 17b078e92..bfb9287d0 100644 --- a/docs/data-sources/tag.md +++ b/docs/data-sources/tag.md @@ -53,6 +53,7 @@ data "aci_tag" "example_application_epg" { ### Required ### * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - Too many parent DNs to display, see model documentation for all possible parents of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview). - [aci_application_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/application_epg) ([fvAEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvAEPg/overview)) - [aci_vrf](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/vrf) ([fvCtx](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvCtx/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) @@ -68,12 +69,11 @@ data "aci_tag" "example_application_epg" { - [aci_external_management_network_instance_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_instance_profile) ([mgmtInstP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtInstP/overview)) - [aci_relation_to_consumed_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_consumed_out_of_band_contract) ([mgmtRsOoBCons](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtRsOoBCons/overview)) - [aci_external_management_network_subnet](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_subnet) ([mgmtSubnet](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtSubnet/overview)) - - [aci_pim_route_map_entry](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_entry) ([pimRouteMapEntry](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapEntry/overview)) - - [aci_pim_route_map_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_policy) ([pimRouteMapPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapPol/overview)) - - [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview)) - - [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview)) - - [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview)) - - Too many classes to display, see model documentation for all possible classes of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview). + - [aci_netflow_exporter_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) ([netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)) + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) + - [aci_netflow_record_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_record_policy) ([netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)) + - [aci_relation_to_netflow_exporter](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_exporter) ([netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) + - [aci_relation_to_netflow_record](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_record) ([netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. ### Read-Only ### diff --git a/docs/resources/annotation.md b/docs/resources/annotation.md index 9f4be718b..fb4a77695 100644 --- a/docs/resources/annotation.md +++ b/docs/resources/annotation.md @@ -62,6 +62,7 @@ All examples for the Annotation resource can be found in the [examples](https:// ### Required ### * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - Too many parent DNs to display, see model documentation for all possible parents of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview). - [aci_application_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/application_epg) ([fvAEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvAEPg/overview)) - [aci_vrf](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/vrf) ([fvCtx](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvCtx/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) @@ -77,12 +78,11 @@ All examples for the Annotation resource can be found in the [examples](https:// - [aci_external_management_network_instance_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_instance_profile) ([mgmtInstP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtInstP/overview)) - [aci_relation_to_consumed_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_consumed_out_of_band_contract) ([mgmtRsOoBCons](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtRsOoBCons/overview)) - [aci_external_management_network_subnet](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_subnet) ([mgmtSubnet](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtSubnet/overview)) - - [aci_pim_route_map_entry](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_entry) ([pimRouteMapEntry](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapEntry/overview)) - - [aci_pim_route_map_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_policy) ([pimRouteMapPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapPol/overview)) - - [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview)) - - [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview)) - - [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview)) - - Too many classes to display, see model documentation for all possible classes of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview). + - [aci_netflow_exporter_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) ([netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)) + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) + - [aci_netflow_record_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_record_policy) ([netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)) + - [aci_relation_to_netflow_exporter](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_exporter) ([netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) + - [aci_relation_to_netflow_record](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_record) ([netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. * `value` (value) - (string) The value of the property. diff --git a/docs/resources/netflow_monitor_policy.md b/docs/resources/netflow_monitor_policy.md new file mode 100644 index 000000000..b8fe7a861 --- /dev/null +++ b/docs/resources/netflow_monitor_policy.md @@ -0,0 +1,167 @@ +--- +# Documentation generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). +subcategory: "Tenant Policies" +layout: "aci" +page_title: "ACI: aci_netflow_monitor_policy" +sidebar_current: "docs-aci-resource-aci_netflow_monitor_policy" +description: |- + Manages ACI Netflow Monitor Policy +--- + +# aci_netflow_monitor_policy # + +Manages ACI Netflow Monitor Policy + + + +## API Information ## + +* Class: [netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview) + + +* Distinguished Name Formats: + - `uni/infra/monitorpol-{name}` + - `uni/tn-{name}/monitorpol-{name}` + +## GUI Information ## + +* Locations: + - `Tenants -> Policies -> NetFlow -> NetFlow Monitors` + - `Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors` + +## Example Usage ## + +The configuration snippet below creates a Netflow Monitor Policy with only required attributes. + +```hcl + +resource "aci_netflow_monitor_policy" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "netfow_monitor" +} + +``` +The configuration snippet below shows all possible attributes of the Netflow Monitor Policy. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_netflow_monitor_policy" "full_example_tenant" { + parent_dn = aci_tenant.example.id + annotation = "annotation" + description = "description" + name = "netfow_monitor" + name_alias = "name_alias" + owner_key = "owner_key" + owner_tag = "owner_tag" + relation_to_netflow_exporters = [ + { + annotation = "annotation_1" + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name + } + ] + relation_to_netflow_record = [ + { + annotation = "annotation_1" + netflow_record_policy_name = aci_netflow_record_policy.example.name + } + ] + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} + +``` + +All examples for the Netflow Monitor Policy resource can be found in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources/aci_netflow_monitor_policy) folder. + +## Schema ## + +### Required ### + +* `name` (name) - (string) The name of the Netflow Monitor Policy object. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Netflow Monitor Policy object. + +### Optional ### +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/tenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview)) + - The distinquised name (DN) of classes below can be used but currently there is no available resource for it: + - [infraInfra](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraInfra/overview) + + - Default: `uni/infra` + +* `annotation` (annotation) - (string) The annotation of the Netflow Monitor Policy object. + - Default: `orchestrator:terraform` +* `description` (descr) - (string) The description of the Netflow Monitor Policy object. +* `name_alias` (nameAlias) - (string) The name alias of the Netflow Monitor Policy object. +* `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. +* `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. + +* `relation_to_netflow_exporters` - (list) A list of Relation To Netflow Exporters (ACI object [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) pointing to Netflow Exporter Policy (ACI Object [netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)) which can be configured using the [aci_netflow_exporter_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) resource. + + #### Required #### + + * `netflow_exporter_policy_name` (tnNetflowExporterPolName) - (string) Name. This attribute can be referenced from a [resource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) with `aci_netflow_exporter_policy.example.name` or from a [datasource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/data-sources/netflow_exporter_policy) with `data.aci_netflow_exporter_policy.example.name`. + + #### Optional #### + + * `annotation` (annotation) - (string) The annotation of the Relation To Netflow Exporter object. + - Default: `orchestrator:terraform` + +* `relation_to_netflow_record` - (list) A list of Relation To Netflow Record (ACI object [netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) pointing to Netflow Record Policy (ACI Object [netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)) which can be configured using the [aci_netflow_record_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_record_policy) resource. + + #### Required #### + + + #### Optional #### + + * `annotation` (annotation) - (string) The annotation of the Relation To Netflow Record object. + - Default: `orchestrator:terraform` + * `netflow_record_policy_name` (tnNetflowRecordPolName) - (string) Name. + +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). Annotations can also be configured using a separate [aci_annotation](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/annotation) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). Tags can also be configured using a separate [aci_tag](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/tag) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +## Importing + +An existing Netflow Monitor Policy can be [imported](https://www.terraform.io/docs/import/index.html) into this resource with its distinguished name (DN), via the following command: + +``` +terraform import aci_netflow_monitor_policy.example_tenant uni/infra/monitorpol-{name} +``` + +Starting in Terraform version 1.5, an existing Netflow Monitor Policy can be imported +using [import blocks](https://developer.hashicorp.com/terraform/language/import) via the following configuration: + +``` +import { + id = "uni/infra/monitorpol-{name}" + to = aci_netflow_monitor_policy.example_tenant +} +``` diff --git a/docs/resources/relation_to_netflow_exporter.md b/docs/resources/relation_to_netflow_exporter.md new file mode 100644 index 000000000..4db430b13 --- /dev/null +++ b/docs/resources/relation_to_netflow_exporter.md @@ -0,0 +1,121 @@ +--- +# Documentation generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). +subcategory: "Tenant Policies" +layout: "aci" +page_title: "ACI: aci_relation_to_netflow_exporter" +sidebar_current: "docs-aci-resource-aci_relation_to_netflow_exporter" +description: |- + Manages ACI Relation To Netflow Exporter +--- + +# aci_relation_to_netflow_exporter # + +Manages ACI Relation To Netflow Exporter + + + +## API Information ## + +* Class: [netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview) + + +* Distinguished Name Formats: + - `uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}` + - `uni/tn-{name}/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}` + +## GUI Information ## + +* Locations: + - `Tenants -> Policies -> NetFlow -> NetFlow Monitors` + - `Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors` + +## Example Usage ## + +The configuration snippet below creates a Relation To Netflow Exporter with only required attributes. + +```hcl + +resource "aci_relation_to_netflow_exporter" "example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name +} + +``` +The configuration snippet below shows all possible attributes of the Relation To Netflow Exporter. + +!> This example might not be valid configuration and is only used to show all possible attributes. + +```hcl + +resource "aci_relation_to_netflow_exporter" "full_example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + annotation = "annotation" + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} + +``` + +All examples for the Relation To Netflow Exporter resource can be found in the [examples](https://github.com/CiscoDevNet/terraform-provider-aci/tree/master/examples/resources/aci_relation_to_netflow_exporter) folder. + +## Schema ## + +### Required ### + +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) +* `netflow_exporter_policy_name` (tnNetflowExporterPolName) - (string) Name. This attribute can be referenced from a [resource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) with `aci_netflow_exporter_policy.example.name` or from a [datasource](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/data-sources/netflow_exporter_policy) with `data.aci_netflow_exporter_policy.example.name`. + +### Read-Only ### + +* `id` - (string) The distinguished name (DN) of the Relation To Netflow Exporter object. + +### Optional ### + +* `annotation` (annotation) - (string) The annotation of the Relation To Netflow Exporter object. + - Default: `orchestrator:terraform` + +* `annotations` - (list) A list of Annotations (ACI object [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview)). Annotations can also be configured using a separate [aci_annotation](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/annotation) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +* `tags` - (list) A list of Tags (ACI object [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview)). Tags can also be configured using a separate [aci_tag](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/tag) resource. This attribute is supported in ACI versions: 3.2(1l) and later. + + #### Required #### + + * `key` (key) - (string) The key used to uniquely identify this configuration object. + * `value` (value) - (string) The value of the property. + +## Importing + +An existing Relation To Netflow Exporter can be [imported](https://www.terraform.io/docs/import/index.html) into this resource with its distinguished name (DN), via the following command: + +``` +terraform import aci_relation_to_netflow_exporter.example_netflow_monitor_policy uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName} +``` + +Starting in Terraform version 1.5, an existing Relation To Netflow Exporter can be imported +using [import blocks](https://developer.hashicorp.com/terraform/language/import) via the following configuration: + +``` +import { + id = "uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}" + to = aci_relation_to_netflow_exporter.example_netflow_monitor_policy +} +``` diff --git a/docs/resources/tag.md b/docs/resources/tag.md index 1cf431ae8..be1e2a63c 100644 --- a/docs/resources/tag.md +++ b/docs/resources/tag.md @@ -62,6 +62,7 @@ All examples for the Tag resource can be found in the [examples](https://github. ### Required ### * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + - Too many parent DNs to display, see model documentation for all possible parents of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview). - [aci_application_epg](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/application_epg) ([fvAEPg](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvAEPg/overview)) - [aci_vrf](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/vrf) ([fvCtx](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvCtx/overview)) - [aci_endpoint_tag_ip](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/endpoint_tag_ip) ([fvEpIpTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvEpIpTag/overview)) @@ -77,12 +78,11 @@ All examples for the Tag resource can be found in the [examples](https://github. - [aci_external_management_network_instance_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_instance_profile) ([mgmtInstP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtInstP/overview)) - [aci_relation_to_consumed_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_consumed_out_of_band_contract) ([mgmtRsOoBCons](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtRsOoBCons/overview)) - [aci_external_management_network_subnet](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/external_management_network_subnet) ([mgmtSubnet](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/mgmtSubnet/overview)) - - [aci_pim_route_map_entry](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_entry) ([pimRouteMapEntry](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapEntry/overview)) - - [aci_pim_route_map_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/pim_route_map_policy) ([pimRouteMapPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/pimRouteMapPol/overview)) - - [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview)) - - [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview)) - - [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview)) - - Too many classes to display, see model documentation for all possible classes of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview). + - [aci_netflow_exporter_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_exporter_policy) ([netflowExporterPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowExporterPol/overview)) + - [aci_netflow_monitor_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_monitor_policy) ([netflowMonitorPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowMonitorPol/overview)) + - [aci_netflow_record_policy](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/netflow_record_policy) ([netflowRecordPol](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRecordPol/overview)) + - [aci_relation_to_netflow_exporter](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_exporter) ([netflowRsMonitorToExporter](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToExporter/overview)) + - [aci_relation_to_netflow_record](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/relation_to_netflow_record) ([netflowRsMonitorToRecord](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/netflowRsMonitorToRecord/overview)) * `key` (key) - (string) The key used to uniquely identify this configuration object. * `value` (value) - (string) The value of the property. diff --git a/examples/data-sources/aci_netflow_monitor_policy/data-source.tf b/examples/data-sources/aci_netflow_monitor_policy/data-source.tf new file mode 100644 index 000000000..3efd6e062 --- /dev/null +++ b/examples/data-sources/aci_netflow_monitor_policy/data-source.tf @@ -0,0 +1,5 @@ + +data "aci_netflow_monitor_policy" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "netfow_monitor" +} diff --git a/examples/data-sources/aci_netflow_monitor_policy/provider.tf b/examples/data-sources/aci_netflow_monitor_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/data-sources/aci_netflow_monitor_policy/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/data-sources/aci_relation_to_netflow_exporter/data-source.tf b/examples/data-sources/aci_relation_to_netflow_exporter/data-source.tf new file mode 100644 index 000000000..0e208949f --- /dev/null +++ b/examples/data-sources/aci_relation_to_netflow_exporter/data-source.tf @@ -0,0 +1,5 @@ + +data "aci_relation_to_netflow_exporter" "example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name +} diff --git a/examples/data-sources/aci_relation_to_netflow_exporter/provider.tf b/examples/data-sources/aci_relation_to_netflow_exporter/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/data-sources/aci_relation_to_netflow_exporter/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/resources/aci_netflow_monitor_policy/provider.tf b/examples/resources/aci_netflow_monitor_policy/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/resources/aci_netflow_monitor_policy/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/resources/aci_netflow_monitor_policy/resource-all-attributes.tf b/examples/resources/aci_netflow_monitor_policy/resource-all-attributes.tf new file mode 100644 index 000000000..158294f40 --- /dev/null +++ b/examples/resources/aci_netflow_monitor_policy/resource-all-attributes.tf @@ -0,0 +1,34 @@ + +resource "aci_netflow_monitor_policy" "full_example_tenant" { + parent_dn = aci_tenant.example.id + annotation = "annotation" + description = "description" + name = "netfow_monitor" + name_alias = "name_alias" + owner_key = "owner_key" + owner_tag = "owner_tag" + relation_to_netflow_exporters = [ + { + annotation = "annotation_1" + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name + } + ] + relation_to_netflow_record = [ + { + annotation = "annotation_1" + netflow_record_policy_name = aci_netflow_record_policy.example.name + } + ] + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} diff --git a/examples/resources/aci_netflow_monitor_policy/resource.tf b/examples/resources/aci_netflow_monitor_policy/resource.tf new file mode 100644 index 000000000..333fe8654 --- /dev/null +++ b/examples/resources/aci_netflow_monitor_policy/resource.tf @@ -0,0 +1,5 @@ + +resource "aci_netflow_monitor_policy" "example_tenant" { + parent_dn = aci_tenant.example.id + name = "netfow_monitor" +} diff --git a/examples/resources/aci_relation_to_netflow_exporter/provider.tf b/examples/resources/aci_relation_to_netflow_exporter/provider.tf new file mode 100644 index 000000000..975fca093 --- /dev/null +++ b/examples/resources/aci_relation_to_netflow_exporter/provider.tf @@ -0,0 +1,14 @@ +terraform { + required_providers { + aci = { + source = "ciscodevnet/aci" + } + } +} + +provider "aci" { + username = "" + password = "" + url = "" + insecure = true +} \ No newline at end of file diff --git a/examples/resources/aci_relation_to_netflow_exporter/resource-all-attributes.tf b/examples/resources/aci_relation_to_netflow_exporter/resource-all-attributes.tf new file mode 100644 index 000000000..d1063afa9 --- /dev/null +++ b/examples/resources/aci_relation_to_netflow_exporter/resource-all-attributes.tf @@ -0,0 +1,18 @@ + +resource "aci_relation_to_netflow_exporter" "full_example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + annotation = "annotation" + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name + annotations = [ + { + key = "key_0" + value = "value_1" + } + ] + tags = [ + { + key = "key_0" + value = "value_1" + } + ] +} diff --git a/examples/resources/aci_relation_to_netflow_exporter/resource.tf b/examples/resources/aci_relation_to_netflow_exporter/resource.tf new file mode 100644 index 000000000..1d7119e3f --- /dev/null +++ b/examples/resources/aci_relation_to_netflow_exporter/resource.tf @@ -0,0 +1,5 @@ + +resource "aci_relation_to_netflow_exporter" "example_netflow_monitor_policy" { + parent_dn = aci_netflow_monitor_policy.example.id + netflow_exporter_policy_name = aci_netflow_exporter_policy.example.name +} diff --git a/gen/definitions/classes.yaml b/gen/definitions/classes.yaml index 462ca67ca..be2acf0e5 100644 --- a/gen/definitions/classes.yaml +++ b/gen/definitions/classes.yaml @@ -164,3 +164,38 @@ l3extProvLbl: ui_locations: - "Tenants (infra) -> Networking -> L3Outs -> Policy -> Main -> Provider Label" sub_category: "L3Out" + +netflowMonitorPol: + resource_name: "netflow_monitor_policy" + ui_locations: + - "Tenants -> Policies -> NetFlow -> NetFlow Monitors" + - "Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors" + sub_category: "Tenant Policies" + +netflowRsMonitorToRecord: + resource_name: "relation_to_netflow_record" + ui_locations: + - "Tenants -> Policies -> NetFlow -> NetFlow Monitors" + - "Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors" + sub_category: "Tenant Policies" + +netflowRsMonitorToExporter: + resource_name: "relation_to_netflow_exporter" + ui_locations: + - "Tenants -> Policies -> NetFlow -> NetFlow Monitors" + - "Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Monitors" + sub_category: "Tenant Policies" + +netflowExporterPol: + resource_name: "netflow_exporter_policy" + ui_locations: + - "Tenants -> Policies -> NetFlow -> NetFlow Exporters" + - "Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Exporters" + sub_category: "Tenant Policies" + +netflowRecordPol: + resource_name: "netflow_record_policy" + ui_locations: + - "Tenants -> Policies -> NetFlow -> NetFlow Records" + - "Fabric -> Access Policies -> Policies -> Interface -> NetFlow -> NetFlow Records" + sub_category: "Tenant Policies" diff --git a/gen/definitions/properties.yaml b/gen/definitions/properties.yaml index ec4edb1d2..6bf424f67 100644 --- a/gen/definitions/properties.yaml +++ b/gen/definitions/properties.yaml @@ -233,3 +233,29 @@ l3extProvLbl: parent_dependency_name: "infra" parent_dn: "aci_l3_outside.test.id" class_in_parent: false + +netflowMonitorPol: + default_values: + parent_dn: "uni/infra" + test_values: + default: + name: "netfow_monitor_default" + resource_required: + name: "netfow_monitor" + datasource_required: + name: "netfow_monitor" + datasource_non_existing: + name: "netfow_monitor_non_existing" + parents: + - class_name: "infraInfra" + parent_dependency: "" + parent_dn: "uni/infra" + - class_name: "fvTenant" + parent_dependency: "" + parent_dn: "aci_tenant.test.id" + +netflowRsMonitorToExporter: + parents: + - class_name: "netflowMonitorPol" + parent_dependency: "fvTenant" + parent_dn: "aci_netlfow_monitor_policy.test.id" diff --git a/gen/generator.go b/gen/generator.go index b4d42d946..ba1228518 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -44,6 +44,7 @@ import ( "reflect" "regexp" "sort" + "strconv" "strings" "text/template" "unicode" @@ -88,6 +89,7 @@ var templateFuncs = template.FuncMap{ "createNonExistingValue": func(val string) string { return fmt.Sprintf("non_existing_%s", val) }, "getParentTestDependencies": GetParentTestDependencies, "getTargetTestDependencies": GetTargetTestDependencies, + "getDefaultValues": GetDefaultValues, "fromInterfacesToString": FromInterfacesToString, "containsNoneAttributeValue": ContainsNoneAttributeValue, "definedInMap": DefinedInMap, @@ -1114,14 +1116,19 @@ func (m *Model) SetClassProperties(classDetails interface{}) { } } - val, ok = propertyValue.(map[string]interface{})["default"] - if ok { - if reflect.TypeOf(val).String() == "string" { - property.DefaultValue = val.(string) - } else if reflect.TypeOf(val).String() == "float64" { - property.DefaultValue = fmt.Sprintf("%f", val.(float64)) - } else { - log.Fatal(fmt.Sprintf("Reflect type %s not not defined. Define in SetClassProperties function.", reflect.TypeOf(val).String())) + defaultValueOverwrite := GetDefaultValues(m.PkgName, propertyName, m.Definitions) + if defaultValueOverwrite != "" { + property.DefaultValue = defaultValueOverwrite + } else { + val, ok = propertyValue.(map[string]interface{})["default"] + if ok { + if reflect.TypeOf(val).String() == "string" { + property.DefaultValue = val.(string) + } else if reflect.TypeOf(val).String() == "float64" { + property.DefaultValue = fmt.Sprintf("%f", val.(float64)) + } else { + log.Fatal(fmt.Sprintf("Reflect type %s not defined. Define in SetClassProperties function.", reflect.TypeOf(val).String())) + } } } @@ -1491,7 +1498,7 @@ func setDocumentationData(m *Model, definitions Definitions) { } } - if len(resourcesNotFound) != 0 { + if len(resourcesNotFound) != 0 && len(resourcesFound) < docsParentDnAmount { if len(resourcesNotFound) > docsParentDnAmount-len(resourcesFound) { // TODO catch default classes and add to documentation resourcesNotFound = resourcesNotFound[0:(docsParentDnAmount - len(resourcesFound))] @@ -1507,7 +1514,7 @@ func setDocumentationData(m *Model, definitions Definitions) { // TODO add overwrite to provide which documentation examples to be included docsExampleAmount := m.Configuration["docs_examples_amount"].(int) - if len(m.ContainedBy) >= docsExampleAmount { + if len(m.ContainedBy) > docsExampleAmount { overwriteExampleClasses := GetOverwriteExampleClasses(m.PkgName, definitions) if len(overwriteExampleClasses) > 0 { for _, exampleClass := range overwriteExampleClasses { @@ -1574,3 +1581,34 @@ func GetClassConfiguration(classPkgName string, definitions Definitions) map[str } return classConfiguration } + +/* +Determine if a attribute default value in terraform configuration should be overwritten/or defined by a attribute default value overwrite in the properties.yaml file. +It can be assigned to "parent_dn". +Precendence order is: + 1. class level from properties.yaml + 2. global level from properties.yaml + 3. meta data property default value +*/ +func GetDefaultValues(classPkgName, propertyName string, definitions Definitions) string { + precedenceList := []string{classPkgName, "global"} + for _, precedence := range precedenceList { + if classDetails, ok := definitions.Properties[precedence]; ok { + for key, value := range classDetails.(map[interface{}]interface{}) { + if key.(string) == "default_values" { + for k, v := range value.(map[interface{}]interface{}) { + if k.(string) == propertyName { + switch v := v.(type) { + case string: + return v + case float64: + return strconv.FormatFloat(v, 'f', -1, 64) + } + } + } + } + } + } + } + return "" +} diff --git a/gen/meta/netflowMonitorPol.json b/gen/meta/netflowMonitorPol.json new file mode 100644 index 000000000..246acbb62 --- /dev/null +++ b/gen/meta/netflowMonitorPol.json @@ -0,0 +1,716 @@ +{ + "netflow:MonitorPol": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Delegate": "", + "health:Inst": "", + "netflow:RsMonitorToExporter": "", + "netflow:RsMonitorToRecord": "", + "netflow:RtBDToNetflowMonitorPol": "", + "netflow:RtCeMonitorPolCons": "", + "netflow:RtIpv4MonitorPolCons": "", + "netflow:RtIpv6MonitorPolCons": "", + "netflow:RtLIfPToNetflowMonitorPol": "", + "netflow:RtNetflowMonitorPol": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fd-": "fault:Delegate", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "rbacDom-": "aaa:RbacAnnotation", + "rsmonitorToExporter-": "netflow:RsMonitorToExporter", + "rsmonitorToRecord": "netflow:RsMonitorToRecord", + "rtfvBDToNetflowMonitorPol-": "netflow:RtBDToNetflowMonitorPol", + "rtinfraNetflowMonitorPol-": "netflow:RtNetflowMonitorPol", + "rtl1CeMonitorPolCons-": "netflow:RtCeMonitorPolCons", + "rtl1Ipv4MonitorPolCons-": "netflow:RtIpv4MonitorPolCons", + "rtl1Ipv6MonitorPolCons-": "netflow:RtIpv6MonitorPolCons", + "rtl3extLIfPToNetflowMonitorPol-": "netflow:RtLIfPToNetflowMonitorPol", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "name" + ], + "rnFormat": "monitorpol-{name}", + "containedBy": { + "fv:Tenant": "", + "infra:Infra": "" + }, + "superClasses": [ + "netflow:AMonitorPol", + "fabric:L2IfPol", + "fabric:ProtoIfPol", + "fabric:ProtoPol", + "pol:Def", + "pol:Obj", + "naming:NamedObject" + ], + "subClasses": { + + }, + "relationFrom": { + "netflow:RtBDToNetflowMonitorPol": "fv:ABDPol", + "netflow:RtCeMonitorPolCons": "l1:EthIf", + "netflow:RtIpv4MonitorPolCons": "l1:EthIf", + "netflow:RtIpv6MonitorPolCons": "l1:EthIf", + "netflow:RtLIfPToNetflowMonitorPol": "l3ext:LIfP", + "netflow:RtNetflowMonitorPol": "infra:AccGrp" + }, + "relationTo": { + "netflow:RsMonitorToExporter": "netflow:ExporterPol", + "netflow:RsMonitorToRecord": "netflow:RecordPol" + }, + "dnFormats": [ + "uni/infra/monitorpol-{name}", + "uni/tn-{name}/monitorpol-{name}" + ], + "writeAccess": [ + "admin" + ], + "readAccess": [ + "access-connectivity", + "admin", + "tenant-connectivity", + "tenant-ext-connectivity" + ], + "faults": { + + }, + "events": { + "E4212704": "creation||netflow:MonitorPol", + "E4212705": "modification||netflow:MonitorPol", + "E4212706": "deletion||netflow:MonitorPol" + }, + "stats": { + + }, + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": false, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "logical", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + + ], + "classId": "9213", + "className": "MonitorPol", + "classPkg": "netflow", + "featureTag": "", + "moCategory": "Regular", + "label": "NetFlow Monitor", + "properties": { + "annotation": { + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38548", + "propLocalId": "8719", + "label": "Annotation", + "baseType": "string:Basic", + "modelType": "mo:Annotation", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "childAction": { + "comment": [ + "Delete or ignore. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "4", + "propLocalId": "5", + "label": "childAction", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationChildAction", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "16384", "localName": "deleteAll", + "platformFlavors": [ + + ], + "label": "deleteAll "}, + { "value": "8192", "localName": "deleteNonPresent", + "platformFlavors": [ + + ], + "label": "deleteNonPresent "}, + { "value": "4096", "localName": "ignore", + "platformFlavors": [ + + ], + "label": "ignore "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "descr": { + "comment": [ + "Specifies a description of the policy definition." + ], + "isConfigurable": true, + "propGlobalId": "5579", + "propLocalId": "28", + "label": "Description", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": true, + "likeProp": "naming:Described:descr", + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "dn": { + "comment": [ + "A tag or metadata is a non-hierarchical keyword or term assigned to the fabric module." + ], + "isConfigurable": false, + "propGlobalId": "1", + "propLocalId": "2", + "label": "dn", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "40687", + "propLocalId": "8023", + "label": "Managed By", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ExtMngdByType", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "undefined", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "msc", + "platformFlavors": [ + + ], + "label": "msc "}, + { "value": "0", "localName": "undefined", + "platformFlavors": [ + + ], + "label": "undefined "} + ], + "default": "undefined", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "lcOwn": { + "comment": [ + "A value that indicates how this object was created. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "9", + "propLocalId": "9", + "label": "lcOwn", + "baseType": "scalar:Enum8", + "modelType": "mo:Owner", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "local", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "4", "localName": "implicit", + "platformFlavors": [ + + ], + "label": "Implicit "}, + { "value": "0", "localName": "local", + "platformFlavors": [ + + ], + "label": "Local "}, + { "value": "1", "localName": "policy", + "platformFlavors": [ + + ], + "label": "Policy "}, + { "value": "2", "localName": "replica", + "platformFlavors": [ + + ], + "label": "Replica "}, + { "value": "3", "localName": "resolveOnBehalf", + "platformFlavors": [ + + ], + "label": "ResolvedOnBehalf "} + ], + "default": "local", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "modTs": { + "comment": [ + "The time when this object was last modified." + ], + "isConfigurable": false, + "propGlobalId": "7", + "propLocalId": "7", + "label": "modTs", + "baseType": "scalar:Date", + "modelType": "mo:TStamp", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "never", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "never", + "platformFlavors": [ + + ], + "label": "never "} + ], + "default": "never", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "monPolDn": { + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "27391", + "propLocalId": "228", + "label": "Monitoring policy", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "name": { + "comment": [ + "The name of the object." + ], + "isConfigurable": true, + "propGlobalId": "27340", + "propLocalId": "13", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": false, + "readOnly": false, + "isNaming": true, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validators": [ + {"min" : 1, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "nameAlias": { + "isConfigurable": true, + "propGlobalId": "28417", + "propLocalId": "6719", + "label": "Display Name", + "baseType": "string:Basic", + "modelType": "naming:NameAlias", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 63, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "ownerKey": { + "comment": [ + "The key for enabling clients to own their data for entity correlation." + ], + "isConfigurable": true, + "propGlobalId": "15230", + "propLocalId": "4100", + "label": "ownerKey", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "ownerTag": { + "comment": [ + "A tag for enabling clients to add their own data. For example, to indicate who created this object." + ], + "isConfigurable": true, + "propGlobalId": "15231", + "propLocalId": "4101", + "label": "ownerTag", + "baseType": "string:Basic", + "modelType": "naming:Descr", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9\\\\!#$%()*,-./:;@ _{|}~?&+]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "rn": { + "comment": [ + "Identifies an object from its siblings within the context of its parent object. The distinguished name contains a sequence of relative names." + ], + "isConfigurable": false, + "propGlobalId": "2", + "propLocalId": "3", + "label": "rn", + "baseType": "reference:BinRN", + "modelType": "reference:BinRN", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "status": { + "comment": [ + "The upgrade status. This property is for internal use only." + ], + "isConfigurable": false, + "propGlobalId": "3", + "propLocalId": "4", + "label": "status", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationStatus", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "created", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be created. An error is returned if the object already exists. \nIn the return value of a setter method: indicates that an object has been created. \n" + ], + "label": "created "}, + { "value": "8", "localName": "deleted", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be deleted. \nIn the return value of a setter method: indicates that an object has been deleted.\n" + ], + "label": "deleted "}, + { "value": "4", "localName": "modified", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be modified \nIn the return value of a setter method: indicates that an object has been modified.\n" + ], + "label": "modified "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "uid": { + "comment": [ + "A unique identifier for this object." + ], + "isConfigurable": false, + "propGlobalId": "8", + "propLocalId": "8", + "label": "uid", + "baseType": "scalar:Uint16", + "modelType": "scalar:Uint16", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "userdom": { + "isConfigurable": true, + "propGlobalId": "60657", + "propLocalId": "13244", + "label": "userdom", + "baseType": "string:Basic", + "modelType": "mo:UserDomType", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 1024, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "validValues": [ + { "value": "all", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "all", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + } + } + } +} \ No newline at end of file diff --git a/gen/meta/netflowRsMonitorToExporter.json b/gen/meta/netflowRsMonitorToExporter.json new file mode 100644 index 000000000..ae50d31f1 --- /dev/null +++ b/gen/meta/netflowRsMonitorToExporter.json @@ -0,0 +1,959 @@ +{ + "netflow:RsMonitorToExporter": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Inst": "", + "health:Inst": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fault-": "fault:Inst", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "rbacDom-": "aaa:RbacAnnotation", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + "tnNetflowExporterPolName" + ], + "rnFormat": "rsmonitorToExporter-{tnNetflowExporterPolName}", + "containedBy": { + "netflow:MonitorPol": "" + }, + "superClasses": [ + "netflow:ARsMonitorToExporter", + "pol:NToRef", + "reln:To", + "reln:Inst" + ], + "subClasses": { + + }, + "relationInfo": { + "type": "named", + "cardinality": "n-to-m", + "fromMo": "netflow:MonitorPol", + "fromRelMo": "netflow:RsMonitorToExporter", + "toMo": "netflow:ExporterPol", + "toRelMo": "netflow:RtMonitorToExporter", + "enforceable": true, + "resolvable": true + }, + "dnFormats": [ + "uni/infra/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}", + "uni/tn-{name}/monitorpol-{name}/rsmonitorToExporter-{tnNetflowExporterPolName}" + ], + "writeAccess": [ + "admin" + ], + "readAccess": [ + "admin" + ], + "faults": { + "F2474": "fltNetflowRsMonitorToExporterResolveFail" + }, + "events": { + "E4212710": "creation||netflow:RsMonitorToExporter", + "E4212711": "modification||netflow:RsMonitorToExporter", + "E4212712": "deletion||netflow:RsMonitorToExporter" + }, + "stats": { + + }, + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": true, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "regular", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "always", + "platformFlavors": [ + + ], + "classId": "9216", + "className": "RsMonitorToExporter", + "classPkg": "netflow", + "featureTag": "", + "moCategory": "RelationshipToLocal", + "label": "Exporter Policy Attachment", + "properties": { + "annotation": { + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38550", + "propLocalId": "8719", + "label": "Annotation", + "baseType": "string:Basic", + "modelType": "mo:Annotation", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "childAction": { + "comment": [ + "Delete or ignore. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "4", + "propLocalId": "5", + "label": "childAction", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationChildAction", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "16384", "localName": "deleteAll", + "platformFlavors": [ + + ], + "label": "deleteAll "}, + { "value": "8192", "localName": "deleteNonPresent", + "platformFlavors": [ + + ], + "label": "deleteNonPresent "}, + { "value": "4096", "localName": "ignore", + "platformFlavors": [ + + ], + "label": "ignore "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "dn": { + "comment": [ + "A tag or metadata is a non-hierarchical keyword or term assigned to the fabric module." + ], + "isConfigurable": false, + "propGlobalId": "1", + "propLocalId": "2", + "label": "dn", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "40689", + "propLocalId": "8023", + "label": "Managed By", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ExtMngdByType", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "undefined", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "msc", + "platformFlavors": [ + + ], + "label": "msc "}, + { "value": "0", "localName": "undefined", + "platformFlavors": [ + + ], + "label": "undefined "} + ], + "default": "undefined", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "forceResolve": { + "comment": [ + "Whether the relation should force pull the target." + ], + "isConfigurable": false, + "propGlobalId": "107", + "propLocalId": "83", + "label": "forceResolve", + "baseType": "scalar:Bool", + "modelType": "scalar:Bool", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "true", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "false", "localName": "no", + "platformFlavors": [ + + ], + "label": "No "}, + { "value": "true", "localName": "yes", + "platformFlavors": [ + + ], + "label": "Yes "} + ], + "default": "yes", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "lcOwn": { + "comment": [ + "A value that indicates how this object was created. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "9", + "propLocalId": "9", + "label": "lcOwn", + "baseType": "scalar:Enum8", + "modelType": "mo:Owner", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "local", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "4", "localName": "implicit", + "platformFlavors": [ + + ], + "label": "Implicit "}, + { "value": "0", "localName": "local", + "platformFlavors": [ + + ], + "label": "Local "}, + { "value": "1", "localName": "policy", + "platformFlavors": [ + + ], + "label": "Policy "}, + { "value": "2", "localName": "replica", + "platformFlavors": [ + + ], + "label": "Replica "}, + { "value": "3", "localName": "resolveOnBehalf", + "platformFlavors": [ + + ], + "label": "ResolvedOnBehalf "} + ], + "default": "local", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "modTs": { + "comment": [ + "The time when this object was last modified." + ], + "isConfigurable": false, + "propGlobalId": "7", + "propLocalId": "7", + "label": "modTs", + "baseType": "scalar:Date", + "modelType": "mo:TStamp", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "never", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "never", + "platformFlavors": [ + + ], + "label": "never "} + ], + "default": "never", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "monPolDn": { + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "27393", + "propLocalId": "228", + "label": "Monitoring policy", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "rType": { + "comment": [ + "Represents the type of resolver." + ], + "isConfigurable": false, + "propGlobalId": "106", + "propLocalId": "82", + "label": "rType", + "baseType": "scalar:Enum8", + "modelType": "reln:ResolverType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "mo", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "3", "localName": "local", + "platformFlavors": [ + + ], + "label": "local "}, + { "value": "1", "localName": "mo", + "platformFlavors": [ + + ], + "label": "mo "}, + { "value": "2", "localName": "service", + "platformFlavors": [ + + ], + "label": "service "} + ], + "default": "mo", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "rn": { + "comment": [ + "Identifies an object from its siblings within the context of its parent object. The distinguished name contains a sequence of relative names." + ], + "isConfigurable": false, + "propGlobalId": "2", + "propLocalId": "3", + "label": "rn", + "baseType": "reference:BinRN", + "modelType": "reference:BinRN", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "state": { + "comment": [ + "Represents the state of the relationship." + ], + "isConfigurable": false, + "propGlobalId": "103", + "propLocalId": "26", + "label": "State", + "baseType": "scalar:Enum8", + "modelType": "reln:State", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "5", "localName": "cardinality-violation", + "platformFlavors": [ + + ], + "comment": [ + "cardinality violation - When relations are created such that\n they violate the cardinality, state of the relation would be\n set to this." + ], + "label": "cardinality-violation "}, + { "value": "unformed", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "formed", + "platformFlavors": [ + + ], + "comment": [ + "the relationship is formed with the target object" + ], + "label": "formed "}, + { "value": "4", "localName": "invalid-target", + "platformFlavors": [ + + ], + "comment": [ + "invalid target DN" + ], + "label": "invalid-target "}, + { "value": "2", "localName": "missing-target", + "platformFlavors": [ + + ], + "comment": [ + "target does not exist" + ], + "label": "missing-target "}, + { "value": "0", "localName": "unformed", + "platformFlavors": [ + + ], + "comment": [ + "the relationship is not formed" + ], + "label": "unformed "} + ], + "default": "unformed", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "stateQual": { + "comment": [ + "Represents the state qualifier of the relationship." + ], + "isConfigurable": false, + "propGlobalId": "104", + "propLocalId": "80", + "label": "State Qualifier", + "baseType": "scalar:Enum8", + "modelType": "reln:StateQual", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "default-target", + "platformFlavors": [ + + ], + "comment": [ + "target not specified, using default" + ], + "label": "default-target "}, + { "value": "none", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "mismatch-target", + "platformFlavors": [ + + ], + "comment": [ + "target not found, using default" + ], + "label": "mismatch-target "}, + { "value": "0", "localName": "none", + "platformFlavors": [ + + ], + "comment": [ + "no issue" + ], + "label": "none "} + ], + "default": "none", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "status": { + "comment": [ + "The upgrade status. This property is for internal use only." + ], + "isConfigurable": false, + "propGlobalId": "3", + "propLocalId": "4", + "label": "status", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationStatus", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "created", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be created. An error is returned if the object already exists. \nIn the return value of a setter method: indicates that an object has been created. \n" + ], + "label": "created "}, + { "value": "8", "localName": "deleted", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be deleted. \nIn the return value of a setter method: indicates that an object has been deleted.\n" + ], + "label": "deleted "}, + { "value": "4", "localName": "modified", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be modified \nIn the return value of a setter method: indicates that an object has been modified.\n" + ], + "label": "modified "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tCl": { + "comment": [ + "The class ID of the target object. This property is managed internally and should not be modified by the user." + ], + "isConfigurable": false, + "propGlobalId": "27372", + "propLocalId": "78", + "label": "Target-class", + "baseType": "scalar:Enum16", + "modelType": "reln:ClassId", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validValues": [ + { "value": "9207", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "9207", "localName": "netflowExporterPol", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "unspecified", + "platformFlavors": [ + + ], + "label": "unspecified "} + ], + "default": "netflowExporterPol", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tContextDn": { + "comment": [ + "Specifies the target context distinguished name." + ], + "isConfigurable": false, + "propGlobalId": "4990", + "propLocalId": "2530", + "label": "Target-context", + "baseType": "reference:BinRef", + "modelType": "reln:Dn", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tDn": { + "comment": [ + "The distinguished name of the target." + ], + "isConfigurable": false, + "propGlobalId": "100", + "propLocalId": "77", + "label": "Target-dn", + "baseType": "reference:BinRef", + "modelType": "reln:Dn", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tRn": { + "comment": [ + "Specifies the target's related name." + ], + "isConfigurable": false, + "propGlobalId": "4989", + "propLocalId": "2529", + "label": "Target-rn", + "baseType": "string:Basic", + "modelType": "string:Basic", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tType": { + "comment": [ + "Represents the type of target. The target type for this object is named." + ], + "isConfigurable": false, + "propGlobalId": "4988", + "propLocalId": "81", + "label": "tType", + "baseType": "scalar:Enum8", + "modelType": "reln:TargetType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "all", + "platformFlavors": [ + + ], + "label": "all "}, + { "value": "name", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "mo", + "platformFlavors": [ + + ], + "label": "mo "}, + { "value": "0", "localName": "name", + "platformFlavors": [ + + ], + "label": "name "} + ], + "default": "name", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tnNetflowExporterPolName": { + "isConfigurable": true, + "propGlobalId": "27371", + "propLocalId": "6396", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": false, + "readOnly": false, + "isNaming": true, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 1, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "uid": { + "comment": [ + "A unique identifier for this object." + ], + "isConfigurable": false, + "propGlobalId": "8", + "propLocalId": "8", + "label": "uid", + "baseType": "scalar:Uint16", + "modelType": "scalar:Uint16", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "userdom": { + "isConfigurable": true, + "propGlobalId": "60657", + "propLocalId": "13244", + "label": "userdom", + "baseType": "string:Basic", + "modelType": "mo:UserDomType", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 1024, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "validValues": [ + { "value": "all", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "all", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + } + } + } +} \ No newline at end of file diff --git a/gen/meta/netflowRsMonitorToRecord.json b/gen/meta/netflowRsMonitorToRecord.json new file mode 100644 index 000000000..ad3f8d879 --- /dev/null +++ b/gen/meta/netflowRsMonitorToRecord.json @@ -0,0 +1,959 @@ +{ + "netflow:RsMonitorToRecord": { + "contains": { + "aaa:RbacAnnotation": "", + "fault:Counts": "", + "fault:Inst": "", + "health:Inst": "", + "tag:Annotation": "", + "tag:Tag": "" + }, + "rnMap": { + "annotationKey-": "tag:Annotation", + "fault-": "fault:Inst", + "fltCnts": "fault:Counts", + "health": "health:Inst", + "rbacDom-": "aaa:RbacAnnotation", + "tagKey-": "tag:Tag" + }, + "identifiedBy": [ + + ], + "rnFormat": "rsmonitorToRecord", + "containedBy": { + "netflow:MonitorPol": "" + }, + "superClasses": [ + "netflow:ARsMonitorToRecord", + "pol:NToRef", + "reln:To", + "reln:Inst" + ], + "subClasses": { + + }, + "relationInfo": { + "type": "named", + "cardinality": "n-to-1", + "fromMo": "netflow:MonitorPol", + "fromRelMo": "netflow:RsMonitorToRecord", + "toMo": "netflow:RecordPol", + "toRelMo": "netflow:RtMonitorToRecord", + "enforceable": true, + "resolvable": true + }, + "dnFormats": [ + "uni/infra/monitorpol-{name}/rsmonitorToRecord", + "uni/tn-{name}/monitorpol-{name}/rsmonitorToRecord" + ], + "writeAccess": [ + "admin" + ], + "readAccess": [ + "admin" + ], + "faults": { + "F2475": "fltNetflowRsMonitorToRecordResolveFail" + }, + "events": { + "E4212713": "creation||netflow:RsMonitorToRecord", + "E4212714": "modification||netflow:RsMonitorToRecord", + "E4212715": "deletion||netflow:RsMonitorToRecord" + }, + "stats": { + + }, + "isAbstract": false, + "isConfigurable": true, + "isContextRoot": false, + "isDeprecated": false, + "isHidden": false, + "isEncrypted": false, + "isExportable": true, + "isPersistent": true, + "isSubjectToQuota": false, + "isObservable": true, + "hasStats": false, + "isStat": false, + "isFaultable": true, + "isDomainable": false, + "isHealthScorable": true, + "shouldCollectHealthStats": false, + "healthCollectionSource": "faults", + "hasEventRules": false, + "abstractionLayer": "regular", + "apicNxProcessing": false, + "monitoringPolicySource": "Parent", + "isCreatableDeletable": "never", + "platformFlavors": [ + + ], + "classId": "9214", + "className": "RsMonitorToRecord", + "classPkg": "netflow", + "featureTag": "", + "moCategory": "RelationshipToLocal", + "label": "Record Policy Attachment", + "properties": { + "annotation": { + "comment": [ + "User annotation. Suggested format orchestrator:value" + ], + "isConfigurable": true, + "propGlobalId": "38549", + "propLocalId": "8719", + "label": "Annotation", + "baseType": "string:Basic", + "modelType": "mo:Annotation", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 128, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "childAction": { + "comment": [ + "Delete or ignore. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "4", + "propLocalId": "5", + "label": "childAction", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationChildAction", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "16384", "localName": "deleteAll", + "platformFlavors": [ + + ], + "label": "deleteAll "}, + { "value": "8192", "localName": "deleteNonPresent", + "platformFlavors": [ + + ], + "label": "deleteNonPresent "}, + { "value": "4096", "localName": "ignore", + "platformFlavors": [ + + ], + "label": "ignore "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "dn": { + "comment": [ + "A tag or metadata is a non-hierarchical keyword or term assigned to the fabric module." + ], + "isConfigurable": false, + "propGlobalId": "1", + "propLocalId": "2", + "label": "dn", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "extMngdBy": { + "comment": [ + "Indicates which orchestrator is managing this MO" + ], + "isConfigurable": false, + "propGlobalId": "40688", + "propLocalId": "8023", + "label": "Managed By", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ExtMngdByType", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "undefined", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "msc", + "platformFlavors": [ + + ], + "label": "msc "}, + { "value": "0", "localName": "undefined", + "platformFlavors": [ + + ], + "label": "undefined "} + ], + "default": "undefined", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "forceResolve": { + "comment": [ + "Whether the relation should force pull the target." + ], + "isConfigurable": false, + "propGlobalId": "107", + "propLocalId": "83", + "label": "forceResolve", + "baseType": "scalar:Bool", + "modelType": "scalar:Bool", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "true", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "false", "localName": "no", + "platformFlavors": [ + + ], + "label": "No "}, + { "value": "true", "localName": "yes", + "platformFlavors": [ + + ], + "label": "Yes "} + ], + "default": "yes", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "lcOwn": { + "comment": [ + "A value that indicates how this object was created. For internal use only." + ], + "isConfigurable": false, + "propGlobalId": "9", + "propLocalId": "9", + "label": "lcOwn", + "baseType": "scalar:Enum8", + "modelType": "mo:Owner", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "local", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "4", "localName": "implicit", + "platformFlavors": [ + + ], + "label": "Implicit "}, + { "value": "0", "localName": "local", + "platformFlavors": [ + + ], + "label": "Local "}, + { "value": "1", "localName": "policy", + "platformFlavors": [ + + ], + "label": "Policy "}, + { "value": "2", "localName": "replica", + "platformFlavors": [ + + ], + "label": "Replica "}, + { "value": "3", "localName": "resolveOnBehalf", + "platformFlavors": [ + + ], + "label": "ResolvedOnBehalf "} + ], + "default": "local", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "modTs": { + "comment": [ + "The time when this object was last modified." + ], + "isConfigurable": false, + "propGlobalId": "7", + "propLocalId": "7", + "label": "modTs", + "baseType": "scalar:Date", + "modelType": "mo:TStamp", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "never", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "never", + "platformFlavors": [ + + ], + "label": "never "} + ], + "default": "never", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "monPolDn": { + "comment": [ + "The monitoring policy attached to this observable object." + ], + "isConfigurable": false, + "propGlobalId": "27392", + "propLocalId": "228", + "label": "Monitoring policy", + "baseType": "reference:BinRef", + "modelType": "reference:BinRef", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "rType": { + "comment": [ + "Represents the type of resolver." + ], + "isConfigurable": false, + "propGlobalId": "106", + "propLocalId": "82", + "label": "rType", + "baseType": "scalar:Enum8", + "modelType": "reln:ResolverType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "mo", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "3", "localName": "local", + "platformFlavors": [ + + ], + "label": "local "}, + { "value": "1", "localName": "mo", + "platformFlavors": [ + + ], + "label": "mo "}, + { "value": "2", "localName": "service", + "platformFlavors": [ + + ], + "label": "service "} + ], + "default": "mo", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "rn": { + "comment": [ + "Identifies an object from its siblings within the context of its parent object. The distinguished name contains a sequence of relative names." + ], + "isConfigurable": false, + "propGlobalId": "2", + "propLocalId": "3", + "label": "rn", + "baseType": "reference:BinRN", + "modelType": "reference:BinRN", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "state": { + "comment": [ + "Represents the state of the relationship." + ], + "isConfigurable": false, + "propGlobalId": "103", + "propLocalId": "26", + "label": "State", + "baseType": "scalar:Enum8", + "modelType": "reln:State", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "5", "localName": "cardinality-violation", + "platformFlavors": [ + + ], + "comment": [ + "cardinality violation - When relations are created such that they violate the cardinality, state of the relation would be set to this." + ], + "label": "cardinality-violation "}, + { "value": "unformed", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "formed", + "platformFlavors": [ + + ], + "comment": [ + "the relationship is formed with the target object" + ], + "label": "formed "}, + { "value": "4", "localName": "invalid-target", + "platformFlavors": [ + + ], + "comment": [ + "invalid target DN" + ], + "label": "invalid-target "}, + { "value": "2", "localName": "missing-target", + "platformFlavors": [ + + ], + "comment": [ + "target does not exist" + ], + "label": "missing-target "}, + { "value": "0", "localName": "unformed", + "platformFlavors": [ + + ], + "comment": [ + "the relationship is not formed" + ], + "label": "unformed "} + ], + "default": "unformed", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "stateQual": { + "comment": [ + "Represents the state qualifier of the relationship." + ], + "isConfigurable": false, + "propGlobalId": "104", + "propLocalId": "80", + "label": "State Qualifier", + "baseType": "scalar:Enum8", + "modelType": "reln:StateQual", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "default-target", + "platformFlavors": [ + + ], + "comment": [ + "target not specified, using default" + ], + "label": "default-target "}, + { "value": "none", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "mismatch-target", + "platformFlavors": [ + + ], + "comment": [ + "target not found, using default" + ], + "label": "mismatch-target "}, + { "value": "0", "localName": "none", + "platformFlavors": [ + + ], + "comment": [ + "no issue" + ], + "label": "none "} + ], + "default": "none", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "status": { + "comment": [ + "The upgrade status. This property is for internal use only." + ], + "isConfigurable": false, + "propGlobalId": "3", + "propLocalId": "4", + "label": "status", + "baseType": "scalar:Bitmask32", + "modelType": "mo:ModificationStatus", + "needsPropDelimiters": false, + "uitype": "bitmask", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "created", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be created. An error is returned if the object already exists. \nIn the return value of a setter method: indicates that an object has been created. \n" + ], + "label": "created "}, + { "value": "8", "localName": "deleted", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be deleted. In the return value of a setter method: indicates that an object has been deleted." + ], + "label": "deleted "}, + { "value": "4", "localName": "modified", + "platformFlavors": [ + + ], + "comment": [ + "In a setter method: specifies that an object should be modified In the return value of a setter method: indicates that an object has been modified." + ], + "label": "modified "} + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tCl": { + "comment": [ + "The class ID of the target object. This property is managed internally and should not be modified by the user." + ], + "isConfigurable": false, + "propGlobalId": "27376", + "propLocalId": "78", + "label": "Target-class", + "baseType": "scalar:Enum16", + "modelType": "reln:ClassId", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validValues": [ + { "value": "9203", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "9203", "localName": "netflowRecordPol", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "0", "localName": "unspecified", + "platformFlavors": [ + + ], + "label": "unspecified "} + ], + "default": "netflowRecordPol", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tContextDn": { + "comment": [ + "Specifies the target context distinguished name." + ], + "isConfigurable": false, + "propGlobalId": "4990", + "propLocalId": "2530", + "label": "Target-context", + "baseType": "reference:BinRef", + "modelType": "reln:Dn", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tDn": { + "comment": [ + "The distinguished name of the target." + ], + "isConfigurable": false, + "propGlobalId": "100", + "propLocalId": "77", + "label": "Target-dn", + "baseType": "reference:BinRef", + "modelType": "reln:Dn", + "needsPropDelimiters": true, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tRn": { + "comment": [ + "Specifies the target's related name." + ], + "isConfigurable": false, + "propGlobalId": "4989", + "propLocalId": "2529", + "label": "Target-rn", + "baseType": "string:Basic", + "modelType": "string:Basic", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tType": { + "comment": [ + "Represents the type of target. The target type for this object is named." + ], + "isConfigurable": false, + "propGlobalId": "4988", + "propLocalId": "81", + "label": "tType", + "baseType": "scalar:Enum8", + "modelType": "reln:TargetType", + "needsPropDelimiters": false, + "uitype": "enum", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": true, + "isLike": false, + "validValues": [ + { "value": "2", "localName": "all", + "platformFlavors": [ + + ], + "label": "all "}, + { "value": "name", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "}, + { "value": "1", "localName": "mo", + "platformFlavors": [ + + ], + "label": "mo "}, + { "value": "0", "localName": "name", + "platformFlavors": [ + + ], + "label": "name "} + ], + "default": "name", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "tnNetflowRecordPolName": { + "isConfigurable": true, + "propGlobalId": "27375", + "propLocalId": "6397", + "label": "Name", + "baseType": "string:Basic", + "modelType": "naming:Name", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 64, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "uid": { + "comment": [ + "A unique identifier for this object." + ], + "isConfigurable": false, + "propGlobalId": "8", + "propLocalId": "8", + "label": "uid", + "baseType": "scalar:Uint16", + "modelType": "scalar:Uint16", + "needsPropDelimiters": false, + "uitype": "auto", + "createOnly": false, + "readWrite": false, + "readOnly": true, + "isNaming": false, + "secure": false, + "implicit": true, + "mandatory": false, + "isOverride": false, + "isLike": false, + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + }, + "userdom": { + "isConfigurable": true, + "propGlobalId": "60657", + "propLocalId": "13244", + "label": "userdom", + "baseType": "string:Basic", + "modelType": "mo:UserDomType", + "needsPropDelimiters": false, + "uitype": "string", + "createOnly": false, + "readWrite": true, + "readOnly": false, + "isNaming": false, + "secure": false, + "implicit": false, + "mandatory": false, + "isOverride": false, + "isLike": false, + "validators": [ + {"min" : 0, "max": 1024, + "regexs": [ + {"regex" : "^[a-zA-Z0-9_.:-]+$", "type": "include"} + ] + } + ], + "validValues": [ + { "value": "all", "localName": "defaultValue", + "platformFlavors": [ + + ], + "label": " "} + ], + "default": "all", + "platformFlavors": [ + + ], + "isDeprecated": false, + "isHidden": false + } + } + } +} \ No newline at end of file diff --git a/gen/templates/datasource.go.tmpl b/gen/templates/datasource.go.tmpl index fba2b1752..22e399311 100644 --- a/gen/templates/datasource.go.tmpl +++ b/gen/templates/datasource.go.tmpl @@ -15,6 +15,9 @@ import ( {{- if or .HasBitmask }} "github.com/hashicorp/terraform-plugin-framework/types" {{- end}} + {{- if getDefaultValues .PkgName "parent_dn" $.Definitions}} + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + {{- end}} "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -49,7 +52,11 @@ func (d *{{.ResourceClassName}}DataSource) Schema(ctx context.Context, req datas }, {{- if .HasParent}} "parent_dn": schema.StringAttribute{ + {{- if getDefaultValues .PkgName "parent_dn" $.Definitions}} + Optional: true, + {{- else}} Required: true, + {{- end}} MarkdownDescription: "The distinguished name (DN) of the parent object.", }, {{- end}} @@ -129,6 +136,12 @@ func (d *{{.ResourceClassName}}DataSource) Read(ctx context.Context, req datasou return } + {{ if getDefaultValues .PkgName "parent_dn" $.Definitions}} + if data.ParentDn.IsNull() || data.ParentDn.IsUnknown(){ + data.ParentDn = basetypes.NewStringValue("{{getDefaultValues .PkgName "parent_dn" $.Definitions}}") + } + {{- end}} + set{{.ResourceClassName}}Id(ctx, data) // Create a copy of the Id for when not found during getAndSet{{.ResourceClassName}}Attributes diff --git a/gen/templates/datasource.md.tmpl b/gen/templates/datasource.md.tmpl index 520f600ce..e6925464d 100644 --- a/gen/templates/datasource.md.tmpl +++ b/gen/templates/datasource.md.tmpl @@ -53,6 +53,9 @@ Data source for {{.ResourceNameAsDescription}} {{- range .DocumentationParentDns}} - {{ . }} {{- end}} + {{- if getDefaultValues .PkgName "parent_dn" $.Definitions}} + - Default: `{{ getDefaultValues .PkgName "parent_dn" $.Definitions}}` + {{ end}} {{- end}} {{- range .Properties}} {{- if .IsNaming}} diff --git a/gen/templates/resource.go.tmpl b/gen/templates/resource.go.tmpl index c43404096..e91b2fd43 100644 --- a/gen/templates/resource.go.tmpl +++ b/gen/templates/resource.go.tmpl @@ -121,7 +121,13 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc }, {{- if .HasParent}} "parent_dn": schema.StringAttribute{ + {{- if getDefaultValues .PkgName "parent_dn" $.Definitions}} + Optional: true, + Computed: true, + Default: stringdefault.StaticString("{{getDefaultValues .PkgName "parent_dn" $.Definitions}}"), + {{- else}} Required: true, + {{- end}} MarkdownDescription: "The distinguished name (DN) of the parent object.", PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), diff --git a/gen/templates/resource.md.tmpl b/gen/templates/resource.md.tmpl index 12eeea3c7..22cbaf925 100644 --- a/gen/templates/resource.md.tmpl +++ b/gen/templates/resource.md.tmpl @@ -68,7 +68,7 @@ All examples for the {{.ResourceNameAsDescription}} resource can be found in the ## Schema ## ### Required ### -{{ if .HasParent}} +{{ if and .HasParent (not (getDefaultValues .PkgName "parent_dn" $.Definitions))}} * `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: {{- range .DocumentationParentDns}} - {{ . }} @@ -89,6 +89,13 @@ All examples for the {{.ResourceNameAsDescription}} resource can be found in the {{- if .HasOptionalProperties}} ### Optional ### +{{- if and .HasParent (getDefaultValues .PkgName "parent_dn" $.Definitions)}} +* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources: + {{- range .DocumentationParentDns}} + - {{ . }} + {{- end}} + - Default: `{{ getDefaultValues .PkgName "parent_dn" $.Definitions}}` +{{- end}} {{ range .Properties}} {{- if and (not .IsNaming) (not .IsRequired)}} {{- if eq .ValueType "bitmask"}} diff --git a/gen/templates/resource_test.go.tmpl b/gen/templates/resource_test.go.tmpl index 578f14ac8..36f1a929e 100644 --- a/gen/templates/resource_test.go.tmpl +++ b/gen/templates/resource_test.go.tmpl @@ -143,7 +143,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- range $key, $value := $.children}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -170,7 +172,9 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- range $key, $value := $.children}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} {{- end}} @@ -192,10 +196,16 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- range $key, $value := $.children}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} + {{- if eq (len $value) 1}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "2"), + {{- end}} {{- end}} ), }, @@ -212,11 +222,25 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} - {{- range $key, $value := $.children}}{{$child := index $value 1 }} - {{- range $child_key, $child_value := $child}} + {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}}{{- $child := index $value 0 }} + {{- if $child.deletable_child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- else}} + {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), - {{- end}} + {{- end}} + {{- end}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} + {{- else}} + {{- $child := index $value 1 }} + {{- range $child_key, $child_value := $child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} {{- end}} ), }, @@ -234,7 +258,20 @@ func TestAccResource{{$.resourceClassName}}With{{capitalize .class_name}}(t *tes {{- end}} {{- end}} {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}}{{- $child := index $value 0 }} + {{- if $child.deletable_child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- else}} + {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} + {{- end}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- end}} {{- end}} ), }, @@ -370,7 +407,9 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- range $key, $value := $.children}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "2"), @@ -396,10 +435,16 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- range $key, $value := $.children}} {{- range $child_index, $child := $value}} {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.{{$child_index}}.{{$child_key}}", "{{$child_value}}"), + {{- end}} {{- end}} {{- end}} + {{- if eq (len $value) 1}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "2"), + {{- end}} {{- end}} ), }, @@ -419,11 +464,25 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}", "{{$value}}"), {{- end}} {{- end}} - {{- range $key, $value := $.children}}{{$child := index $value 1 }} - {{- range $child_key, $child_value := $child}} + {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}}{{- $child := index $value 0 }} + {{- if $child.deletable_child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- else}} + {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), - {{- end}} + {{- end}} + {{- end}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} + {{- else}} + {{- $child := index $value 1 }} + {{- range $child_key, $child_value := $child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} {{- end}} ), }, @@ -444,7 +503,20 @@ func TestAccResource{{.resourceClassName}}(t *testing.T) { {{- end}} {{- end}} {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}}{{- $child := index $value 0 }} + {{- if $child.deletable_child}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- else}} + {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.0.{{$child_key}}", "{{$child_value}}"), + {{- end}} + {{- end}} + resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "1"), + {{- end}} + {{- else}} resource.TestCheckResourceAttr("aci_{{$.resourceName}}.test", "{{$key}}.#", "0"), + {{- end}} {{- end}} ), }, @@ -541,7 +613,9 @@ resource "aci_{{$.resourceName}}" "test" { {{- range $child := $value}} { {{- range $child_key, $child_value := $child}} + {{- if ne $child_key "deletable_child"}} {{$child_key}} = "{{$child_value}}" + {{- end}} {{- end}} }, {{- end}} @@ -574,6 +648,12 @@ resource "aci_{{$.resourceName}}" "test" { {{- end }} {{- end}} {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}} + {{- $child := index $value 0}} + {{- if $child.deletable_child}} + {{$key}} = [] + {{- end}} + {{- else}} {{$key}} = [ {{$child := index $value 1 }} { {{- range $child_key, $child_value := $child}} @@ -581,6 +661,7 @@ resource "aci_{{$.resourceName}}" "test" { {{- end}} }, ] + {{- end}} {{- end}} } ` @@ -596,7 +677,14 @@ resource "aci_{{$.resourceName}}" "test" { {{- end }} {{- end}} {{- range $key, $value := $.children}} + {{- if eq (len $value) 1}} + {{- $child := index $value 0}} + {{- if $child.deletable_child}} {{$key}} = [] + {{- end}} + {{- else}} + {{$key}} = [] + {{- end}} {{- end}} } ` diff --git a/gen/templates/testvars.yaml.tmpl b/gen/templates/testvars.yaml.tmpl index ef92b1543..fc638fd13 100644 --- a/gen/templates/testvars.yaml.tmpl +++ b/gen/templates/testvars.yaml.tmpl @@ -53,12 +53,21 @@ all: {{- end}} {{ if .Children}} children: - {{- range $key, $value := .Children}}{{$name := .ResourceName}} + {{- range $key, $value := .Children}}{{$name := .ResourceName}}{{$child_deletable := .AllowDelete}} {{.ResourceName}}: + {{- if not .IdentifiedBy}} + - {{ range .Properties}}{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}_1"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} + {{ end}} + {{- if $child_deletable -}} + deletable_child: true + {{- else -}} + deletable_child: false + {{ end}} + {{- else}} - {{ range .Properties}}{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{$length := len .ValidValues}}{{if ne $length 0}}"{{ index .ValidValues 0 }}"{{else if not .IsNaming}}"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}_1"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 0 $.Definitions}}"{{- end}} {{ end}} - {{ range .Properties}}{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}: {{$length := len .ValidValues}}{{if ge $length 2}}"{{ index .ValidValues 1 }}"{{else if not .IsNaming}}"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}_2"{{- else}}"{{lookupChildTestValue .PkgName $.ResourceName .SnakeCaseName $.TestVars 1 $.Definitions}}"{{- end}} - {{ end}}{{- end}}{{- end}} + {{ end}}{{- end}}{{- end}}{{- end}} {{- if .ContainedBy}} parents: {{- $index := 0}}{{- range $key := .DocumentationExamples}}{{$parentDependency := getParentTestDependencies $.PkgName $index $.Definitions}} diff --git a/gen/testvars/netflowMonitorPol.yaml b/gen/testvars/netflowMonitorPol.yaml new file mode 100644 index 000000000..1c9b59842 --- /dev/null +++ b/gen/testvars/netflowMonitorPol.yaml @@ -0,0 +1,59 @@ +# Code generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +default: + annotation: "orchestrator:terraform" + description: "" + name_alias: "" + owner_key: "" + owner_tag: "" + +datasource_non_existing: + name: "netfow_monitor_non_existing" + +datasource_required: + name: "netfow_monitor" + +resource_required: + name: "netfow_monitor" + +all: + annotation: "annotation" + description: "description" + name_alias: "name_alias" + owner_key: "owner_key" + owner_tag: "owner_tag" + +children: + relation_to_netflow_exporters: + - annotation: "annotation_1" + netflow_exporter_policy_name: "netflow_exporter_policy_name_0" + + - annotation: "annotation_2" + netflow_exporter_policy_name: "netflow_exporter_policy_name_1" + + relation_to_netflow_record: + - annotation: "annotation_1" + netflow_record_policy_name: "netflow_record_policy_name_1" + deletable_child: false + + annotations: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "value_2" + + tags: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "value_2" + +parents: + - class_name: "fvTenant" + parent_dependency: "" + parent_dn: "aci_tenant.test.id" + class_in_parent: false diff --git a/gen/testvars/netflowRsMonitorToExporter.yaml b/gen/testvars/netflowRsMonitorToExporter.yaml new file mode 100644 index 000000000..68ab8e82b --- /dev/null +++ b/gen/testvars/netflowRsMonitorToExporter.yaml @@ -0,0 +1,39 @@ +# Code generated by "gen/generator.go"; DO NOT EDIT. +# In order to regenerate this file execute `go generate` from the repository root. +# More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +default: + annotation: "orchestrator:terraform" + +datasource_non_existing: + netflow_exporter_policy_name: "non_existing_tn_netflow_exporter_pol_name" + +datasource_required: + netflow_exporter_policy_name: "test_tn_netflow_exporter_pol_name" + +resource_required: + netflow_exporter_policy_name: "test_tn_netflow_exporter_pol_name" + +all: + annotation: "annotation" + +children: + annotations: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "value_2" + + tags: + - key: "key_0" + value: "value_1" + + - key: "key_1" + value: "value_2" + +parents: + - class_name: "netflowMonitorPol" + parent_dependency: "fvTenant" + parent_dn: "aci_netflow_monitor_policy.test.id" + class_in_parent: false diff --git a/internal/provider/data_source_aci_netflow_monitor_policy.go b/internal/provider/data_source_aci_netflow_monitor_policy.go new file mode 100644 index 000000000..df3d82f21 --- /dev/null +++ b/internal/provider/data_source_aci_netflow_monitor_policy.go @@ -0,0 +1,202 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "context" + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &NetflowMonitorPolDataSource{} + +func NewNetflowMonitorPolDataSource() datasource.DataSource { + return &NetflowMonitorPolDataSource{} +} + +// NetflowMonitorPolDataSource defines the data source implementation. +type NetflowMonitorPolDataSource struct { + client *client.Client +} + +func (d *NetflowMonitorPolDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_netflow_monitor_policy") + resp.TypeName = req.ProviderTypeName + "_netflow_monitor_policy" + tflog.Debug(ctx, "End metadata of datasource: aci_netflow_monitor_policy") +} + +func (d *NetflowMonitorPolDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_netflow_monitor_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The netflow_monitor_policy datasource for the 'netflowMonitorPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Netflow Monitor Policy object.", + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Netflow Monitor Policy object.`, + }, + "description": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The description of the Netflow Monitor Policy object.`, + }, + "name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `The name of the Netflow Monitor Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The name alias of the Netflow Monitor Policy object.`, + }, + "owner_key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "relation_to_netflow_exporters": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Relation To Netflow Exporter object.`, + }, + "netflow_exporter_policy_name": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `Name.`, + }, + }, + }, + }, + "relation_to_netflow_record": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Relation To Netflow Record object.`, + }, + "netflow_record_policy_name": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `Name.`, + }, + }, + }, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of datasource: aci_netflow_monitor_policy") +} + +func (d *NetflowMonitorPolDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_netflow_monitor_policy") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + d.client = client + tflog.Debug(ctx, "End configure of datasource: aci_netflow_monitor_policy") +} + +func (d *NetflowMonitorPolDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_netflow_monitor_policy") + var data *NetflowMonitorPolResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + if data.ParentDn.IsNull() || data.ParentDn.IsUnknown() { + data.ParentDn = basetypes.NewStringValue("uni/infra") + } + + setNetflowMonitorPolId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetNetflowMonitorPolAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) + + getAndSetNetflowMonitorPolAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_netflow_monitor_policy data source", + fmt.Sprintf("The aci_netflow_monitor_policy data source with id '%s' has not been found", cachedId), + ) + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End read of datasource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_netflow_monitor_policy_test.go b/internal/provider/data_source_aci_netflow_monitor_policy_test.go new file mode 100644 index 000000000..7af9046b2 --- /dev/null +++ b/internal/provider/data_source_aci_netflow_monitor_policy_test.go @@ -0,0 +1,54 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDataSourceNetflowMonitorPolWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigNetflowMonitorPolDataSourceDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("data.aci_netflow_monitor_policy.test", "owner_tag", ""), + ), + }, + { + Config: testConfigNetflowMonitorPolNotExistingFvTenant, + ExpectError: regexp.MustCompile("Failed to read aci_netflow_monitor_policy data source"), + }, + }, + }) +} + +const testConfigNetflowMonitorPolDataSourceDependencyWithFvTenant = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +data "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + depends_on = [aci_netflow_monitor_policy.test] +} +` + +const testConfigNetflowMonitorPolNotExistingFvTenant = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +data "aci_netflow_monitor_policy" "test_non_existing" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor_non_existing" + depends_on = [aci_netflow_monitor_policy.test] +} +` diff --git a/internal/provider/data_source_aci_relation_to_netflow_exporter.go b/internal/provider/data_source_aci_relation_to_netflow_exporter.go new file mode 100644 index 000000000..cca30ef3e --- /dev/null +++ b/internal/provider/data_source_aci_relation_to_netflow_exporter.go @@ -0,0 +1,149 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "context" + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ datasource.DataSource = &NetflowRsMonitorToExporterDataSource{} + +func NewNetflowRsMonitorToExporterDataSource() datasource.DataSource { + return &NetflowRsMonitorToExporterDataSource{} +} + +// NetflowRsMonitorToExporterDataSource defines the data source implementation. +type NetflowRsMonitorToExporterDataSource struct { + client *client.Client +} + +func (d *NetflowRsMonitorToExporterDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of datasource: aci_relation_to_netflow_exporter") + resp.TypeName = req.ProviderTypeName + "_relation_to_netflow_exporter" + tflog.Debug(ctx, "End metadata of datasource: aci_relation_to_netflow_exporter") +} + +func (d *NetflowRsMonitorToExporterDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of datasource: aci_relation_to_netflow_exporter") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The relation_to_netflow_exporter datasource for the 'netflowRsMonitorToExporter' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Relation To Netflow Exporter object.", + }, + "parent_dn": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + }, + "annotation": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The annotation of the Relation To Netflow Exporter object.`, + }, + "netflow_exporter_policy_name": schema.StringAttribute{ + Required: true, + MarkdownDescription: `Name.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Computed: true, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of datasource: aci_relation_to_netflow_exporter") +} + +func (d *NetflowRsMonitorToExporterDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of datasource: aci_relation_to_netflow_exporter") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + d.client = client + tflog.Debug(ctx, "End configure of datasource: aci_relation_to_netflow_exporter") +} + +func (d *NetflowRsMonitorToExporterDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "Start read of datasource: aci_relation_to_netflow_exporter") + var data *NetflowRsMonitorToExporterResourceModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setNetflowRsMonitorToExporterId(ctx, data) + + // Create a copy of the Id for when not found during getAndSetNetflowRsMonitorToExporterAttributes + cachedId := data.Id.ValueString() + + tflog.Debug(ctx, fmt.Sprintf("Read of datasource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) + + getAndSetNetflowRsMonitorToExporterAttributes(ctx, &resp.Diagnostics, d.client, data) + + if data.Id.IsNull() { + resp.Diagnostics.AddError( + "Failed to read aci_relation_to_netflow_exporter data source", + fmt.Sprintf("The aci_relation_to_netflow_exporter data source with id '%s' has not been found", cachedId), + ) + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End read of datasource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) +} diff --git a/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go b/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go new file mode 100644 index 000000000..c5ef90c08 --- /dev/null +++ b/internal/provider/data_source_aci_relation_to_netflow_exporter_test.go @@ -0,0 +1,50 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccDataSourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testConfigNetflowRsMonitorToExporterDataSourceDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("data.aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + ), + }, + { + Config: testConfigNetflowRsMonitorToExporterNotExistingNetflowMonitorPol, + ExpectError: regexp.MustCompile("Failed to read aci_relation_to_netflow_exporter data source"), + }, + }, + }) +} + +const testConfigNetflowRsMonitorToExporterDataSourceDependencyWithNetflowMonitorPol = testConfigNetflowRsMonitorToExporterMinDependencyWithNetflowMonitorPol + ` +data "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + depends_on = [aci_relation_to_netflow_exporter.test] +} +` + +const testConfigNetflowRsMonitorToExporterNotExistingNetflowMonitorPol = testConfigNetflowRsMonitorToExporterMinDependencyWithNetflowMonitorPol + ` +data "aci_relation_to_netflow_exporter" "test_non_existing" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "non_existing_tn_netflow_exporter_pol_name" + depends_on = [aci_relation_to_netflow_exporter.test] +} +` diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2f962970d..9dc52fc66 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -207,6 +207,8 @@ func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource NewMgmtInstPResource, NewMgmtRsOoBConsResource, NewMgmtSubnetResource, + NewNetflowMonitorPolResource, + NewNetflowRsMonitorToExporterResource, NewPimRouteMapEntryResource, NewPimRouteMapPolResource, NewTagAnnotationResource, @@ -229,6 +231,8 @@ func (p *AciProvider) DataSources(ctx context.Context) []func() datasource.DataS NewMgmtInstPDataSource, NewMgmtRsOoBConsDataSource, NewMgmtSubnetDataSource, + NewNetflowMonitorPolDataSource, + NewNetflowRsMonitorToExporterDataSource, NewPimRouteMapEntryDataSource, NewPimRouteMapPolDataSource, NewTagAnnotationDataSource, diff --git a/internal/provider/resource_aci_netflow_monitor_policy.go b/internal/provider/resource_aci_netflow_monitor_policy.go new file mode 100644 index 000000000..e3f1251a8 --- /dev/null +++ b/internal/provider/resource_aci_netflow_monitor_policy.go @@ -0,0 +1,823 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "context" + "encoding/json" + "fmt" + "reflect" + "strings" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework/diag" + "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/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "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-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &NetflowMonitorPolResource{} +var _ resource.ResourceWithImportState = &NetflowMonitorPolResource{} + +func NewNetflowMonitorPolResource() resource.Resource { + return &NetflowMonitorPolResource{} +} + +// NetflowMonitorPolResource defines the resource implementation. +type NetflowMonitorPolResource struct { + client *client.Client +} + +// NetflowMonitorPolResourceModel describes the resource data model. +type NetflowMonitorPolResourceModel struct { + Id types.String `tfsdk:"id"` + ParentDn types.String `tfsdk:"parent_dn"` + Annotation types.String `tfsdk:"annotation"` + Descr types.String `tfsdk:"description"` + Name types.String `tfsdk:"name"` + NameAlias types.String `tfsdk:"name_alias"` + OwnerKey types.String `tfsdk:"owner_key"` + OwnerTag types.String `tfsdk:"owner_tag"` + NetflowRsMonitorToExporter types.Set `tfsdk:"relation_to_netflow_exporters"` + NetflowRsMonitorToRecord types.Set `tfsdk:"relation_to_netflow_record"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +// NetflowRsMonitorToExporterNetflowMonitorPolResourceModel describes the resource data model for the children without relation ships. +type NetflowRsMonitorToExporterNetflowMonitorPolResourceModel struct { + Annotation types.String `tfsdk:"annotation"` + TnNetflowExporterPolName types.String `tfsdk:"netflow_exporter_policy_name"` +} + +// NetflowRsMonitorToRecordNetflowMonitorPolResourceModel describes the resource data model for the children without relation ships. +type NetflowRsMonitorToRecordNetflowMonitorPolResourceModel struct { + Annotation types.String `tfsdk:"annotation"` + TnNetflowRecordPolName types.String `tfsdk:"netflow_record_policy_name"` +} + +// TagAnnotationNetflowMonitorPolResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationNetflowMonitorPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +// TagTagNetflowMonitorPolResourceModel describes the resource data model for the children without relation ships. +type TagTagNetflowMonitorPolResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +type NetflowMonitorPolIdentifier struct { + Name types.String +} + +func (r *NetflowMonitorPolResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_netflow_monitor_policy") + resp.TypeName = req.ProviderTypeName + "_netflow_monitor_policy" + tflog.Debug(ctx, "End metadata of resource: aci_netflow_monitor_policy") +} + +func (r *NetflowMonitorPolResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_netflow_monitor_policy") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The netflow_monitor_policy resource for the 'netflowMonitorPol' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Netflow Monitor Policy object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parent_dn": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("uni/infra"), + MarkdownDescription: "The distinguished name (DN) of the parent object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + }, + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + Default: stringdefault.StaticString(globalAnnotation), + MarkdownDescription: `The annotation of the Netflow Monitor Policy object.`, + }, + "description": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The description of the Netflow Monitor Policy object.`, + }, + "name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `The name of the Netflow Monitor Policy object.`, + }, + "name_alias": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The name alias of the Netflow Monitor Policy object.`, + }, + "owner_key": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key for enabling clients to own their data for entity correlation.`, + }, + "owner_tag": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, + }, + "relation_to_netflow_exporters": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The annotation of the Relation To Netflow Exporter object.`, + }, + "netflow_exporter_policy_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `Name.`, + }, + }, + }, + }, + "relation_to_netflow_record": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + Validators: []validator.Set{ + setvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The annotation of the Relation To Netflow Record object.`, + }, + "netflow_record_policy_name": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `Name.`, + }, + }, + }, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of resource: aci_netflow_monitor_policy") +} + +func (r *NetflowMonitorPolResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_netflow_monitor_policy") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client + tflog.Debug(ctx, "End configure of resource: aci_netflow_monitor_policy") +} + +func (r *NetflowMonitorPolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_netflow_monitor_policy") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *NetflowMonitorPolResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + setNetflowMonitorPolId(ctx, stateData) + getAndSetNetflowMonitorPolAttributes(ctx, &resp.Diagnostics, r.client, stateData) + + var data *NetflowMonitorPolResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setNetflowMonitorPolId(ctx, data) + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) + + var netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState []NetflowRsMonitorToExporterNetflowMonitorPolResourceModel + data.NetflowRsMonitorToExporter.ElementsAs(ctx, &netflowRsMonitorToExporterPlan, false) + stateData.NetflowRsMonitorToExporter.ElementsAs(ctx, &netflowRsMonitorToExporterState, false) + var netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState []NetflowRsMonitorToRecordNetflowMonitorPolResourceModel + data.NetflowRsMonitorToRecord.ElementsAs(ctx, &netflowRsMonitorToRecordPlan, false) + stateData.NetflowRsMonitorToRecord.ElementsAs(ctx, &netflowRsMonitorToRecordState, false) + var tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowMonitorPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagNetflowMonitorPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getNetflowMonitorPolCreateJsonPayload(ctx, &resp.Diagnostics, data, netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState, netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { + return + } + + getAndSetNetflowMonitorPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowMonitorPolResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_netflow_monitor_policy") + var data *NetflowMonitorPolResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Read of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) + + getAndSetNetflowMonitorPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *NetflowMonitorPolResourceModel + resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) + } else { + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + } + + tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowMonitorPolResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_netflow_monitor_policy") + var data *NetflowMonitorPolResourceModel + var stateData *NetflowMonitorPolResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) + + var netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState []NetflowRsMonitorToExporterNetflowMonitorPolResourceModel + data.NetflowRsMonitorToExporter.ElementsAs(ctx, &netflowRsMonitorToExporterPlan, false) + stateData.NetflowRsMonitorToExporter.ElementsAs(ctx, &netflowRsMonitorToExporterState, false) + var netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState []NetflowRsMonitorToRecordNetflowMonitorPolResourceModel + data.NetflowRsMonitorToRecord.ElementsAs(ctx, &netflowRsMonitorToRecordPlan, false) + stateData.NetflowRsMonitorToRecord.ElementsAs(ctx, &netflowRsMonitorToRecordState, false) + var tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowMonitorPolResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagNetflowMonitorPolResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getNetflowMonitorPolCreateJsonPayload(ctx, &resp.Diagnostics, data, netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState, netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + + if resp.Diagnostics.HasError() { + return + } + + getAndSetNetflowMonitorPolAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowMonitorPolResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_netflow_monitor_policy") + var data *NetflowMonitorPolResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Delete of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "netflowMonitorPol", data.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { + return + } + tflog.Debug(ctx, fmt.Sprintf("End delete of resource aci_netflow_monitor_policy with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowMonitorPolResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_netflow_monitor_policy") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *NetflowMonitorPolResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_netflow_monitor_policy with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_netflow_monitor_policy") +} + +func getAndSetNetflowMonitorPolAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowMonitorPolResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowMonitorPol,netflowRsMonitorToExporter,netflowRsMonitorToRecord,tagAnnotation,tagTag"), "GET", nil) + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("netflowMonitorPol").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("netflowMonitorPol").Data().([]interface{}) + if len(classReadInfo) == 1 { + attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) + for attributeName, attributeValue := range attributes { + if attributeName == "dn" { + data.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowMonitorPolParentDn(ctx, attributeValue.(string), data) + } + if attributeName == "annotation" { + data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "descr" { + data.Descr = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "name" { + data.Name = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "nameAlias" { + data.NameAlias = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "ownerKey" { + data.OwnerKey = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "ownerTag" { + data.OwnerTag = basetypes.NewStringValue(attributeValue.(string)) + } + } + NetflowRsMonitorToExporterNetflowMonitorPolList := make([]NetflowRsMonitorToExporterNetflowMonitorPolResourceModel, 0) + NetflowRsMonitorToRecordNetflowMonitorPolList := make([]NetflowRsMonitorToRecordNetflowMonitorPolResourceModel, 1) + TagAnnotationNetflowMonitorPolList := make([]TagAnnotationNetflowMonitorPolResourceModel, 0) + TagTagNetflowMonitorPolList := make([]TagTagNetflowMonitorPolResourceModel, 0) + _, ok := classReadInfo[0].(map[string]interface{})["children"] + if ok { + children := classReadInfo[0].(map[string]interface{})["children"].([]interface{}) + for _, child := range children { + for childClassName, childClassDetails := range child.(map[string]interface{}) { + childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{}) + if childClassName == "netflowRsMonitorToExporter" { + NetflowRsMonitorToExporterNetflowMonitorPol := NetflowRsMonitorToExporterNetflowMonitorPolResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "annotation" { + NetflowRsMonitorToExporterNetflowMonitorPol.Annotation = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "tnNetflowExporterPolName" { + NetflowRsMonitorToExporterNetflowMonitorPol.TnNetflowExporterPolName = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + NetflowRsMonitorToExporterNetflowMonitorPolList = append(NetflowRsMonitorToExporterNetflowMonitorPolList, NetflowRsMonitorToExporterNetflowMonitorPol) + } + if childClassName == "netflowRsMonitorToRecord" { + NetflowRsMonitorToRecordNetflowMonitorPol := NetflowRsMonitorToRecordNetflowMonitorPolResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "annotation" { + NetflowRsMonitorToRecordNetflowMonitorPol.Annotation = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "tnNetflowRecordPolName" { + NetflowRsMonitorToRecordNetflowMonitorPol.TnNetflowRecordPolName = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + NetflowRsMonitorToRecordNetflowMonitorPolList[0] = NetflowRsMonitorToRecordNetflowMonitorPol + } + if childClassName == "tagAnnotation" { + TagAnnotationNetflowMonitorPol := TagAnnotationNetflowMonitorPolResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationNetflowMonitorPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationNetflowMonitorPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagAnnotationNetflowMonitorPolList = append(TagAnnotationNetflowMonitorPolList, TagAnnotationNetflowMonitorPol) + } + if childClassName == "tagTag" { + TagTagNetflowMonitorPol := TagTagNetflowMonitorPolResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagNetflowMonitorPol.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagNetflowMonitorPol.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagTagNetflowMonitorPolList = append(TagTagNetflowMonitorPolList, TagTagNetflowMonitorPol) + } + } + } + } + netflowRsMonitorToExporterSet, _ := types.SetValueFrom(ctx, data.NetflowRsMonitorToExporter.ElementType(ctx), NetflowRsMonitorToExporterNetflowMonitorPolList) + data.NetflowRsMonitorToExporter = netflowRsMonitorToExporterSet + netflowRsMonitorToRecordSet, _ := types.SetValueFrom(ctx, data.NetflowRsMonitorToRecord.ElementType(ctx), NetflowRsMonitorToRecordNetflowMonitorPolList) + data.NetflowRsMonitorToRecord = netflowRsMonitorToRecordSet + tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowMonitorPolList) + data.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowMonitorPolList) + data.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'netflowMonitorPol'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + data.Id = basetypes.NewStringNull() + } +} + +func getNetflowMonitorPolRn(ctx context.Context, data *NetflowMonitorPolResourceModel) string { + rn := "monitorpol-{name}" + for _, identifier := range []string{"name"} { + fieldName := fmt.Sprintf("%s%s", strings.ToUpper(identifier[:1]), identifier[1:]) + fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString() + rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", identifier), fieldValue) + } + return rn +} + +func setNetflowMonitorPolParentDn(ctx context.Context, dn string, data *NetflowMonitorPolResourceModel) { + bracketIndex := 0 + rnIndex := 0 + for i := len(dn) - 1; i >= 0; i-- { + if string(dn[i]) == "]" { + bracketIndex = bracketIndex + 1 + } else if string(dn[i]) == "[" { + bracketIndex = bracketIndex - 1 + } else if string(dn[i]) == "/" && bracketIndex == 0 { + rnIndex = i + break + } + } + data.ParentDn = basetypes.NewStringValue(dn[:rnIndex]) +} + +func setNetflowMonitorPolId(ctx context.Context, data *NetflowMonitorPolResourceModel) { + rn := getNetflowMonitorPolRn(ctx, data) + data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn)) +} + +func getNetflowMonitorPolNetflowRsMonitorToExporterChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState []NetflowRsMonitorToExporterNetflowMonitorPolResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.NetflowRsMonitorToExporter.IsUnknown() { + netflowRsMonitorToExporterIdentifiers := []NetflowRsMonitorToExporterIdentifier{} + for _, netflowRsMonitorToExporter := range netflowRsMonitorToExporterPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !netflowRsMonitorToExporter.Annotation.IsUnknown() { + childMap["attributes"]["annotation"] = netflowRsMonitorToExporter.Annotation.ValueString() + } else { + childMap["attributes"]["annotation"] = globalAnnotation + } + if !netflowRsMonitorToExporter.TnNetflowExporterPolName.IsUnknown() { + childMap["attributes"]["tnNetflowExporterPolName"] = netflowRsMonitorToExporter.TnNetflowExporterPolName.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"netflowRsMonitorToExporter": childMap}) + netflowRsMonitorToExporterIdentifier := NetflowRsMonitorToExporterIdentifier{} + netflowRsMonitorToExporterIdentifier.TnNetflowExporterPolName = netflowRsMonitorToExporter.TnNetflowExporterPolName + netflowRsMonitorToExporterIdentifiers = append(netflowRsMonitorToExporterIdentifiers, netflowRsMonitorToExporterIdentifier) + } + for _, netflowRsMonitorToExporter := range netflowRsMonitorToExporterState { + delete := true + for _, netflowRsMonitorToExporterIdentifier := range netflowRsMonitorToExporterIdentifiers { + if netflowRsMonitorToExporterIdentifier.TnNetflowExporterPolName == netflowRsMonitorToExporter.TnNetflowExporterPolName { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["tnNetflowExporterPolName"] = netflowRsMonitorToExporter.TnNetflowExporterPolName.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"netflowRsMonitorToExporter": childMap}) + } + } + } else { + data.NetflowRsMonitorToExporter = types.SetNull(data.NetflowRsMonitorToExporter.ElementType(ctx)) + } + + return childPayloads +} +func getNetflowMonitorPolNetflowRsMonitorToRecordChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState []NetflowRsMonitorToRecordNetflowMonitorPolResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.NetflowRsMonitorToRecord.IsUnknown() { + for _, netflowRsMonitorToRecord := range netflowRsMonitorToRecordPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !netflowRsMonitorToRecord.Annotation.IsUnknown() { + childMap["attributes"]["annotation"] = netflowRsMonitorToRecord.Annotation.ValueString() + } else { + childMap["attributes"]["annotation"] = globalAnnotation + } + if !netflowRsMonitorToRecord.TnNetflowRecordPolName.IsUnknown() { + childMap["attributes"]["tnNetflowRecordPolName"] = netflowRsMonitorToRecord.TnNetflowRecordPolName.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"netflowRsMonitorToRecord": childMap}) + } + if len(netflowRsMonitorToRecordPlan) == 0 && len(netflowRsMonitorToRecordState) == 1 { + diags.AddError( + "NetflowRsMonitorToRecord object cannot be deleted", + "deletion of child is only possible upon deletion of the parent", + ) + return nil + } + } else { + data.NetflowRsMonitorToRecord = types.SetNull(data.NetflowRsMonitorToRecord.ElementType(ctx)) + } + + return childPayloads +} +func getNetflowMonitorPolTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowMonitorPolResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotation := range tagAnnotationPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagAnnotation.Key.IsUnknown() { + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + } + if !tagAnnotation.Value.IsUnknown() { + childMap["attributes"]["value"] = tagAnnotation.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotation.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotation.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + } + } + } else { + data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx)) + } + + return childPayloads +} +func getNetflowMonitorPolTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, tagTagPlan, tagTagState []TagTagNetflowMonitorPolResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTag := range tagTagPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagTag.Key.IsUnknown() { + childMap["attributes"]["key"] = tagTag.Key.ValueString() + } + if !tagTag.Value.IsUnknown() { + childMap["attributes"]["value"] = tagTag.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTag.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTag.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagTag.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + } + } + } else { + data.TagTag = types.SetNull(data.TagTag.ElementType(ctx)) + } + + return childPayloads +} + +func getNetflowMonitorPolCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, data *NetflowMonitorPolResourceModel, netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState []NetflowRsMonitorToExporterNetflowMonitorPolResourceModel, netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState []NetflowRsMonitorToRecordNetflowMonitorPolResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowMonitorPolResourceModel, tagTagPlan, tagTagState []TagTagNetflowMonitorPolResourceModel) *container.Container { + payloadMap := map[string]interface{}{} + payloadMap["attributes"] = map[string]string{} + childPayloads := []map[string]interface{}{} + + NetflowRsMonitorToExporterchildPayloads := getNetflowMonitorPolNetflowRsMonitorToExporterChildPayloads(ctx, diags, data, netflowRsMonitorToExporterPlan, netflowRsMonitorToExporterState) + if NetflowRsMonitorToExporterchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, NetflowRsMonitorToExporterchildPayloads...) + + NetflowRsMonitorToRecordchildPayloads := getNetflowMonitorPolNetflowRsMonitorToRecordChildPayloads(ctx, diags, data, netflowRsMonitorToRecordPlan, netflowRsMonitorToRecordState) + if NetflowRsMonitorToRecordchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, NetflowRsMonitorToRecordchildPayloads...) + + TagAnnotationchildPayloads := getNetflowMonitorPolTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getNetflowMonitorPolTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState) + if TagTagchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagTagchildPayloads...) + + payloadMap["children"] = childPayloads + if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() { + payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString() + } + if !data.Descr.IsNull() && !data.Descr.IsUnknown() { + payloadMap["attributes"].(map[string]string)["descr"] = data.Descr.ValueString() + } + if !data.Name.IsNull() && !data.Name.IsUnknown() { + payloadMap["attributes"].(map[string]string)["name"] = data.Name.ValueString() + } + if !data.NameAlias.IsNull() && !data.NameAlias.IsUnknown() { + payloadMap["attributes"].(map[string]string)["nameAlias"] = data.NameAlias.ValueString() + } + if !data.OwnerKey.IsNull() && !data.OwnerKey.IsUnknown() { + payloadMap["attributes"].(map[string]string)["ownerKey"] = data.OwnerKey.ValueString() + } + if !data.OwnerTag.IsNull() && !data.OwnerTag.IsUnknown() { + payloadMap["attributes"].(map[string]string)["ownerTag"] = data.OwnerTag.ValueString() + } + + payload, err := json.Marshal(map[string]interface{}{"netflowMonitorPol": payloadMap}) + if err != nil { + diags.AddError( + "Marshalling of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + + jsonPayload, err := container.ParseJSON(payload) + + if err != nil { + diags.AddError( + "Construction of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + return jsonPayload +} diff --git a/internal/provider/resource_aci_netflow_monitor_policy_test.go b/internal/provider/resource_aci_netflow_monitor_policy_test.go new file mode 100644 index 000000000..1c5fae7a0 --- /dev/null +++ b/internal/provider/resource_aci_netflow_monitor_policy_test.go @@ -0,0 +1,309 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceNetflowMonitorPolWithFvTenant(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigNetflowMonitorPolMinDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", ""), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigNetflowMonitorPolAllDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "annotation"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", "description"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", "name_alias"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", "owner_key"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", "owner_tag"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigNetflowMonitorPolMinDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigNetflowMonitorPolResetDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", ""), + ), + }, + // Import testing + { + ResourceName: "aci_netflow_monitor_policy.test", + ImportState: true, + ImportStateVerify: true, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", ""), + ), + }, + // Update with children + { + Config: testConfigNetflowMonitorPolChildrenDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.netflow_exporter_policy_name", "netflow_exporter_policy_name_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.netflow_exporter_policy_name", "netflow_exporter_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.netflow_record_policy_name", "netflow_record_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.value", "value_2"), + ), + }, + // Import testing with children + { + ResourceName: "aci_netflow_monitor_policy.test", + ImportState: true, + ImportStateVerify: true, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name", "netfow_monitor"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "description", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "name_alias", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_key", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "owner_tag", ""), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.netflow_exporter_policy_name", "netflow_exporter_policy_name_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.netflow_exporter_policy_name", "netflow_exporter_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.netflow_record_policy_name", "netflow_record_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.value", "value_2"), + ), + }, + // Update with children removed from config + { + Config: testConfigNetflowMonitorPolChildrenRemoveFromConfigDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.netflow_exporter_policy_name", "netflow_exporter_policy_name_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.1.netflow_exporter_policy_name", "netflow_exporter_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.#", "2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.netflow_record_policy_name", "netflow_record_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.#", "1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigNetflowMonitorPolChildrenRemoveOneDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.0.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.annotation", "annotation_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.0.netflow_exporter_policy_name", "netflow_exporter_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.#", "1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.netflow_record_policy_name", "netflow_record_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.#", "1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.0.value", "value_2"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigNetflowMonitorPolChildrenRemoveAllDependencyWithFvTenant, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_exporters.#", "0"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.0.netflow_record_policy_name", "netflow_record_policy_name_1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "relation_to_netflow_record.#", "1"), + resource.TestCheckResourceAttr("aci_netflow_monitor_policy.test", "tags.#", "0"), + ), + }, + }, + }) +} + +const testConfigNetflowMonitorPolMinDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" +} +` + +const testConfigNetflowMonitorPolAllDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + annotation = "annotation" + description = "description" + name_alias = "name_alias" + owner_key = "owner_key" + owner_tag = "owner_tag" +} +` + +const testConfigNetflowMonitorPolResetDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + annotation = "orchestrator:terraform" + description = "" + name_alias = "" + owner_key = "" + owner_tag = "" +} +` +const testConfigNetflowMonitorPolChildrenDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + annotations = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "value_2" + }, + ] + relation_to_netflow_exporters = [ + { + annotation = "annotation_1" + netflow_exporter_policy_name = "netflow_exporter_policy_name_0" + }, + { + annotation = "annotation_2" + netflow_exporter_policy_name = "netflow_exporter_policy_name_1" + }, + ] + relation_to_netflow_record = [ + { + annotation = "annotation_1" + netflow_record_policy_name = "netflow_record_policy_name_1" + }, + ] + tags = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "value_2" + }, + ] +} +` + +const testConfigNetflowMonitorPolChildrenRemoveFromConfigDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" +} +` + +const testConfigNetflowMonitorPolChildrenRemoveOneDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + annotations = [ + { + key = "key_1" + value = "value_2" + }, + ] + relation_to_netflow_exporters = [ + { + annotation = "annotation_2" + netflow_exporter_policy_name = "netflow_exporter_policy_name_1" + }, + ] + tags = [ + { + key = "key_1" + value = "value_2" + }, + ] +} +` + +const testConfigNetflowMonitorPolChildrenRemoveAllDependencyWithFvTenant = testConfigFvTenantMin + ` +resource "aci_netflow_monitor_policy" "test" { + parent_dn = aci_tenant.test.id + name = "netfow_monitor" + annotations = [] + relation_to_netflow_exporters = [] + tags = [] +} +` diff --git a/internal/provider/resource_aci_relation_to_netflow_exporter.go b/internal/provider/resource_aci_relation_to_netflow_exporter.go new file mode 100644 index 000000000..858087501 --- /dev/null +++ b/internal/provider/resource_aci_relation_to_netflow_exporter.go @@ -0,0 +1,563 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "context" + "encoding/json" + "fmt" + "reflect" + "strings" + + "github.com/ciscoecosystem/aci-go-client/v2/client" + "github.com/ciscoecosystem/aci-go-client/v2/container" + "github.com/hashicorp/terraform-plugin-framework/diag" + "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/setplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var _ resource.Resource = &NetflowRsMonitorToExporterResource{} +var _ resource.ResourceWithImportState = &NetflowRsMonitorToExporterResource{} + +func NewNetflowRsMonitorToExporterResource() resource.Resource { + return &NetflowRsMonitorToExporterResource{} +} + +// NetflowRsMonitorToExporterResource defines the resource implementation. +type NetflowRsMonitorToExporterResource struct { + client *client.Client +} + +// NetflowRsMonitorToExporterResourceModel describes the resource data model. +type NetflowRsMonitorToExporterResourceModel struct { + Id types.String `tfsdk:"id"` + ParentDn types.String `tfsdk:"parent_dn"` + Annotation types.String `tfsdk:"annotation"` + TnNetflowExporterPolName types.String `tfsdk:"netflow_exporter_policy_name"` + TagAnnotation types.Set `tfsdk:"annotations"` + TagTag types.Set `tfsdk:"tags"` +} + +// TagAnnotationNetflowRsMonitorToExporterResourceModel describes the resource data model for the children without relation ships. +type TagAnnotationNetflowRsMonitorToExporterResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +// TagTagNetflowRsMonitorToExporterResourceModel describes the resource data model for the children without relation ships. +type TagTagNetflowRsMonitorToExporterResourceModel struct { + Key types.String `tfsdk:"key"` + Value types.String `tfsdk:"value"` +} + +type NetflowRsMonitorToExporterIdentifier struct { + TnNetflowExporterPolName types.String +} + +func (r *NetflowRsMonitorToExporterResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + tflog.Debug(ctx, "Start metadata of resource: aci_relation_to_netflow_exporter") + resp.TypeName = req.ProviderTypeName + "_relation_to_netflow_exporter" + tflog.Debug(ctx, "End metadata of resource: aci_relation_to_netflow_exporter") +} + +func (r *NetflowRsMonitorToExporterResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + tflog.Debug(ctx, "Start schema of resource: aci_relation_to_netflow_exporter") + resp.Schema = schema.Schema{ + // This description is used by the documentation generator and the language server. + MarkdownDescription: "The relation_to_netflow_exporter resource for the 'netflowRsMonitorToExporter' class", + + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "The distinguished name (DN) of the Relation To Netflow Exporter object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "parent_dn": schema.StringAttribute{ + Required: true, + MarkdownDescription: "The distinguished name (DN) of the parent object.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + }, + "annotation": schema.StringAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + Default: stringdefault.StaticString(globalAnnotation), + MarkdownDescription: `The annotation of the Relation To Netflow Exporter object.`, + }, + "netflow_exporter_policy_name": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + stringplanmodifier.RequiresReplace(), + }, + MarkdownDescription: `Name.`, + }, + "annotations": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + "tags": schema.SetNestedAttribute{ + MarkdownDescription: ``, + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "key": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The key used to uniquely identify this configuration object.`, + }, + "value": schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + MarkdownDescription: `The value of the property.`, + }, + }, + }, + }, + }, + } + tflog.Debug(ctx, "End schema of resource: aci_relation_to_netflow_exporter") +} + +func (r *NetflowRsMonitorToExporterResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + tflog.Debug(ctx, "Start configure of resource: aci_relation_to_netflow_exporter") + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + + return + } + + r.client = client + tflog.Debug(ctx, "End configure of resource: aci_relation_to_netflow_exporter") +} + +func (r *NetflowRsMonitorToExporterResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Start create of resource: aci_relation_to_netflow_exporter") + // On create retrieve information on current state prior to making any changes in order to determine child delete operations + var stateData *NetflowRsMonitorToExporterResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...) + setNetflowRsMonitorToExporterId(ctx, stateData) + getAndSetNetflowRsMonitorToExporterAttributes(ctx, &resp.Diagnostics, r.client, stateData) + + var data *NetflowRsMonitorToExporterResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + setNetflowRsMonitorToExporterId(ctx, data) + + tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowRsMonitorToExporterResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagNetflowRsMonitorToExporterResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getNetflowRsMonitorToExporterCreateJsonPayload(ctx, &resp.Diagnostics, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { + return + } + + getAndSetNetflowRsMonitorToExporterAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowRsMonitorToExporterResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Start read of resource: aci_relation_to_netflow_exporter") + var data *NetflowRsMonitorToExporterResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Read of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) + + getAndSetNetflowRsMonitorToExporterAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + if data.Id.IsNull() { + var emptyData *NetflowRsMonitorToExporterResourceModel + resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...) + } else { + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + } + + tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowRsMonitorToExporterResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Start update of resource: aci_relation_to_netflow_exporter") + var data *NetflowRsMonitorToExporterResourceModel + var stateData *NetflowRsMonitorToExporterResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + resp.Diagnostics.Append(req.State.Get(ctx, &stateData)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) + + var tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowRsMonitorToExporterResourceModel + data.TagAnnotation.ElementsAs(ctx, &tagAnnotationPlan, false) + stateData.TagAnnotation.ElementsAs(ctx, &tagAnnotationState, false) + var tagTagPlan, tagTagState []TagTagNetflowRsMonitorToExporterResourceModel + data.TagTag.ElementsAs(ctx, &tagTagPlan, false) + stateData.TagTag.ElementsAs(ctx, &tagTagState, false) + jsonPayload := getNetflowRsMonitorToExporterCreateJsonPayload(ctx, &resp.Diagnostics, data, tagAnnotationPlan, tagAnnotationState, tagTagPlan, tagTagState) + + if resp.Diagnostics.HasError() { + return + } + + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + + if resp.Diagnostics.HasError() { + return + } + + getAndSetNetflowRsMonitorToExporterAttributes(ctx, &resp.Diagnostics, r.client, data) + + // Save updated data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowRsMonitorToExporterResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Start delete of resource: aci_relation_to_netflow_exporter") + var data *NetflowRsMonitorToExporterResourceModel + + // Read Terraform prior state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + tflog.Debug(ctx, fmt.Sprintf("Delete of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) + jsonPayload := GetDeleteJsonPayload(ctx, &resp.Diagnostics, "netflowRsMonitorToExporter", data.Id.ValueString()) + if resp.Diagnostics.HasError() { + return + } + DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload) + if resp.Diagnostics.HasError() { + return + } + tflog.Debug(ctx, fmt.Sprintf("End delete of resource aci_relation_to_netflow_exporter with id '%s'", data.Id.ValueString())) +} + +func (r *NetflowRsMonitorToExporterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Start import state of resource: aci_relation_to_netflow_exporter") + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + + var stateData *NetflowRsMonitorToExporterResourceModel + resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...) + tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_relation_to_netflow_exporter with id '%s'", stateData.Id.ValueString())) + + tflog.Debug(ctx, "End import of state resource: aci_relation_to_netflow_exporter") +} + +func getAndSetNetflowRsMonitorToExporterAttributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *NetflowRsMonitorToExporterResourceModel) { + requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "netflowRsMonitorToExporter,tagAnnotation,tagTag"), "GET", nil) + + if diags.HasError() { + return + } + if requestData.Search("imdata").Search("netflowRsMonitorToExporter").Data() != nil { + classReadInfo := requestData.Search("imdata").Search("netflowRsMonitorToExporter").Data().([]interface{}) + if len(classReadInfo) == 1 { + attributes := classReadInfo[0].(map[string]interface{})["attributes"].(map[string]interface{}) + for attributeName, attributeValue := range attributes { + if attributeName == "dn" { + data.Id = basetypes.NewStringValue(attributeValue.(string)) + setNetflowRsMonitorToExporterParentDn(ctx, attributeValue.(string), data) + } + if attributeName == "annotation" { + data.Annotation = basetypes.NewStringValue(attributeValue.(string)) + } + if attributeName == "tnNetflowExporterPolName" { + data.TnNetflowExporterPolName = basetypes.NewStringValue(attributeValue.(string)) + } + } + TagAnnotationNetflowRsMonitorToExporterList := make([]TagAnnotationNetflowRsMonitorToExporterResourceModel, 0) + TagTagNetflowRsMonitorToExporterList := make([]TagTagNetflowRsMonitorToExporterResourceModel, 0) + _, ok := classReadInfo[0].(map[string]interface{})["children"] + if ok { + children := classReadInfo[0].(map[string]interface{})["children"].([]interface{}) + for _, child := range children { + for childClassName, childClassDetails := range child.(map[string]interface{}) { + childAttributes := childClassDetails.(map[string]interface{})["attributes"].(map[string]interface{}) + if childClassName == "tagAnnotation" { + TagAnnotationNetflowRsMonitorToExporter := TagAnnotationNetflowRsMonitorToExporterResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagAnnotationNetflowRsMonitorToExporter.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagAnnotationNetflowRsMonitorToExporter.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagAnnotationNetflowRsMonitorToExporterList = append(TagAnnotationNetflowRsMonitorToExporterList, TagAnnotationNetflowRsMonitorToExporter) + } + if childClassName == "tagTag" { + TagTagNetflowRsMonitorToExporter := TagTagNetflowRsMonitorToExporterResourceModel{} + for childAttributeName, childAttributeValue := range childAttributes { + if childAttributeName == "key" { + TagTagNetflowRsMonitorToExporter.Key = basetypes.NewStringValue(childAttributeValue.(string)) + } + if childAttributeName == "value" { + TagTagNetflowRsMonitorToExporter.Value = basetypes.NewStringValue(childAttributeValue.(string)) + } + } + TagTagNetflowRsMonitorToExporterList = append(TagTagNetflowRsMonitorToExporterList, TagTagNetflowRsMonitorToExporter) + } + } + } + } + tagAnnotationSet, _ := types.SetValueFrom(ctx, data.TagAnnotation.ElementType(ctx), TagAnnotationNetflowRsMonitorToExporterList) + data.TagAnnotation = tagAnnotationSet + tagTagSet, _ := types.SetValueFrom(ctx, data.TagTag.ElementType(ctx), TagTagNetflowRsMonitorToExporterList) + data.TagTag = tagTagSet + } else { + diags.AddError( + "too many results in response", + fmt.Sprintf("%v matches returned for class 'netflowRsMonitorToExporter'. Please report this issue to the provider developers.", len(classReadInfo)), + ) + } + } else { + data.Id = basetypes.NewStringNull() + } +} + +func getNetflowRsMonitorToExporterRn(ctx context.Context, data *NetflowRsMonitorToExporterResourceModel) string { + rn := "rsmonitorToExporter-{tnNetflowExporterPolName}" + for _, identifier := range []string{"tnNetflowExporterPolName"} { + fieldName := fmt.Sprintf("%s%s", strings.ToUpper(identifier[:1]), identifier[1:]) + fieldValue := reflect.ValueOf(data).Elem().FieldByName(fieldName).Interface().(basetypes.StringValue).ValueString() + rn = strings.ReplaceAll(rn, fmt.Sprintf("{%s}", identifier), fieldValue) + } + return rn +} + +func setNetflowRsMonitorToExporterParentDn(ctx context.Context, dn string, data *NetflowRsMonitorToExporterResourceModel) { + bracketIndex := 0 + rnIndex := 0 + for i := len(dn) - 1; i >= 0; i-- { + if string(dn[i]) == "]" { + bracketIndex = bracketIndex + 1 + } else if string(dn[i]) == "[" { + bracketIndex = bracketIndex - 1 + } else if string(dn[i]) == "/" && bracketIndex == 0 { + rnIndex = i + break + } + } + data.ParentDn = basetypes.NewStringValue(dn[:rnIndex]) +} + +func setNetflowRsMonitorToExporterId(ctx context.Context, data *NetflowRsMonitorToExporterResourceModel) { + rn := getNetflowRsMonitorToExporterRn(ctx, data) + data.Id = types.StringValue(fmt.Sprintf("%s/%s", data.ParentDn.ValueString(), rn)) +} + +func getNetflowRsMonitorToExporterTagAnnotationChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowRsMonitorToExporterResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowRsMonitorToExporterResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagAnnotation.IsUnknown() { + tagAnnotationIdentifiers := []TagAnnotationIdentifier{} + for _, tagAnnotation := range tagAnnotationPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagAnnotation.Key.IsUnknown() { + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + } + if !tagAnnotation.Value.IsUnknown() { + childMap["attributes"]["value"] = tagAnnotation.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + tagAnnotationIdentifier := TagAnnotationIdentifier{} + tagAnnotationIdentifier.Key = tagAnnotation.Key + tagAnnotationIdentifiers = append(tagAnnotationIdentifiers, tagAnnotationIdentifier) + } + for _, tagAnnotation := range tagAnnotationState { + delete := true + for _, tagAnnotationIdentifier := range tagAnnotationIdentifiers { + if tagAnnotationIdentifier.Key == tagAnnotation.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagAnnotation.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagAnnotation": childMap}) + } + } + } else { + data.TagAnnotation = types.SetNull(data.TagAnnotation.ElementType(ctx)) + } + + return childPayloads +} +func getNetflowRsMonitorToExporterTagTagChildPayloads(ctx context.Context, diags *diag.Diagnostics, data *NetflowRsMonitorToExporterResourceModel, tagTagPlan, tagTagState []TagTagNetflowRsMonitorToExporterResourceModel) []map[string]interface{} { + + childPayloads := []map[string]interface{}{} + if !data.TagTag.IsUnknown() { + tagTagIdentifiers := []TagTagIdentifier{} + for _, tagTag := range tagTagPlan { + childMap := map[string]map[string]interface{}{"attributes": {}} + if !tagTag.Key.IsUnknown() { + childMap["attributes"]["key"] = tagTag.Key.ValueString() + } + if !tagTag.Value.IsUnknown() { + childMap["attributes"]["value"] = tagTag.Value.ValueString() + } + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + tagTagIdentifier := TagTagIdentifier{} + tagTagIdentifier.Key = tagTag.Key + tagTagIdentifiers = append(tagTagIdentifiers, tagTagIdentifier) + } + for _, tagTag := range tagTagState { + delete := true + for _, tagTagIdentifier := range tagTagIdentifiers { + if tagTagIdentifier.Key == tagTag.Key { + delete = false + break + } + } + if delete { + childMap := map[string]map[string]interface{}{"attributes": {}} + childMap["attributes"]["status"] = "deleted" + childMap["attributes"]["key"] = tagTag.Key.ValueString() + childPayloads = append(childPayloads, map[string]interface{}{"tagTag": childMap}) + } + } + } else { + data.TagTag = types.SetNull(data.TagTag.ElementType(ctx)) + } + + return childPayloads +} + +func getNetflowRsMonitorToExporterCreateJsonPayload(ctx context.Context, diags *diag.Diagnostics, data *NetflowRsMonitorToExporterResourceModel, tagAnnotationPlan, tagAnnotationState []TagAnnotationNetflowRsMonitorToExporterResourceModel, tagTagPlan, tagTagState []TagTagNetflowRsMonitorToExporterResourceModel) *container.Container { + payloadMap := map[string]interface{}{} + payloadMap["attributes"] = map[string]string{} + childPayloads := []map[string]interface{}{} + + TagAnnotationchildPayloads := getNetflowRsMonitorToExporterTagAnnotationChildPayloads(ctx, diags, data, tagAnnotationPlan, tagAnnotationState) + if TagAnnotationchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagAnnotationchildPayloads...) + + TagTagchildPayloads := getNetflowRsMonitorToExporterTagTagChildPayloads(ctx, diags, data, tagTagPlan, tagTagState) + if TagTagchildPayloads == nil { + return nil + } + childPayloads = append(childPayloads, TagTagchildPayloads...) + + payloadMap["children"] = childPayloads + if !data.Annotation.IsNull() && !data.Annotation.IsUnknown() { + payloadMap["attributes"].(map[string]string)["annotation"] = data.Annotation.ValueString() + } + if !data.TnNetflowExporterPolName.IsNull() && !data.TnNetflowExporterPolName.IsUnknown() { + payloadMap["attributes"].(map[string]string)["tnNetflowExporterPolName"] = data.TnNetflowExporterPolName.ValueString() + } + + payload, err := json.Marshal(map[string]interface{}{"netflowRsMonitorToExporter": payloadMap}) + if err != nil { + diags.AddError( + "Marshalling of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + + jsonPayload, err := container.ParseJSON(payload) + + if err != nil { + diags.AddError( + "Construction of json payload failed", + fmt.Sprintf("Err: %s. Please report this issue to the provider developers.", err), + ) + return nil + } + return jsonPayload +} diff --git a/internal/provider/resource_aci_relation_to_netflow_exporter_test.go b/internal/provider/resource_aci_relation_to_netflow_exporter_test.go new file mode 100644 index 000000000..d913e16f1 --- /dev/null +++ b/internal/provider/resource_aci_relation_to_netflow_exporter_test.go @@ -0,0 +1,224 @@ +// Code generated by "gen/generator.go"; DO NOT EDIT. +// In order to regenerate this file execute `go generate` from the repository root. +// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md). + +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAccResourceNetflowRsMonitorToExporterWithNetflowMonitorPol(t *testing.T) { + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Create with minimum config and verify default APIC values + { + Config: testConfigNetflowRsMonitorToExporterMinDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + ), + }, + // Update with all config and verify default APIC values + { + Config: testConfigNetflowRsMonitorToExporterAllDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "annotation"), + ), + }, + // Update with minimum config and verify config is unchanged + { + Config: testConfigNetflowRsMonitorToExporterMinDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + ), + }, + // Update with empty strings config or default value + { + Config: testConfigNetflowRsMonitorToExporterResetDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + ), + }, + // Import testing + { + ResourceName: "aci_relation_to_netflow_exporter.test", + ImportState: true, + ImportStateVerify: true, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + ), + }, + // Update with children + { + Config: testConfigNetflowRsMonitorToExporterChildrenDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.value", "value_2"), + ), + }, + // Import testing with children + { + ResourceName: "aci_relation_to_netflow_exporter.test", + ImportState: true, + ImportStateVerify: true, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "netflow_exporter_policy_name", "test_tn_netflow_exporter_pol_name"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotation", "orchestrator:terraform"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.value", "value_2"), + ), + }, + // Update with children removed from config + { + Config: testConfigNetflowRsMonitorToExporterChildrenRemoveFromConfigDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.#", "2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.key", "key_0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.value", "value_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.1.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.#", "2"), + ), + }, + // Update with children first child removed + { + Config: testConfigNetflowRsMonitorToExporterChildrenRemoveOneDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.0.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.#", "1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.key", "key_1"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.0.value", "value_2"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.#", "1"), + ), + }, + // Update with all children removed + { + Config: testConfigNetflowRsMonitorToExporterChildrenRemoveAllDependencyWithNetflowMonitorPol, + ExpectNonEmptyPlan: false, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "annotations.#", "0"), + resource.TestCheckResourceAttr("aci_relation_to_netflow_exporter.test", "tags.#", "0"), + ), + }, + }, + }) +} + +const testConfigNetflowRsMonitorToExporterMinDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" +} +` + +const testConfigNetflowRsMonitorToExporterAllDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + annotation = "annotation" +} +` + +const testConfigNetflowRsMonitorToExporterResetDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + annotation = "orchestrator:terraform" +} +` +const testConfigNetflowRsMonitorToExporterChildrenDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + annotations = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "value_2" + }, + ] + tags = [ + { + key = "key_0" + value = "value_1" + }, + { + key = "key_1" + value = "value_2" + }, + ] +} +` + +const testConfigNetflowRsMonitorToExporterChildrenRemoveFromConfigDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" +} +` + +const testConfigNetflowRsMonitorToExporterChildrenRemoveOneDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + annotations = [ + { + key = "key_1" + value = "value_2" + }, + ] + tags = [ + { + key = "key_1" + value = "value_2" + }, + ] +} +` + +const testConfigNetflowRsMonitorToExporterChildrenRemoveAllDependencyWithNetflowMonitorPol = testConfigNetflowMonitorPolMinDependencyWithFvTenant + ` +resource "aci_relation_to_netflow_exporter" "test" { + parent_dn = aci_netflow_monitor_policy.test.id + netflow_exporter_policy_name = "test_tn_netflow_exporter_pol_name" + annotations = [] + tags = [] +} +` diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/all.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/all.go new file mode 100644 index 000000000..a160764cb --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/all.go @@ -0,0 +1,57 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// All returns a validator which ensures that any configured attribute value +// attribute value validates against all the given validators. +// +// Use of All is only necessary when used in conjunction with Any or AnyWithAllWarnings +// as the Validators field automatically applies a logical AND. +func All(validators ...validator.Set) validator.Set { + return allValidator{ + validators: validators, + } +} + +var _ validator.Set = allValidator{} + +// allValidator implements the validator. +type allValidator struct { + validators []validator.Set +} + +// Description describes the validation in plain text formatting. +func (v allValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy all of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v allValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v allValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + for _, subValidator := range v.validators { + validateResp := &validator.SetResponse{} + + subValidator.ValidateSet(ctx, req, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/also_requires.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/also_requires.go new file mode 100644 index 000000000..a505b2d11 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/also_requires.go @@ -0,0 +1,26 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AlsoRequires checks that a set of path.Expression has a non-null value, +// if the current attribute or block also has a non-null value. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.RequiredTogether], +// [providervalidator.RequiredTogether], or [resourcevalidator.RequiredTogether] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute or block +// being validated. +func AlsoRequires(expressions ...path.Expression) validator.Set { + return schemavalidator.AlsoRequiresValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any.go new file mode 100644 index 000000000..387ca8651 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// Any returns a validator which ensures that any configured attribute value +// passes at least one of the given validators. +// +// To prevent practitioner confusion should non-passing validators have +// conflicting logic, only warnings from the passing validator are returned. +// Use AnyWithAllWarnings() to return warnings from non-passing validators +// as well. +func Any(validators ...validator.Set) validator.Set { + return anyValidator{ + validators: validators, + } +} + +var _ validator.Set = anyValidator{} + +// anyValidator implements the validator. +type anyValidator struct { + validators []validator.Set +} + +// Description describes the validation in plain text formatting. +func (v anyValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy at least one of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v anyValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v anyValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + for _, subValidator := range v.validators { + validateResp := &validator.SetResponse{} + + subValidator.ValidateSet(ctx, req, validateResp) + + if !validateResp.Diagnostics.HasError() { + resp.Diagnostics = validateResp.Diagnostics + + return + } + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any_with_all_warnings.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any_with_all_warnings.go new file mode 100644 index 000000000..e0c534e62 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/any_with_all_warnings.go @@ -0,0 +1,67 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AnyWithAllWarnings returns a validator which ensures that any configured +// attribute value passes at least one of the given validators. This validator +// returns all warnings, including failed validators. +// +// Use Any() to return warnings only from the passing validator. +func AnyWithAllWarnings(validators ...validator.Set) validator.Set { + return anyWithAllWarningsValidator{ + validators: validators, + } +} + +var _ validator.Set = anyWithAllWarningsValidator{} + +// anyWithAllWarningsValidator implements the validator. +type anyWithAllWarningsValidator struct { + validators []validator.Set +} + +// Description describes the validation in plain text formatting. +func (v anyWithAllWarningsValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy at least one of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v anyWithAllWarningsValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v anyWithAllWarningsValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + anyValid := false + + for _, subValidator := range v.validators { + validateResp := &validator.SetResponse{} + + subValidator.ValidateSet(ctx, req, validateResp) + + if !validateResp.Diagnostics.HasError() { + anyValid = true + } + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } + + if anyValid { + resp.Diagnostics = resp.Diagnostics.Warnings() + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/at_least_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/at_least_one_of.go new file mode 100644 index 000000000..7ff7edabc --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/at_least_one_of.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AtLeastOneOf checks that of a set of path.Expression, +// including the attribute or block this validator is applied to, +// at least one has a non-null value. +// +// This implements the validation logic declaratively within the tfsdk.Schema. +// Refer to [datasourcevalidator.AtLeastOneOf], +// [providervalidator.AtLeastOneOf], or [resourcevalidator.AtLeastOneOf] +// for declaring this type of validation outside the schema definition. +// +// Any relative path.Expression will be resolved using the attribute or block +// being validated. +func AtLeastOneOf(expressions ...path.Expression) validator.Set { + return schemavalidator.AtLeastOneOfValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/conflicts_with.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/conflicts_with.go new file mode 100644 index 000000000..54792664a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/conflicts_with.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// ConflictsWith checks that a set of path.Expression, +// including the attribute or block the validator is applied to, +// do not have a value simultaneously. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.Conflicting], +// [providervalidator.Conflicting], or [resourcevalidator.Conflicting] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute or block +// being validated. +func ConflictsWith(expressions ...path.Expression) validator.Set { + return schemavalidator.ConflictsWithValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/doc.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/doc.go new file mode 100644 index 000000000..258a0db5a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/doc.go @@ -0,0 +1,5 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Package setvalidator provides validators for types.Set attributes. +package setvalidator diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/exactly_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/exactly_one_of.go new file mode 100644 index 000000000..b48408d7b --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/exactly_one_of.go @@ -0,0 +1,28 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// ExactlyOneOf checks that of a set of path.Expression, +// including the attribute or block the validator is applied to, +// one and only one attribute has a value. +// It will also cause a validation error if none are specified. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.ExactlyOneOf], +// [providervalidator.ExactlyOneOf], or [resourcevalidator.ExactlyOneOf] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute or block +// being validated. +func ExactlyOneOf(expressions ...path.Expression) validator.Set { + return schemavalidator.ExactlyOneOfValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/is_required.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/is_required.go new file mode 100644 index 000000000..63564c5c2 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/is_required.go @@ -0,0 +1,44 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Set = isRequiredValidator{} + +// isRequiredValidator validates that a set has a configuration value. +type isRequiredValidator struct{} + +// Description describes the validation in plain text formatting. +func (v isRequiredValidator) Description(_ context.Context) string { + return "must have a configuration value as the provider has marked it as required" +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v isRequiredValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v isRequiredValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() { + resp.Diagnostics.Append(validatordiag.InvalidBlockDiagnostic( + req.Path, + v.Description(ctx), + )) + } +} + +// IsRequired returns a validator which ensures that any configured set has a value (not null). +// +// This validator is equivalent to the `Required` field on attributes and is only +// practical for use with `schema.SetNestedBlock` +func IsRequired() validator.Set { + return isRequiredValidator{} +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_least.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_least.go new file mode 100644 index 000000000..d010b8585 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_least.go @@ -0,0 +1,59 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Set = sizeAtLeastValidator{} + +// sizeAtLeastValidator validates that set contains at least min elements. +type sizeAtLeastValidator struct { + min int +} + +// Description describes the validation in plain text formatting. +func (v sizeAtLeastValidator) Description(_ context.Context) string { + return fmt.Sprintf("set must contain at least %d elements", v.min) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v sizeAtLeastValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v sizeAtLeastValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + elems := req.ConfigValue.Elements() + + if len(elems) < v.min { + resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( + req.Path, + v.Description(ctx), + fmt.Sprintf("%d", len(elems)), + )) + } +} + +// SizeAtLeast returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at least min elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func SizeAtLeast(min int) validator.Set { + return sizeAtLeastValidator{ + min: min, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_most.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_most.go new file mode 100644 index 000000000..4479f5970 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_at_most.go @@ -0,0 +1,59 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Set = sizeAtMostValidator{} + +// sizeAtMostValidator validates that set contains at most max elements. +type sizeAtMostValidator struct { + max int +} + +// Description describes the validation in plain text formatting. +func (v sizeAtMostValidator) Description(_ context.Context) string { + return fmt.Sprintf("set must contain at most %d elements", v.max) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v sizeAtMostValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v sizeAtMostValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + elems := req.ConfigValue.Elements() + + if len(elems) > v.max { + resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( + req.Path, + v.Description(ctx), + fmt.Sprintf("%d", len(elems)), + )) + } +} + +// SizeAtMost returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at most max elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func SizeAtMost(max int) validator.Set { + return sizeAtMostValidator{ + max: max, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_between.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_between.go new file mode 100644 index 000000000..15945a7bc --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/size_between.go @@ -0,0 +1,62 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.Set = sizeBetweenValidator{} + +// sizeBetweenValidator validates that set contains at least min elements +// and at most max elements. +type sizeBetweenValidator struct { + min int + max int +} + +// Description describes the validation in plain text formatting. +func (v sizeBetweenValidator) Description(_ context.Context) string { + return fmt.Sprintf("set must contain at least %d elements and at most %d elements", v.min, v.max) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v sizeBetweenValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v sizeBetweenValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + elems := req.ConfigValue.Elements() + + if len(elems) < v.min || len(elems) > v.max { + resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( + req.Path, + v.Description(ctx), + fmt.Sprintf("%d", len(elems)), + )) + } +} + +// SizeBetween returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a Set. +// - Contains at least min elements and at most max elements. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func SizeBetween(min, max int) validator.Set { + return sizeBetweenValidator{ + min: min, + max: max, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_float64s_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_float64s_are.go new file mode 100644 index 000000000..04140b8c6 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_float64s_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueFloat64sAre returns an validator which ensures that any configured +// Float64 values passes each Float64 validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueFloat64sAre(elementValidators ...validator.Float64) validator.Set { + return valueFloat64sAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueFloat64sAreValidator{} + +// valueFloat64sAreValidator validates that each Float64 member validates against each of the value validators. +type valueFloat64sAreValidator struct { + elementValidators []validator.Float64 +} + +// Description describes the validation in plain text formatting. +func (v valueFloat64sAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueFloat64sAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateFloat64 performs the validation. +func (v valueFloat64sAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.Float64Typable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Float64 values validator, however its values do not implement types.Float64Type or the types.Float64Typable interface for custom Float64 types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.Float64Valuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Float64 values validator, however its values do not implement types.Float64Type or the types.Float64Typable interface for custom Float64 types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToFloat64Value(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.Float64Request{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.Float64Response{} + + elementValidator.ValidateFloat64(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_int64s_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_int64s_are.go new file mode 100644 index 000000000..37cf6c271 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_int64s_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueInt64sAre returns an validator which ensures that any configured +// Int64 values passes each Int64 validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueInt64sAre(elementValidators ...validator.Int64) validator.Set { + return valueInt64sAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueInt64sAreValidator{} + +// valueInt64sAreValidator validates that each Int64 member validates against each of the value validators. +type valueInt64sAreValidator struct { + elementValidators []validator.Int64 +} + +// Description describes the validation in plain text formatting. +func (v valueInt64sAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueInt64sAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateInt64 performs the validation. +func (v valueInt64sAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.Int64Typable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Int64 values validator, however its values do not implement types.Int64Type or the types.Int64Typable interface for custom Int64 types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.Int64Valuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Int64 values validator, however its values do not implement types.Int64Type or the types.Int64Typable interface for custom Int64 types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToInt64Value(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.Int64Request{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.Int64Response{} + + elementValidator.ValidateInt64(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_lists_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_lists_are.go new file mode 100644 index 000000000..3f54b37e3 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_lists_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueListsAre returns an validator which ensures that any configured +// List values passes each List validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueListsAre(elementValidators ...validator.List) validator.Set { + return valueListsAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueListsAreValidator{} + +// valueListsAreValidator validates that each set member validates against each of the value validators. +type valueListsAreValidator struct { + elementValidators []validator.List +} + +// Description describes the validation in plain text formatting. +func (v valueListsAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueListsAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v valueListsAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.ListTypable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a List values validator, however its values do not implement types.ListType or the types.ListTypable interface for custom List types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.ListValuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a List values validator, however its values do not implement types.ListType or the types.ListTypable interface for custom List types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToListValue(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.ListRequest{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.ListResponse{} + + elementValidator.ValidateList(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_maps_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_maps_are.go new file mode 100644 index 000000000..19328be47 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_maps_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueMapsAre returns an validator which ensures that any configured +// Map values passes each Map validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueMapsAre(elementValidators ...validator.Map) validator.Set { + return valueMapsAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueMapsAreValidator{} + +// valueMapsAreValidator validates that each set member validates against each of the value validators. +type valueMapsAreValidator struct { + elementValidators []validator.Map +} + +// Description describes the validation in plain text formatting. +func (v valueMapsAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueMapsAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v valueMapsAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.MapTypable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Map values validator, however its values do not implement types.MapType or the types.MapTypable interface for custom Map types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.MapValuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Map values validator, however its values do not implement types.MapType or the types.MapTypable interface for custom Map types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToMapValue(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.MapRequest{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.MapResponse{} + + elementValidator.ValidateMap(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_numbers_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_numbers_are.go new file mode 100644 index 000000000..abcc496ae --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_numbers_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueNumbersAre returns an validator which ensures that any configured +// Number values passes each Number validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueNumbersAre(elementValidators ...validator.Number) validator.Set { + return valueNumbersAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueNumbersAreValidator{} + +// valueNumbersAreValidator validates that each Number member validates against each of the value validators. +type valueNumbersAreValidator struct { + elementValidators []validator.Number +} + +// Description describes the validation in plain text formatting. +func (v valueNumbersAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueNumbersAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateNumber performs the validation. +func (v valueNumbersAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.NumberTypable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Number values validator, however its values do not implement types.NumberType or the types.NumberTypable interface for custom Number types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.NumberValuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Number values validator, however its values do not implement types.NumberType or the types.NumberTypable interface for custom Number types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToNumberValue(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.NumberRequest{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.NumberResponse{} + + elementValidator.ValidateNumber(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_sets_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_sets_are.go new file mode 100644 index 000000000..023582a04 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_sets_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueSetsAre returns an validator which ensures that any configured +// Set values passes each Set validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueSetsAre(elementValidators ...validator.Set) validator.Set { + return valueSetsAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueSetsAreValidator{} + +// valueSetsAreValidator validates that each set member validates against each of the value validators. +type valueSetsAreValidator struct { + elementValidators []validator.Set +} + +// Description describes the validation in plain text formatting. +func (v valueSetsAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueSetsAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v valueSetsAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.SetTypable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Set values validator, however its values do not implement types.SetType or the types.SetTypable interface for custom Set types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.SetValuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a Set values validator, however its values do not implement types.SetType or the types.SetTypable interface for custom Set types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToSetValue(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.SetRequest{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.SetResponse{} + + elementValidator.ValidateSet(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_strings_are.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_strings_are.go new file mode 100644 index 000000000..38b4b7815 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/setvalidator/value_strings_are.go @@ -0,0 +1,119 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package setvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" +) + +// ValueStringsAre returns an validator which ensures that any configured +// String values passes each String validator. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +func ValueStringsAre(elementValidators ...validator.String) validator.Set { + return valueStringsAreValidator{ + elementValidators: elementValidators, + } +} + +var _ validator.Set = valueStringsAreValidator{} + +// valueStringsAreValidator validates that each set member validates against each of the value validators. +type valueStringsAreValidator struct { + elementValidators []validator.String +} + +// Description describes the validation in plain text formatting. +func (v valueStringsAreValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, elementValidator := range v.elementValidators { + descriptions = append(descriptions, elementValidator.Description(ctx)) + } + + return fmt.Sprintf("element value must satisfy all validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v valueStringsAreValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateSet performs the validation. +func (v valueStringsAreValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { + return + } + + _, ok := req.ConfigValue.ElementType(ctx).(basetypes.StringTypable) + + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Type", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a String values validator, however its values do not implement types.StringType or the types.StringTypable interface for custom String types. "+ + "Use the appropriate values validator that matches the element type. "+ + "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx)), + ) + + return + } + + for _, element := range req.ConfigValue.Elements() { + elementPath := req.Path.AtSetValue(element) + + elementValuable, ok := element.(basetypes.StringValuable) + + // The check above should have prevented this, but raise an error + // instead of a type assertion panic or skipping the element. Any issue + // here likely indicates something wrong in the framework itself. + if !ok { + resp.Diagnostics.AddAttributeError( + req.Path, + "Invalid Validator for Element Value", + "While performing schema-based validation, an unexpected error occurred. "+ + "The attribute declares a String values validator, however its values do not implement types.StringType or the types.StringTypable interface for custom String types. "+ + "This is likely an issue with terraform-plugin-framework and should be reported to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", req.Path.String())+ + fmt.Sprintf("Element Type: %T\n", req.ConfigValue.ElementType(ctx))+ + fmt.Sprintf("Element Value Type: %T\n", element), + ) + + return + } + + elementValue, diags := elementValuable.ToStringValue(ctx) + + resp.Diagnostics.Append(diags...) + + // Only return early if the new diagnostics indicate an issue since + // it likely will be the same for all elements. + if diags.HasError() { + return + } + + elementReq := validator.StringRequest{ + Path: elementPath, + PathExpression: elementPath.Expression(), + ConfigValue: elementValue, + Config: req.Config, + } + + for _, elementValidator := range v.elementValidators { + elementResp := &validator.StringResponse{} + + elementValidator.ValidateString(ctx, elementReq, elementResp) + + resp.Diagnostics.Append(elementResp.Diagnostics...) + } + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index cc7727536..09fd5f33f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -180,6 +180,7 @@ github.com/hashicorp/terraform-plugin-framework/types/basetypes ## explicit; go 1.19 github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator +github.com/hashicorp/terraform-plugin-framework-validators/setvalidator github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator # github.com/hashicorp/terraform-plugin-go v0.22.1 ## explicit; go 1.21