diff --git a/CHANGELOG.md b/CHANGELOG.md index 22735d8e4..d6773f1eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,50 @@ # RELEASE NOTES +## 5.2.0 (Aug 29, 2023) + +#### FEATURES/ENHANCEMENTS: + +* [IMPORTANT] Cloud Wrapper + * Added resources: + * `akamai_cloudwrapper_activation` - activate cloud wrapper configuration, import cloud wrapper configuration activation + * `akamai_cloudwrapper_configuration` - create, read and update cloud wrapper configuration + * Added data sources: + * `akamai_cloudwrapper_capacities` - reads capacities available for the provided contract IDs + * `akamai_cloudwrapper_configuration` - reads configuration associated with config ID + * `akamai_cloudwrapper_configurations` - reads all the configurations + * `akamai_cloudwrapper_location` - reads location for given location name and traffic type + * `akamai_cloudwrapper_locations` - reads all locations + * `akamai_cloudwrapper_properties` - reads properties associated with contract IDs with Cloud Wrapper entitlement + +* [IMPORTANT] Client Lists + * Added resources: + * `akamai_clientlist_list` - create, update and delete Client Lists + * `akamai_clientlist_activation` - activate a client list + * Added data source: + * `akamai_clientlist_lists` - reads Client Lists + * Support filter by `name` and/or `types` + +* BOTMAN + * Added resource: + * `akamai_botman_custom_client_sequence` - read and update custom client sequence + * Added data source: + * `akamai_botman_custom_client_sequence` - reads custom client sequence + +* PAPI + * `logStreamName` field from `datastream` behavior has changed from string to array of strings for rule format `v2023-05-30` + ## 5.1.0 (Aug 01, 2023) #### BUG FIXES: * PAPI * Dropped too strict early snippet validation ([#436](https://github.com/akamai/terraform-provider-akamai/issues/436)) - * Fixed issue that `akamai_property` or `akamai_property_include` would sometimes show strange `null -> null` diff in `rules` (or dropping `null` in newer Terraform versions) even if no update actually is needed. If there is anything else changing in the rule tree, the `null -> null` will be also visible in the diff. That may be fixed in later time. - * Fixed issue that `akamai_property_rules_builder` data source did not support PM variables for fields with validation based on regular expressions + * Fixed issue that `akamai_property` or `akamai_property_include` would sometimes show strange `null -> null` diff + in `rules` (or dropping `null` in newer Terraform versions) even if no update actually is needed. If there is + anything else changing in the rule tree, the `null -> null` will be also visible in the diff. That may be fixed in + later time. + * Fixed issue that `akamai_property_rules_builder` data source did not support PM variables for fields with validation + based on regular expressions #### FEATURES/ENHANCEMENTS: @@ -56,9 +93,9 @@ * Changed the following data sources in DataStream 2 V2 API: * `akamai_datastream_activation_history` - changed schema and corresponding implementations. * `akamai_datastream_dataset_fields` - changed parameter, schema and corresponding implementations. - * `akamai_datastreams` - changed parameter, schema and corresponding implementations. + * `akamai_datastreams` - changed parameter, schema and corresponding implementations. * Changed the following resources in DataStream 2 V2 API: - * `akamai_datastreams` - changed in schema payload, response attributes and corresponding implementations. + * `akamai_datastreams` - changed in schema payload, response attributes and corresponding implementations. * Updated attribute names in `datastream.connectors`. * Updated methods in `datastream.stream` for the above changes. @@ -76,7 +113,7 @@ * CPS * `enable_multi_stacked_certificates` field in `akamai_cps_dv_enrollment` resource - + * DNS * `dns_section` and `dns` fields in provider schema @@ -154,7 +191,7 @@ * Appsec * Update malware policy `ContentTypes` to include `EncodedContentAttributes`. * Malware policy's `ContentTypes` is reported as part of an individual policy but is no longer included in the bulk report of all policies. - + * PAPI * Remove `cpc_` prefix in `akamai_cp_code` resource and data source IDs @@ -189,7 +226,7 @@ * Fixed bug related to regex validation for handling property delay in `akamai_cloudlets_policy_activation` * Fixed sporadic issue with `akamai_cloudlets_policy_activation` due to network delay -* PAPI +* PAPI * Fixed reading float values in `akamai_property_rules_builder` * Add validation for hostnames `cname_from` field in `akamai_property` resource * Assign only active property activation version in `akamai_property_activation` resource on read @@ -302,7 +339,7 @@ * GTM * Fixed diff in resources: - * `resource_akamai_gtm_asmap` for field `assignment.as_numbers` + * `resource_akamai_gtm_asmap` for field `assignment.as_numbers` * `resource_akamai_gtm_cidrmap` for field `assignment.blocks` * `resource_akamai_gtm_geomap` for field `assignment.countries` * `resource_akamai_gtm_domain` for field `email_notification_list` @@ -921,7 +958,7 @@ #### BREAKING CHANGES: * PAPI - `resource_akamai_property:` Changed hostnames field to a block type syntax to support additional user inputs. Refer to [Property Resource](docs/resources/property.md) for new syntax. -**Important Note** +**Important Note** Existing terraform users with hostnames defined in older syntax need to manually fix their hostnames configuration and existing state if needed. Additional info in [Property Resource](docs/resources/property.md) #### BUG FIXES: diff --git a/GNUmakefile b/GNUmakefile index 0068c03d5..4043fc663 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -31,7 +31,7 @@ check: fmtcheck lint vet .PHONY: test test: - go test $(TEST) -v $(TESTARGS) -timeout 20m 2>&1 + go test $(TEST) -v $(TESTARGS) -timeout 30m 2>&1 .PHONY: testacc testacc: diff --git a/docs/data-sources/data-sources.md b/docs/data-sources/data-sources.md index b5c791e6b..500b24d1c 100644 --- a/docs/data-sources/data-sources.md +++ b/docs/data-sources/data-sources.md @@ -8,15 +8,17 @@ We’ve moved our documentation to the Akamai TechDocs site. Use the table to fi | Subprovider | Description | |---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| -| [Application Security](https://techdocs.akamai.com/terraform/v5.1/docs/appsec-datasources) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | -| [Bot Manager](https://techdocs.akamai.com/terraform/v5.1/docs/botman-datasources) | Identify, track, and respond to bot activity on your domain or in your app. | -| [Certificates](https://techdocs.akamai.com/terraform/v5.1/docs/cps-datasources) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | -| [Cloudlets](https://techdocs.akamai.com/terraform/v5.1/docs/cl-datasources) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | -| [DataStream](https://techdocs.akamai.com/terraform/v5.1/docs/ds-datasources) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | -| [Edge DNS](https://techdocs.akamai.com/terraform/v5.1/docs/edns-datasources) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | -| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.1/docs/ew-datasources) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | -| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.1/docs/gtm-datasources) | Use load balancing to manage website and mobile performance demands. | -| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.1/docs/iam-datasources) | Create users and groups, and define policies that manage access to your Akamai applications. | -| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.1/docs/ivm-datasources) | Automate image and video delivery optimizations for your website visitors. | -| [Network Lists](https://techdocs.akamai.com/terraform/v5.1/docs/nl-datasources) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | -| [Property](https://techdocs.akamai.com/terraform/v5.1/docs/pm-datasources) | Define rules and behaviors that govern your website delivery based on match criteria. | +| [Application Security](https://techdocs.akamai.com/terraform/v5.2/docs/appsec-datasources) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | +| [Bot Manager](https://techdocs.akamai.com/terraform/v5.2/docs/botman-datasources) | Identify, track, and respond to bot activity on your domain or in your app. | +| [Certificates](https://techdocs.akamai.com/terraform/v5.2/docs/cps-datasources) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | +| [Client Lists](https://techdocs.akamai.com/terraform/v5.2/docs/cli-data-sources) | Reduce harmful security attacks by allowing only trusted IP/CIDRs, locations, autonomous system numbers, and TLS fingerprints to access your services and content.| +| [Cloud Wrapper](https://techdocs.akamai.com/terraform/v5.2/docs/cw-data-sources) | Provide your customers with a more consistent user experience by adding a custom caching layer that improves the connection between your cloud infrastructure and the Akamai platform.| +| [Cloudlets](https://techdocs.akamai.com/terraform/v5.2/docs/cl-datasources) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | +| [DataStream](https://techdocs.akamai.com/terraform/v5.2/docs/ds-datasources) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | +| [Edge DNS](https://techdocs.akamai.com/terraform/v5.2/docs/edns-datasources) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | +| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.2/docs/ew-datasources) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | +| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.2/docs/gtm-datasources) | Use load balancing to manage website and mobile performance demands. | +| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.2/docs/iam-datasources) | Create users and groups, and define policies that manage access to your Akamai applications. | +| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.2/docs/ivm-datasources) | Automate image and video delivery optimizations for your website visitors. | +| [Network Lists](https://techdocs.akamai.com/terraform/v5.2/docs/nl-datasources) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | +| [Property](https://techdocs.akamai.com/terraform/v5.2/docs/pm-datasources) | Define rules and behaviors that govern your website delivery based on match criteria. | diff --git a/docs/guides/get-started.md b/docs/guides/get-started.md index e2401bd73..eba134bde 100644 --- a/docs/guides/get-started.md +++ b/docs/guides/get-started.md @@ -21,7 +21,7 @@ Your Akamai Terraform configuration starts with listing us as a required provide required_providers { akamai = { source = "akamai/akamai" - version = "5.1.0" + version = "5.2.0" } } } @@ -99,18 +99,20 @@ Use the table to find information about the subprovider you’re using. | Subprovider | Description | |----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| -| [Application Security](https://techdocs.akamai.com/terraform/v5.1/docs/configure-appsec) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | -| [Bot Manager](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-botman) | Identify, track, and respond to bot activity on your domain or in your app. | -| [Certificates](https://techdocs.akamai.com/terraform/v5.1/docs/cps-integration-guide) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | -| [Cloudlets](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-cloudlets) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | -| [DataStream](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-datastream) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | -| [Edge DNS](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-edgedns) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | -| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-edgeworkers) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | -| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-gtm) | Use load balancing to manage website and mobile performance demands. | -| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-iam) | Create users and groups, and define policies that manage access to your Akamai applications. | -| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-ivm) | Automate image and video delivery optimizations for your website visitors. | -| [Network Lists](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-network-lists) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | -| [Property](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-property-provisioning) | Define rules and behaviors that govern your website delivery based on match criteria. | +| [Application Security](https://techdocs.akamai.com/terraform/v5.2/docs/configure-appsec) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | +| [Bot Manager](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-botman) | Identify, track, and respond to bot activity on your domain or in your app. | +| [Certificates](https://techdocs.akamai.com/terraform/v5.2/docs/cps-integration-guide) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | +| [Client Lists](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-client-lists) | Reduce harmful security attacks by allowing only trusted IP/CIDRs, locations, autonomous system numbers, and TLS fingerprints to access your services and content.| +| [Cloud Wrapper](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-cloud-wrapper) | Provide your customers with a more consistent user experience by adding a custom caching layer that improves the connection between your cloud infrastructure and the Akamai platform.| +| [Cloudlets](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-cloudlets) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | +| [DataStream](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-datastream) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | +| [Edge DNS](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-edgedns) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | +| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-edgeworkers) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | +| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-gtm) | Use load balancing to manage website and mobile performance demands. | +| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-iam) | Create users and groups, and define policies that manage access to your Akamai applications. | +| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-ivm) | Automate image and video delivery optimizations for your website visitors. | +| [Network Lists](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-network-lists) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | +| [Property](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-property-provisioning) | Define rules and behaviors that govern your website delivery based on match criteria. | ### Get contract and group IDs diff --git a/docs/index.md b/docs/index.md index 8ff578701..61ed6fb6b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -35,18 +35,20 @@ We’ve moved our documentation to the Akamai TechDocs site. Use the table to fi | Subprovider | Description | |----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| -| [Application Security](https://techdocs.akamai.com/terraform/v5.1/docs/configure-appsec) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | -| [Bot Manager](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-botman) | Identify, track, and respond to bot activity on your domain or in your app. | -| [Certificates](https://techdocs.akamai.com/terraform/v5.1/docs/cps-integration-guide) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | -| [Cloudlets](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-cloudlets) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | -| [DataStream](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-datastream) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | -| [Edge DNS](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-edgedns) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | -| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-edgeworkers) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | -| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-gtm) | Use load balancing to manage website and mobile performance demands. | -| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-iam) | Create users and groups, and define policies that manage access to your Akamai applications. | -| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-ivm) | Automate image and video delivery optimizations for your website visitors. | -| [Network Lists](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-network-lists) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | -| [Property](https://techdocs.akamai.com/terraform/v5.1/docs/set-up-property-provisioning) | Define rules and behaviors that govern your website delivery based on match criteria. | +| [Application Security](https://techdocs.akamai.com/terraform/v5.2/docs/configure-appsec) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | +| [Bot Manager](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-botman) | Identify, track, and respond to bot activity on your domain or in your app. | +| [Certificates](https://techdocs.akamai.com/terraform/v5.2/docs/cps-integration-guide) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | +| [Client Lists](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-client-lists) | Reduce harmful security attacks by allowing only trusted IP/CIDRs, locations, autonomous system numbers, and TLS fingerprints to access your services and content.| +| [Cloud Wrapper](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-cloud-wrapper) | Provide your customers with a more consistent user experience by adding a custom caching layer that improves the connection between your cloud infrastructure and the Akamai platform.| +| [Cloudlets](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-cloudlets) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | +| [DataStream](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-datastream) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | +| [Edge DNS](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-edgedns) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | +| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-edgeworkers) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | +| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-gtm) | Use load balancing to manage website and mobile performance demands. | +| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-iam) | Create users and groups, and define policies that manage access to your Akamai applications. | +| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-ivm) | Automate image and video delivery optimizations for your website visitors. | +| [Network Lists](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-network-lists) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | +| [Property](https://techdocs.akamai.com/terraform/v5.2/docs/set-up-property-provisioning) | Define rules and behaviors that govern your website delivery based on match criteria. | ## Links to resources diff --git a/docs/resources/resources.md b/docs/resources/resources.md index 76a1efe3d..4a2021a9b 100644 --- a/docs/resources/resources.md +++ b/docs/resources/resources.md @@ -8,15 +8,17 @@ We’ve moved our documentation to the Akamai TechDocs site. Use the table to fi | Subprovider | Description | |-------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------| -| [Application Security](https://techdocs.akamai.com/terraform/v5.1/docs/appsec-resources) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | -| [Bot Manager](https://techdocs.akamai.com/terraform/v5.1/docs/botman-resources) | Identify, track, and respond to bot activity on your domain or in your app. | -| [Certificates](https://techdocs.akamai.com/terraform/v5.1/docs/cps-resources) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | -| [Cloudlets](https://techdocs.akamai.com/terraform/v5.1/docs/cl-resources) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | -| [DataStream](https://techdocs.akamai.com/terraform/v5.1/docs/ds-resources) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | -| [Edge DNS](https://techdocs.akamai.com/terraform/v5.1/docs/edns-resources) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | -| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.1/docs/ew-resources) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | -| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.1/docs/gtm-resources) | Use load balancing to manage website and mobile performance demands. | -| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.1/docs/iam-resources) | Create users and groups, and define policies that manage access to your Akamai applications. | -| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.1/docs/ivm-resources) | Automate image and video delivery optimizations for your website visitors. | -| [Network Lists](https://techdocs.akamai.com/terraform/v5.1/docs/nl-resources) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | -| [Property](https://techdocs.akamai.com/terraform/v5.1/docs/pm-resources) | Define rules and behaviors that govern your website delivery based on match criteria. | +| [Application Security](https://techdocs.akamai.com/terraform/v5.2/docs/appsec-resources) | Manage security configurations, security policies, match targets, rate policies, and firewall rules. | +| [Bot Manager](https://techdocs.akamai.com/terraform/v5.2/docs/botman-resources) | Identify, track, and respond to bot activity on your domain or in your app. | +| [Certificates](https://techdocs.akamai.com/terraform/v5.2/docs/cps-resources) | Full life cycle management of SSL certificates for your ​Akamai​ CDN applications. | +| [Client Lists](https://techdocs.akamai.com/terraform/v5.2/docs/cli-resources) |Reduce harmful security attacks by allowing only trusted IP/CIDRs, locations, autonomous system numbers, and TLS fingerprints to access your services and content.| +| [Cloud Wrapper](https://techdocs.akamai.com/terraform/v5.2/docs/cw-resources) | Provide your customers with a more consistent user experience by adding a custom caching layer that improves the connection between your cloud infrastructure and the Akamai platform.| +| [Cloudlets](https://techdocs.akamai.com/terraform/v5.2/docs/cl-resources) | Solve specific business challenges using value-added apps that complement ​Akamai​'s core solutions. | +| [DataStream](https://techdocs.akamai.com/terraform/v5.2/docs/ds-resources) | Monitor activity on the ​Akamai​ platform and send live log data to a destination of your choice. | +| [Edge DNS](https://techdocs.akamai.com/terraform/v5.2/docs/edns-resources) | Replace or augment your DNS infrastructure with a cloud-based authoritative DNS solution. | +| [EdgeWorkers](https://techdocs.akamai.com/terraform/v5.2/docs/ew-resources) | Execute JavaScript functions at the edge to optimize site performance and customize web experiences. | +| [Global Traffic Management](https://techdocs.akamai.com/terraform/v5.2/docs/gtm-resources) | Use load balancing to manage website and mobile performance demands. | +| [Identity and Access Management](https://techdocs.akamai.com/terraform/v5.2/docs/iam-resources) | Create users and groups, and define policies that manage access to your Akamai applications. | +| [Image and Video Manager](https://techdocs.akamai.com/terraform/v5.2/docs/ivm-resources) | Automate image and video delivery optimizations for your website visitors. | +| [Network Lists](https://techdocs.akamai.com/terraform/v5.2/docs/nl-resources) | Automate the creation, deployment, and management of lists used in ​Akamai​ security products. | +| [Property](https://techdocs.akamai.com/terraform/v5.2/docs/pm-resources) | Define rules and behaviors that govern your website delivery based on match criteria. | diff --git a/go.mod b/go.mod index 6a9853412..4d324f0ce 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/akamai/terraform-provider-akamai/v5 require ( - github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.1.0 + github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.2.1 github.com/allegro/bigcache/v2 v2.2.5 github.com/apex/log v1.9.0 github.com/go-ozzo/ozzo-validation/v4 v4.3.0 @@ -9,9 +9,11 @@ require ( github.com/google/uuid v1.3.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-hclog v1.5.0 - github.com/hashicorp/terraform-plugin-framework v1.2.0 - github.com/hashicorp/terraform-plugin-go v0.15.0 - github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 + github.com/hashicorp/terraform-plugin-framework v1.3.3 + github.com/hashicorp/terraform-plugin-framework-validators v0.11.0 + github.com/hashicorp/terraform-plugin-go v0.18.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 + github.com/hashicorp/terraform-plugin-testing v1.4.0 github.com/jedib0t/go-pretty/v6 v6.0.4 github.com/jinzhu/copier v0.3.2 github.com/spf13/cast v1.3.1 @@ -21,13 +23,15 @@ require ( ) require ( + github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect + github.com/cloudflare/circl v1.3.3 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect - github.com/hashicorp/go-plugin v1.4.9 // indirect + github.com/hashicorp/go-plugin v1.4.10 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - golang.org/x/mod v0.8.0 // indirect - google.golang.org/grpc v1.54.0 // indirect + golang.org/x/mod v0.10.0 // indirect + google.golang.org/grpc v1.56.1 // indirect ) require ( @@ -38,22 +42,23 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.8.1 github.com/fatih/color v1.13.0 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hc-install v0.5.0 // indirect - github.com/hashicorp/hcl/v2 v2.16.2 // indirect + github.com/hashicorp/hc-install v0.5.2 // indirect + github.com/hashicorp/hcl/v2 v2.17.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.18.1 // indirect - github.com/hashicorp/terraform-json v0.16.0 // indirect + github.com/hashicorp/terraform-json v0.17.1 // indirect + github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-mux v0.10.0 - github.com/hashicorp/terraform-registry-address v0.2.0 // indirect - github.com/hashicorp/terraform-svchost v0.0.1 // indirect + github.com/hashicorp/terraform-registry-address v0.2.1 // indirect + github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect github.com/iancoleman/strcase v0.2.0 github.com/mattn/go-colorable v0.1.12 // indirect @@ -70,16 +75,16 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/objx v0.1.1 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect - github.com/zclconf/go-cty v1.13.1 // indirect + github.com/zclconf/go-cty v1.13.2 // indirect go.uber.org/ratelimit v0.2.0 // indirect - golang.org/x/crypto v0.7.0 // indirect - golang.org/x/net v0.8.0 // indirect + golang.org/x/crypto v0.11.0 // indirect + golang.org/x/net v0.11.0 // indirect golang.org/x/sync v0.2.0 - golang.org/x/sys v0.6.0 // indirect - golang.org/x/text v0.8.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect - google.golang.org/protobuf v1.30.0 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect + google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 9fb0ec6a9..a1d240947 100644 --- a/go.sum +++ b/go.sum @@ -1,60 +1,44 @@ -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= -github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= -github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= -github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= -github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.1.0 h1:QBcW0BOSLBN2DGgs6je3L/E/S3nCKhi4Me4oijT44Dw= -github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.1.0/go.mod h1:zZWAMUwE4q5sVPgnjz9jiqtXA01tM3m9HYd6Wk0ev90= +github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.2.1 h1:amPKOiXDgUXQcSMMg0XXvOZkF9sQcffZXZrZT4VJ3z0= +github.com/akamai/AkamaiOPEN-edgegrid-golang/v7 v7.2.1/go.mod h1:zZWAMUwE4q5sVPgnjz9jiqtXA01tM3m9HYd6Wk0ev90= github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI= github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY= github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI= github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0= github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA= github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo= github.com/aphistic/golf v0.0.0-20180712155816-02c07f170c5a/go.mod h1:3NqKYiepwy8kCu4PNA+aP7WUV72eXWJeP9/r3/K9aLE= github.com/aphistic/sweet v0.2.0/go.mod h1:fWDlIh/isSE9n6EPsRmC0det+whmX6dJid3stzu0Xys= -github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFUye+ZcSR6opIgz9Co7WcDx6ZcY+RjfFHoA0I= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06GQ59hwDQAvmK1qxOQGB3WuVTRoY0okPTAv0= github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= +github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dlclark/regexp2 v1.8.1 h1:6Lcdwya6GjPUNsBct8Lg/yRPwMhABj269AAzdGSiR+0= github.com/dlclark/regexp2 v1.8.1/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= -github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= -github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= -github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Aiu34= -github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0= -github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4= -github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc= +github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-git/v5 v5.6.1 h1:q4ZRqQl4pR/ZJHc1L5CFjGA1a10u76aV1iC+nh+bHsk= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es= github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew= @@ -63,15 +47,13 @@ github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= @@ -87,55 +69,54 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUK github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-plugin v1.4.9 h1:ESiK220/qE0aGxWdzKIvRH69iLiuN/PjoLTm69RoWtU= -github.com/hashicorp/go-plugin v1.4.9/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s= +github.com/hashicorp/go-plugin v1.4.10 h1:xUbmA4jC6Dq163/fWcp8P3JuHilrHHMLNRxzGQJ9hNk= +github.com/hashicorp/go-plugin v1.4.10/go.mod h1:6/1TEzT0eQznvI/gV2CM29DLSkAK/e58mUWKVsPaph0= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.5.0 h1:D9bl4KayIYKEeJ4vUDe9L5huqxZXczKaykSRcmQ0xY0= -github.com/hashicorp/hc-install v0.5.0/go.mod h1:JyzMfbzfSBSjoDCRPna1vi/24BEDxFaCPfdHtM5SCdo= -github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0= -github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= +github.com/hashicorp/hc-install v0.5.2 h1:SfwMFnEXVVirpwkDuSF5kymUOhrUxrTq3udEseZdOD0= +github.com/hashicorp/hc-install v0.5.2/go.mod h1:9QISwe6newMWIfEiXpzuu1k9HAGtQYgnSH8H9T8wmoI= +github.com/hashicorp/hcl/v2 v2.17.0 h1:z1XvSUyXd1HP10U4lrLg5e0JMVz6CPaJvAgxM0KNZVY= +github.com/hashicorp/hcl/v2 v2.17.0/go.mod h1:gJyW2PTShkJqQBKpAmPO3yxMxIuoXkOF2TpqXzrQyx4= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.18.1 h1:LAbfDvNQU1l0NOQlTuudjczVhHj061fNX5H8XZxHlH4= github.com/hashicorp/terraform-exec v0.18.1/go.mod h1:58wg4IeuAJ6LVsLUeD2DWZZoc/bYi6dzhLHzxM41980= -github.com/hashicorp/terraform-json v0.16.0 h1:UKkeWRWb23do5LNAFlh/K3N0ymn1qTOO8c+85Albo3s= -github.com/hashicorp/terraform-json v0.16.0/go.mod h1:v0Ufk9jJnk6tcIZvScHvetlKfiNTC+WS21mnXIlc0B0= -github.com/hashicorp/terraform-plugin-framework v1.2.0 h1:MZjFFfULnFq8fh04FqrKPcJ/nGpHOvX4buIygT3MSNY= -github.com/hashicorp/terraform-plugin-framework v1.2.0/go.mod h1:nToI62JylqXDq84weLJ/U3umUsBhZAaTmU0HXIVUOcw= -github.com/hashicorp/terraform-plugin-go v0.15.0 h1:1BJNSUFs09DS8h/XNyJNJaeusQuWc/T9V99ylU9Zwp0= -github.com/hashicorp/terraform-plugin-go v0.15.0/go.mod h1:tk9E3/Zx4RlF/9FdGAhwxHExqIHHldqiQGt20G6g+nQ= +github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= +github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-plugin-framework v1.3.3 h1:D18BlA8gdV4+W8WKhUqxudiYomPZHv94FFzyoSCKC8Q= +github.com/hashicorp/terraform-plugin-framework v1.3.3/go.mod h1:2gGDpWiTI0irr9NSTLFAKlTi6KwGti3AoU19rFqU30o= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E= +github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1/go.mod h1:MsjL1sQ9L7wGwzJ5RjcI6FzEMdyoBnw+XK8ZnOvQOLY= +github.com/hashicorp/terraform-plugin-framework-validators v0.11.0 h1:DKb1bX7/EPZUTW6F5zdwJzS/EZ/ycVD6JAW5RYOj4f8= +github.com/hashicorp/terraform-plugin-framework-validators v0.11.0/go.mod h1:dzxOiHh7O9CAwc6p8N4mR1H++LtRkl+u+21YNiBVNno= +github.com/hashicorp/terraform-plugin-go v0.18.0 h1:IwTkOS9cOW1ehLd/rG0y+u/TGLK9y6fGoBjXVUquzpE= +github.com/hashicorp/terraform-plugin-go v0.18.0/go.mod h1:l7VK+2u5Kf2y+A+742GX0ouLut3gttudmvMgN0PA74Y= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/hashicorp/terraform-plugin-mux v0.10.0 h1:VejY1BffxGy2iYOaa8DDHavY4k9jbvAE8F3lhruspKY= github.com/hashicorp/terraform-plugin-mux v0.10.0/go.mod h1:9sdnpmY20xIsl4ItsfODZYE+MgpSy/osXpSf+RwaZCY= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 h1:zHcMbxY0+rFO9gY99elV/XC/UnQVg7FhRCbj1i5b7vM= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1/go.mod h1:+tNlb0wkfdsDJ7JEiERLz4HzM19HyiuIoGzTsM7rPpw= -github.com/hashicorp/terraform-registry-address v0.2.0 h1:92LUg03NhfgZv44zpNTLBGIbiyTokQCDcdH5BhVHT3s= -github.com/hashicorp/terraform-registry-address v0.2.0/go.mod h1:478wuzJPzdmqT6OGbB/iH82EDcI8VFM4yujknh/1nIs= -github.com/hashicorp/terraform-svchost v0.0.1 h1:Zj6fR5wnpOHnJUmLyWozjMeDaVuE+cstMPj41/eKmSQ= -github.com/hashicorp/terraform-svchost v0.0.1/go.mod h1:ut8JaH0vumgdCfJaihdcZULqkAwHdQNwNH7taIDdsZM= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0 h1:I8efBnjuDrgPjNF1MEypHy48VgcTIUY4X6rOFunrR3Y= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0/go.mod h1:cUEP4ly/nxlHy5HzD6YRrHydtlheGvGRJDhiWqqVik4= +github.com/hashicorp/terraform-plugin-testing v1.4.0 h1:DVIXxw7VHZvnwWVik4HzhpC2yytaJ5FpiHxz5debKmE= +github.com/hashicorp/terraform-plugin-testing v1.4.0/go.mod h1:b7Bha24iGrbZQjT+ZE8m9crck1YjdVOZ8mfGCQ19OxA= +github.com/hashicorp/terraform-registry-address v0.2.1 h1:QuTf6oJ1+WSflJw6WYOHhLgwUiQ0FrROpHPYFtwTYWM= +github.com/hashicorp/terraform-registry-address v0.2.1/go.mod h1:BSE9fIFzp0qWsJUUyGquo4ldV9k2n+psif6NYkBRS3Y= +github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= +github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty/v6 v6.0.4 h1:7WaHUeKo5yc2vABlsh30p4VWxQoXaWktBY/nR/2qnPg= github.com/jedib0t/go-pretty/v6 v6.0.4/go.mod h1:MTr6FgcfNdnN5wPVBzJ6mhJeDyiF0yBvS2TMXEV/XSU= -github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w= github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro= @@ -143,27 +124,20 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7/go.mod h1:2iMrUgbbvHEiQClaW2NsSzMyGHqN+rDFqY705q49KG0= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -172,8 +146,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -184,27 +156,24 @@ github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9 github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0= github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= @@ -218,9 +187,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0= @@ -237,115 +204,82 @@ github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9 github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= -github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zclconf/go-cty v1.13.1 h1:0a6bRwuiSHtAmqCqNOE+c2oHgepv0ctoxU4FUe43kwc= -github.com/zclconf/go-cty v1.13.1/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= +github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= +github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= +golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f h1:BWUVssLB0HVOSY78gIdvk1dTVYtT1y8SBWtPYuTJ/6w= -google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= -google.golang.org/grpc v1.54.0 h1:EhTqbhiYeixwWQtAEZAxmV9MGqcjEU2mFx52xCzNyag= -google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= +google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ= +google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= -google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/akamai/framework_provider_test.go b/pkg/akamai/framework_provider_test.go index 9c991d9aa..7cd39711c 100644 --- a/pkg/akamai/framework_provider_test.go +++ b/pkg/akamai/framework_provider_test.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/providerserver" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" ) diff --git a/pkg/common/collections/slice.go b/pkg/common/collections/slice.go new file mode 100644 index 000000000..91e09bd43 --- /dev/null +++ b/pkg/common/collections/slice.go @@ -0,0 +1,8 @@ +package collections + +// ForEachInSlice applies the provided function for each element of the slice. +func ForEachInSlice[S ~[]E, E any](s S, fn func(a E) E) { + for i, v := range s { + s[i] = fn(v) + } +} diff --git a/pkg/common/collections/slice_test.go b/pkg/common/collections/slice_test.go new file mode 100644 index 000000000..f169ad035 --- /dev/null +++ b/pkg/common/collections/slice_test.go @@ -0,0 +1,95 @@ +package collections + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestForEachInSlice(t *testing.T) { + var intTests = []struct { + s, want []int + fn func(d int) int + }{ + { + s: []int{}, + want: []int{}, + fn: func(d int) int { return d }, + }, + { + s: []int{1, 2, 3}, + want: []int{2, 3, 4}, + fn: func(d int) int { return d + 1 }, + }, + { + s: []int{1, 2, 3}, + want: []int{1, 4, 9}, + fn: func(d int) int { return d * d }, + }, + } + + for _, test := range intTests { + ForEachInSlice(test.s, test.fn) + assert.Equal(t, test.want, test.s) + } + + var floatTests = []struct { + s, want []float64 + fn func(d float64) float64 + }{ + { + s: []float64{1, 2, 3}, + want: []float64{1, 2, 3}, + fn: func(f float64) float64 { return f }, + }, + } + + for _, test := range floatTests { + ForEachInSlice(test.s, test.fn) + assert.Equal(t, test.want, test.s) + } + + var stringTests = []struct { + s, want []string + fn func(s string) string + }{ + { + s: []string{"a", "b", "c"}, + want: []string{"ab", "bb", "cb"}, + fn: func(s string) string { return s + "b" }, + }, + { + s: []string{"prefa", "prefb", "c"}, + want: []string{"a", "b", "c"}, + fn: func(s string) string { return strings.TrimPrefix(s, "pref") }, + }, + } + + for _, test := range stringTests { + ForEachInSlice(test.s, test.fn) + assert.Equal(t, test.want, test.s) + } + + type mySlice []int + mySliceTests := []struct { + s, want mySlice + fn func(d int) int + }{ + { + s: mySlice{1, 2, 3}, + want: mySlice{2, 3, 4}, + fn: func(d int) int { return d + 1 }, + }, + { + s: mySlice{1, 2, 3}, + want: mySlice{1, 4, 9}, + fn: func(d int) int { return d * d }, + }, + } + + for _, test := range mySliceTests { + ForEachInSlice(test.s, test.fn) + assert.Equal(t, test.want, test.s) + } +} diff --git a/pkg/common/framework/modifiers/doc.go b/pkg/common/framework/modifiers/doc.go new file mode 100644 index 000000000..8c9187268 --- /dev/null +++ b/pkg/common/framework/modifiers/doc.go @@ -0,0 +1,2 @@ +// Package modifiers contains plan modifier related functions to be used with resource and data sources written using Terraform Provider Framework +package modifiers diff --git a/pkg/common/framework/modifiers/eq_with_prefix.go b/pkg/common/framework/modifiers/eq_with_prefix.go new file mode 100644 index 000000000..2eed16962 --- /dev/null +++ b/pkg/common/framework/modifiers/eq_with_prefix.go @@ -0,0 +1,11 @@ +package modifiers + +import "strings" + +// EqualUpToPrefixFunc returns function that compares if two strings are equal stripping prefix +func EqualUpToPrefixFunc(prefix string) func(string, string) bool { + return func(s1, s2 string) bool { + return strings.TrimPrefix(s1, prefix) == + strings.TrimPrefix(s2, prefix) + } +} diff --git a/pkg/common/framework/modifiers/prevent_string_update.go b/pkg/common/framework/modifiers/prevent_string_update.go new file mode 100644 index 000000000..22d423171 --- /dev/null +++ b/pkg/common/framework/modifiers/prevent_string_update.go @@ -0,0 +1,37 @@ +package modifiers + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +// PreventStringUpdate returns a plan modifier that ensures given field cannot be updated after creation. +func PreventStringUpdate() planmodifier.String { + return preventStringUpdateModifier{} +} + +// preventStringUpdateModifier implements the plan modifier. +type preventStringUpdateModifier struct{} + +// Description returns a human-readable description of the plan modifier. +func (m preventStringUpdateModifier) Description(_ context.Context) string { + return "Use if you want to ensure that no update " + + "is available for given field." +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m preventStringUpdateModifier) MarkdownDescription(ctx context.Context) string { + return m.Description(ctx) +} + +// PlanModifyString implements the plan modification logic. +func (m preventStringUpdateModifier) PlanModifyString(_ context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { + if req.StateValue.IsNull() { + return + } + if req.PlanValue != req.StateValue { + resp.Diagnostics.AddError("Update not Supported", fmt.Sprintf("updating field `%s` is not possible", req.Path.String())) + } +} diff --git a/pkg/common/framework/modifiers/set_use_state_if.go b/pkg/common/framework/modifiers/set_use_state_if.go new file mode 100644 index 000000000..8286b39e6 --- /dev/null +++ b/pkg/common/framework/modifiers/set_use_state_if.go @@ -0,0 +1,76 @@ +package modifiers + +import ( + "context" + + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/replacer" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// SetUseStateIf returns a plan modifier that copies a known prior state +// value into the planned value if given function returns true. +// Use this when you want to suppress value changes. +// Value will remain the same after a resource update. +// +// To prevent Terraform errors, the framework automatically sets unconfigured +// and Computed attributes to an unknown value "(known after apply)" on update. +// Using this plan modifier will instead display the prior state value in the +// plan, unless a prior plan modifier adjusts the value. +func SetUseStateIf(eqFunc func(string, string) bool) planmodifier.Set { + return setUseStateIfModifier{ + equal: eqFunc, + } +} + +// setUseStateIfModifier implements the plan modifier. +type setUseStateIfModifier struct { + equal func(string, string) bool +} + +// Description returns a human-readable description of the plan modifier. +func (m setUseStateIfModifier) Description(_ context.Context) string { + return "Use if you want to suppress value changes. " + + "Once provided function returns true, the value of this attribute in state will not change. " +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m setUseStateIfModifier) MarkdownDescription(_ context.Context) string { + return "Use if you want to suppress value changes. " + + "Once provided function returns true, the value of this attribute in state will not change. " +} + +// PlanModifyString implements the plan modification logic. +func (m setUseStateIfModifier) PlanModifySet(ctx context.Context, req planmodifier.SetRequest, resp *planmodifier.SetResponse) { + // Do nothing if there is no state value. + if req.StateValue.IsNull() { + return + } + + // Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up. + if req.ConfigValue.IsUnknown() { + return + } + + planValues := []string{} + stateValues := []string{} + resp.Diagnostics.Append(req.PlanValue.ElementsAs(ctx, &planValues, false)...) + resp.Diagnostics.Append(req.StateValue.ElementsAs(ctx, &stateValues, false)...) + if resp.Diagnostics.HasError() { + return + } + + replaced := replacer.Replacer{ + Source: planValues, + Replacements: stateValues, + EqFunc: m.equal, + }.Replace() + + replacedSet, diags := types.SetValueFrom(ctx, types.StringType, replaced) + if resp.Diagnostics.HasError() { + resp.Diagnostics.Append(diags...) + return + } + + resp.PlanValue = replacedSet +} diff --git a/pkg/common/framework/modifiers/string_use_state_if.go b/pkg/common/framework/modifiers/string_use_state_if.go new file mode 100644 index 000000000..b86529f54 --- /dev/null +++ b/pkg/common/framework/modifiers/string_use_state_if.go @@ -0,0 +1,56 @@ +package modifiers + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" +) + +// StringUseStateIf returns a plan modifier that copies a known prior state +// value into the planned value if given function returns true. +// Use this when you want to suppress value changes. +// Value will remain the same after a resource update. +// +// To prevent Terraform errors, the framework automatically sets unconfigured +// and Computed attributes to an unknown value "(known after apply)" on update. +// Using this plan modifier will instead display the prior state value in the +// plan, unless a prior plan modifier adjusts the value. +func StringUseStateIf(pred func(string, string) bool) planmodifier.String { + return stringUseStateIfModifier{ + pred: pred, + } +} + +// stringUseStateIfModifier implements the plan modifier. +type stringUseStateIfModifier struct { + pred func(string, string) bool +} + +// Description returns a human-readable description of the plan modifier. +func (m stringUseStateIfModifier) Description(_ context.Context) string { + return "Use if you want to suppress value changes. " + + "Once provided function returns true, the value of this attribute in state will not change. " +} + +// MarkdownDescription returns a markdown description of the plan modifier. +func (m stringUseStateIfModifier) MarkdownDescription(_ context.Context) string { + return "Use if you want to suppress value changes. " + + "Once provided function returns true, the value of this attribute in state will not change. " +} + +// PlanModifyString implements the plan modification logic. +func (m stringUseStateIfModifier) PlanModifyString(_ context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { + // Do nothing if there is no state value. + if req.StateValue.IsNull() { + return + } + + // Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up. + if req.ConfigValue.IsUnknown() { + return + } + + if m.pred(req.PlanValue.ValueString(), req.StateValue.ValueString()) { + resp.PlanValue = req.StateValue + } +} diff --git a/pkg/common/framework/replacer/replacer.go b/pkg/common/framework/replacer/replacer.go new file mode 100644 index 000000000..6f0c2b53e --- /dev/null +++ b/pkg/common/framework/replacer/replacer.go @@ -0,0 +1,36 @@ +// Package replacer ... +package replacer + +// Replacer represents a string replacement operation. +type Replacer struct { + Source []string + Replacements []string + EqFunc func(string, string) bool +} + +// Replace replaces strings in the Source slice with corresponding strings from the Replacements slice. +// It returns a new slice with the replaced strings, while leaving the original Source slice unchanged. +// The replacement is performed by iterating over the Source slice and checking if each element has a match in the Replacements slice. +// If a match is found, the corresponding element from the Replacements slice is used as the replacement. +func (r Replacer) Replace() []string { + if r.EqFunc == nil { + r.EqFunc = func(_, _ string) bool { return false } + } + newslice := make([]string, len(r.Source)) + copy(newslice, r.Source) + for i, val := range newslice { + if v, ok := r.findPreferred(val); ok { + newslice[i] = v + } + } + return newslice +} + +func (r Replacer) findPreferred(s string) (string, bool) { + for _, v := range r.Replacements { + if r.EqFunc(v, s) { + return v, true + } + } + return "", false +} diff --git a/pkg/common/framework/replacer/replacer_test.go b/pkg/common/framework/replacer/replacer_test.go new file mode 100644 index 000000000..8f250324f --- /dev/null +++ b/pkg/common/framework/replacer/replacer_test.go @@ -0,0 +1,68 @@ +// Package replacer_test ... +package replacer_test + +import ( + "testing" + + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/modifiers" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/replacer" + "github.com/stretchr/testify/assert" +) + +func TestReplacer(t *testing.T) { + tests := map[string]struct { + source []string + replacements []string + expected []string + eqFunc func(string, string) bool + }{ + "all replaced with prefix": { + source: []string{"123", "456", "789"}, + replacements: []string{"prp_123", "prp_456", "prp_789"}, + expected: []string{"prp_123", "prp_456", "prp_789"}, + eqFunc: modifiers.EqualUpToPrefixFunc("prp_"), + }, + "some replaced with prefix": { + source: []string{"123", "456", "789"}, + replacements: []string{"prp_123", "prp_456"}, + expected: []string{"prp_123", "prp_456", "789"}, + eqFunc: modifiers.EqualUpToPrefixFunc("prp_"), + }, + "replacements without prefix": { + source: []string{"prp_123", "prp_456", "prp_789"}, + replacements: []string{"123", "456"}, + expected: []string{"123", "456", "prp_789"}, + eqFunc: modifiers.EqualUpToPrefixFunc("prp_"), + }, + "no matches": { + source: []string{"123", "456", "789"}, + replacements: []string{"prp_1234", "prp_4567", "prp_7890"}, + expected: []string{"123", "456", "789"}, + eqFunc: modifiers.EqualUpToPrefixFunc("prp_"), + }, + "no matches - wrong prefix": { + source: []string{"123", "456", "789"}, + replacements: []string{"prp_123", "prp_456"}, + expected: []string{"123", "456", "789"}, + eqFunc: modifiers.EqualUpToPrefixFunc("ctr_"), + }, + "no eq func - should not modify source": { + source: []string{"123", "456", "789"}, + replacements: []string{"prp_123", "prp_456"}, + expected: []string{"123", "456", "789"}, + eqFunc: nil, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + actual := replacer.Replacer{ + Source: test.source, + Replacements: test.replacements, + EqFunc: test.eqFunc, + }.Replace() + + assert.Equal(t, test.expected, actual) + }) + } +} diff --git a/pkg/common/testutils/testutils.go b/pkg/common/testutils/testutils.go index ac1bb3c39..d6d13ef75 100644 --- a/pkg/common/testutils/testutils.go +++ b/pkg/common/testutils/testutils.go @@ -3,7 +3,11 @@ package testutils import ( "fmt" + "io/ioutil" "os" + "testing" + + "github.com/stretchr/testify/require" ) // tfTestTempDir specifies the location of tmp directory which will be used by provider SDK's testing framework @@ -30,3 +34,16 @@ func TFTestTeardown() error { } return nil } + +// LoadFixtureBytes returns the entire contents of the given file as a byte slice +func LoadFixtureBytes(t *testing.T, path string) []byte { + t.Helper() + contents, err := ioutil.ReadFile(path) + require.NoError(t, err) + return contents +} + +// LoadFixtureString returns the entire contents of the given file as a string +func LoadFixtureString(t *testing.T, format string, args ...interface{}) string { + return string(LoadFixtureBytes(t, fmt.Sprintf(format, args...))) +} diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_attack_payload_logging_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_attack_payload_logging_test.go index 976f02b05..7bb864b1e 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_attack_payload_logging_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_attack_payload_logging_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasic(t *testing.T) { ).Return(&config, nil) getLoggingResponse := appsec.GetAdvancedSettingsAttackPayloadLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &getLoggingResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &getLoggingResponse) require.NoError(t, err) client.On("GetAdvancedSettingsAttackPayloadLogging", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_attack_payload_logging.test", "id", "43253:"), ), @@ -57,7 +58,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasicPolicyId(t *testing. client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -66,7 +67,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasicPolicyId(t *testing. ).Return(&config, nil) getLoggingResponse := appsec.GetAdvancedSettingsAttackPayloadLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &getLoggingResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &getLoggingResponse) require.NoError(t, err) client.On("GetAdvancedSettingsAttackPayloadLogging", @@ -80,7 +81,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingDataBasicPolicyId(t *testing. ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsAttackPayloadLogging/match_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsAttackPayloadLogging/match_by_policy_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_attack_payload_logging.policy", "id", "43253:test_policy"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_evasive_path_match_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_evasive_path_match_test.go index 4ad20060a..ac99ce580 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_evasive_path_match_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_evasive_path_match_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsEvasivePathMatch_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsEvasivePathMatch_data_basic(t *testing.T) { ).Return(&config, nil) getEvasivePathMatchResponse := appsec.GetAdvancedSettingsEvasivePathMatchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &getEvasivePathMatchResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &getEvasivePathMatchResponse) require.NoError(t, err) client.On("GetAdvancedSettingsEvasivePathMatch", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsEvasivePathMatch_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsEvasivePathMatch/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsEvasivePathMatch/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_evasive_path_match.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_logging_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_logging_test.go index 5bc3b43f4..ffa78b827 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_logging_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_logging_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsLogging_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsLogging_data_basic(t *testing.T) { ).Return(&config, nil) getLoggingResponse := appsec.GetAdvancedSettingsLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &getLoggingResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &getLoggingResponse) require.NoError(t, err) client.On("GetAdvancedSettingsLogging", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsLogging_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsLogging/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsLogging/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_logging.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pii_learning_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pii_learning_test.go index a7980aafb..e40e942c6 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pii_learning_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pii_learning_test.go @@ -8,7 +8,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -26,7 +27,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -35,7 +36,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_basic(t *testing.T) { ).Return(&config, nil) getPIILearningResponse := appsec.AdvancedSettingsPIILearningResponse{} - piiLearningBytes := loadFixtureBytes("testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") + piiLearningBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") var piiLearningJSON bytes.Buffer err = json.Compact(&piiLearningJSON, []byte(piiLearningBytes)) require.NoError(t, err) @@ -58,7 +59,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsPIILearning/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsPIILearning/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_pii_learning.test", "id", "43253"), resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_pii_learning.test", "json", piiLearningJSON.String()), @@ -79,7 +80,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_missing_parameter(t *testing.T) client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -88,7 +89,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_missing_parameter(t *testing.T) ).Return(&config, nil) getPIILearningResponse := appsec.AdvancedSettingsPIILearningResponse{} - piiLearningBytes := loadFixtureBytes("testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") + piiLearningBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") var piiLearningJSON bytes.Buffer err = json.Compact(&piiLearningJSON, []byte(piiLearningBytes)) require.NoError(t, err) @@ -111,7 +112,7 @@ func TestAkamaiAdvancedSettingsPIILearning_data_missing_parameter(t *testing.T) ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsPIILearning/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsPIILearning/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_pii_learning.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pragma_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pragma_test.go index e86bdbcab..f56282d14 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pragma_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_pragma_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsPragma_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsPragma_data_basic(t *testing.T) { ).Return(&config, nil) getPragmaResponse := appsec.GetAdvancedSettingsPragmaResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &getPragmaResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &getPragmaResponse) require.NoError(t, err) client.On("GetAdvancedSettingsPragma", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsPragma_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsPragma/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsPragma/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_pragma_header.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_prefetch_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_prefetch_test.go index 391f63788..607d5a312 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_prefetch_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_prefetch_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsPrefetch_data_basic(t *testing.T) { client := &appsec.Mock{} getPrefetchResponse := appsec.GetAdvancedSettingsPrefetchResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &getPrefetchResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &getPrefetchResponse) require.NoError(t, err) client.On("GetAdvancedSettingsPrefetch", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsPrefetch_data_basic(t *testing.T) { ).Return(&getPrefetchResponse, nil) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsPrefetch_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsPrefetch/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsPrefetch/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_prefetch.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_request_body_test.go b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_request_body_test.go index f84ec49b0..5484686a7 100644 --- a/pkg/providers/appsec/data_akamai_appsec_advanced_settings_request_body_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_advanced_settings_request_body_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasic(t *testing.T) { ).Return(&config, nil) getRequestBodyResponse := appsec.GetAdvancedSettingsRequestBodyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &getRequestBodyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &getRequestBodyResponse) require.NoError(t, err) client.On("GetAdvancedSettingsRequestBody", @@ -38,7 +39,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsRequestBody/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsRequestBody/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_request_body.test", "id", "43253:"), ), @@ -57,7 +58,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasicPolicyID(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -66,7 +67,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasicPolicyID(t *testing.T) { ).Return(&config, nil) getRequestBodyResponse := appsec.GetAdvancedSettingsRequestBodyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &getRequestBodyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &getRequestBodyResponse) require.NoError(t, err) client.On("GetAdvancedSettingsRequestBody", @@ -80,7 +81,7 @@ func TestAkamaiAdvancedSettingsRequestBodyDataBasicPolicyID(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAdvancedSettingsRequestBody/match_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAdvancedSettingsRequestBody/match_by_policy_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_advanced_settings_request_body.policy", "id", "43253:test_policy"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_api_endpoints_test.go b/pkg/providers/appsec/data_akamai_appsec_api_endpoints_test.go index b9021a26f..1593bf3ae 100644 --- a/pkg/providers/appsec/data_akamai_appsec_api_endpoints_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_api_endpoints_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiApiEndpoints_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiApiEndpoints_data_basic(t *testing.T) { ).Return(&config, nil) getAPIEndpointsResponse := appsec.GetApiEndpointsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSApiEndpoints/ApiEndpoints.json"), &getAPIEndpointsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSApiEndpoints/ApiEndpoints.json"), &getAPIEndpointsResponse) require.NoError(t, err) client.On("GetApiEndpoints", @@ -38,7 +39,7 @@ func TestAkamaiApiEndpoints_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSApiEndpoints/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSApiEndpoints/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_api_endpoints.test", "id", "619183"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_match_targets_test.go b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_match_targets_test.go index b386d8156..d0d2bccc4 100644 --- a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_match_targets_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_match_targets_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiApiHostnameCoverageMatchTargets_data_basic(t *testing.T) { client := &appsec.Mock{} getMatchTargetsResponse := appsec.GetApiHostnameCoverageMatchTargetsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSApiHostnameCoverageMatchTargets/ApiHostnameCoverageMatchTargets.json"), &getMatchTargetsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSApiHostnameCoverageMatchTargets/ApiHostnameCoverageMatchTargets.json"), &getMatchTargetsResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiApiHostnameCoverageMatchTargets_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSApiHostnameCoverageMatchTargets/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSApiHostnameCoverageMatchTargets/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_hostname_coverage_match_targets.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_overlapping_test.go b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_overlapping_test.go index a28604dc8..bbcf91fdf 100644 --- a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_overlapping_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_overlapping_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiApiHostnameCoverageOverlapping_data_basic(t *testing.T) { client := &appsec.Mock{} getOverlapResponse := appsec.GetApiHostnameCoverageOverlappingResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSApiHostnameCoverageOverlapping/ApiHostnameCoverageOverlapping.json"), &getOverlapResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSApiHostnameCoverageOverlapping/ApiHostnameCoverageOverlapping.json"), &getOverlapResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiApiHostnameCoverageOverlapping_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSApiHostnameCoverageOverlapping/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSApiHostnameCoverageOverlapping/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_hostname_coverage_overlapping.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_test.go b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_test.go index f4ee176d9..8092e1194 100644 --- a/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_api_hostname_coverage_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiApiHostnameCoverage_data_basic(t *testing.T) { client := &appsec.Mock{} getCoverageResponse := appsec.GetApiHostnameCoverageResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSApiHostnameCoverage/ApiHostnameCoverage.json"), &getCoverageResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSApiHostnameCoverage/ApiHostnameCoverage.json"), &getCoverageResponse) require.NoError(t, err) client.On("GetApiHostnameCoverage", @@ -29,7 +30,7 @@ func TestAkamaiApiHostnameCoverage_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSApiHostnameCoverage/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSApiHostnameCoverage/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_hostname_coverage.test", "id", "3644"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_api_request_constraints_test.go b/pkg/providers/appsec/data_akamai_appsec_api_request_constraints_test.go index fb2e6ec4f..399449a7a 100644 --- a/pkg/providers/appsec/data_akamai_appsec_api_request_constraints_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_api_request_constraints_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiApiRequestConstraints_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiApiRequestConstraints_data_basic(t *testing.T) { ).Return(&config, nil) getAPIRequestConstraintsResponse := appsec.GetApiRequestConstraintsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSApiRequestConstraints/ApiRequestConstraints.json"), &getAPIRequestConstraintsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSApiRequestConstraints/ApiRequestConstraints.json"), &getAPIRequestConstraintsResponse) require.NoError(t, err) client.On("GetApiRequestConstraints", @@ -38,7 +39,7 @@ func TestAkamaiApiRequestConstraints_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSApiRequestConstraints/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSApiRequestConstraints/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_api_request_constraints.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_attack_groups_test.go b/pkg/providers/appsec/data_akamai_appsec_attack_groups_test.go index aa3e6d65d..349e14d10 100644 --- a/pkg/providers/appsec/data_akamai_appsec_attack_groups_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_attack_groups_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiAttackGroups_data_basic(t *testing.T) { client := &appsec.Mock{} getAttackGroupsResponse := appsec.GetAttackGroupsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSAttackGroups/AttackGroups.json"), &getAttackGroupsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSAttackGroups/AttackGroups.json"), &getAttackGroupsResponse) require.NoError(t, err) configs := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configs) require.NoError(t, err) client.On("GetAttackGroups", @@ -38,7 +39,7 @@ func TestAkamaiAttackGroups_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSAttackGroups/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSAttackGroups/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_attack_groups.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_bypass_network_lists_test.go b/pkg/providers/appsec/data_akamai_appsec_bypass_network_lists_test.go index e6e15c19d..5fd374ff4 100644 --- a/pkg/providers/appsec/data_akamai_appsec_bypass_network_lists_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_bypass_network_lists_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiBypassNetworkLists_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiBypassNetworkLists_data_basic(t *testing.T) { ).Return(&config, nil) getBypassNetworkListsResponse := appsec.GetWAPBypassNetworkListsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSBypassNetworkLists/BypassNetworkLists.json"), &getBypassNetworkListsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSBypassNetworkLists/BypassNetworkLists.json"), &getBypassNetworkListsResponse) require.NoError(t, err) client.On("GetWAPBypassNetworkLists", @@ -38,7 +39,7 @@ func TestAkamaiBypassNetworkLists_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSBypassNetworkLists/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSBypassNetworkLists/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_bypass_network_lists.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_configuration_test.go b/pkg/providers/appsec/data_akamai_appsec_configuration_test.go index d609ab159..8656d9e22 100644 --- a/pkg/providers/appsec/data_akamai_appsec_configuration_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_configuration_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestAkamaiConfiguration_data_basic(t *testing.T) { client := &appsec.Mock{} getConfigurationsResponse := appsec.GetConfigurationsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSConfiguration/Configuration.json"), &getConfigurationsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSConfiguration/Configuration.json"), &getConfigurationsResponse) require.NoError(t, err) client.On("GetConfigurations", @@ -31,7 +32,7 @@ func TestAkamaiConfiguration_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSConfiguration/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSConfiguration/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_configuration.test", "id", "43253"), ), @@ -50,7 +51,7 @@ func TestAkamaiConfiguration_data_nonexistentConfig(t *testing.T) { client := &appsec.Mock{} getConfigurationsResponse := appsec.GetConfigurationsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSConfiguration/Configuration.json"), &getConfigurationsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSConfiguration/Configuration.json"), &getConfigurationsResponse) require.NoError(t, err) client.On("GetConfigurations", @@ -63,7 +64,7 @@ func TestAkamaiConfiguration_data_nonexistentConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSConfiguration/nonexistent_config.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSConfiguration/nonexistent_config.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_configuration.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_configuration_version_test.go b/pkg/providers/appsec/data_akamai_appsec_configuration_version_test.go index fb607914a..84f8e3146 100644 --- a/pkg/providers/appsec/data_akamai_appsec_configuration_version_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_configuration_version_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiConfigurationVersion_data_basic(t *testing.T) { client := &appsec.Mock{} getConfigurationVersionsResponse := appsec.GetConfigurationVersionsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSConfigurationVersion/ConfigurationVersion.json"), &getConfigurationVersionsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSConfigurationVersion/ConfigurationVersion.json"), &getConfigurationVersionsResponse) require.NoError(t, err) client.On("GetConfigurationVersions", @@ -29,7 +30,7 @@ func TestAkamaiConfigurationVersion_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSConfigurationVersion/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSConfigurationVersion/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_configuration_version.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_contracts_groups_test.go b/pkg/providers/appsec/data_akamai_appsec_contracts_groups_test.go index 08a6c8130..3f39e9e16 100644 --- a/pkg/providers/appsec/data_akamai_appsec_contracts_groups_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_contracts_groups_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiContractsGroups_data_basic(t *testing.T) { client := &appsec.Mock{} getContractsGroupsResponse := appsec.GetContractsGroupsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSContractsGroups/ContractsGroups.json"), &getContractsGroupsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSContractsGroups/ContractsGroups.json"), &getContractsGroupsResponse) require.NoError(t, err) client.On("GetContractsGroups", @@ -29,7 +30,7 @@ func TestAkamaiContractsGroups_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSContractsGroups/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractsGroups/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_contracts_groups.test", "id", "C-1FRYVV3"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_custom_deny_test.go b/pkg/providers/appsec/data_akamai_appsec_custom_deny_test.go index ec03f8c65..b02a09409 100644 --- a/pkg/providers/appsec/data_akamai_appsec_custom_deny_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_custom_deny_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiCustomDeny_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiCustomDeny_data_basic(t *testing.T) { ).Return(&config, nil) getCustomDenyListResponse := appsec.GetCustomDenyListResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSCustomDeny/CustomDenyList.json"), &getCustomDenyListResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSCustomDeny/CustomDenyList.json"), &getCustomDenyListResponse) require.NoError(t, err) client.On("GetCustomDenyList", @@ -38,7 +39,7 @@ func TestAkamaiCustomDeny_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSCustomDeny/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCustomDeny/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_custom_deny.test", "custom_deny_id", "deny_custom_54994"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_custom_rule_actions_test.go b/pkg/providers/appsec/data_akamai_appsec_custom_rule_actions_test.go index 10a192ba6..3316385af 100644 --- a/pkg/providers/appsec/data_akamai_appsec_custom_rule_actions_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_custom_rule_actions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiCustomRuleActions_data_basic(t *testing.T) { client := &appsec.Mock{} getCustomRuleActionsResponse := appsec.GetCustomRuleActionsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSCustomRuleActions/CustomRuleActions.json"), &getCustomRuleActionsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSCustomRuleActions/CustomRuleActions.json"), &getCustomRuleActionsResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiCustomRuleActions_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSCustomRuleActions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCustomRuleActions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_custom_rule_actions.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_custom_rules_test.go b/pkg/providers/appsec/data_akamai_appsec_custom_rules_test.go index 3ca26191b..37dc7daef 100644 --- a/pkg/providers/appsec/data_akamai_appsec_custom_rules_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_custom_rules_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiCustomRules_data_basic(t *testing.T) { client := &appsec.Mock{} getCustomRulesResponse := appsec.GetCustomRulesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSCustomRules/CustomRules.json"), &getCustomRulesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSCustomRules/CustomRules.json"), &getCustomRulesResponse) require.NoError(t, err) client.On("GetCustomRules", @@ -29,7 +30,7 @@ func TestAkamaiCustomRules_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSCustomRules/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCustomRules/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_custom_rules.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_eval_groups_test.go b/pkg/providers/appsec/data_akamai_appsec_eval_groups_test.go index 43aa05fba..58840e3d6 100644 --- a/pkg/providers/appsec/data_akamai_appsec_eval_groups_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_eval_groups_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestAkamaiEvalGroups_data_basic(t *testing.T) { client := &appsec.Mock{} configs := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configs) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configs) require.NoError(t, err) client.On("GetEvalGroups", @@ -36,7 +37,7 @@ func TestAkamaiEvalGroups_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSEvalGroups/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSEvalGroups/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_eval_groups.test", "id", "43253"), ), @@ -55,7 +56,7 @@ func TestAkamaiEvalGroups_data_error_retrieving_eval_groups(t *testing.T) { client := &appsec.Mock{} configs := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configs) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configs) require.NoError(t, err) client.On("GetEvalGroups", @@ -74,7 +75,7 @@ func TestAkamaiEvalGroups_data_error_retrieving_eval_groups(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSEvalGroups/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSEvalGroups/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_eval_groups.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_eval_penalty_box_test.go b/pkg/providers/appsec/data_akamai_appsec_eval_penalty_box_test.go index 47fb1d644..2b7e300e0 100644 --- a/pkg/providers/appsec/data_akamai_appsec_eval_penalty_box_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_eval_penalty_box_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiEvalPenaltyBox_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiEvalPenaltyBox_data_basic(t *testing.T) { ).Return(&config, nil) penaltyBox := appsec.GetPenaltyBoxResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSEvalPenaltyBox/PenaltyBox.json"), &penaltyBox) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSEvalPenaltyBox/PenaltyBox.json"), &penaltyBox) require.NoError(t, err) client.On("GetEvalPenaltyBox", @@ -38,7 +39,7 @@ func TestAkamaiEvalPenaltyBox_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSEvalPenaltyBox/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSEvalPenaltyBox/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_eval_penalty_box.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_eval_rules_test.go b/pkg/providers/appsec/data_akamai_appsec_eval_rules_test.go index 8c7238776..599cce06a 100644 --- a/pkg/providers/appsec/data_akamai_appsec_eval_rules_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_eval_rules_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiEvalRules_data_basic(t *testing.T) { client := &appsec.Mock{} getEvalRulesResponse := appsec.GetEvalRulesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSEvalRules/EvalRules.json"), &getEvalRulesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSEvalRules/EvalRules.json"), &getEvalRulesResponse) require.NoError(t, err) configs := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configs) require.NoError(t, err) client.On("GetEvalRules", @@ -38,7 +39,7 @@ func TestAkamaiEvalRules_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSEvalRules/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSEvalRules/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_eval_rules.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_eval_test.go b/pkg/providers/appsec/data_akamai_appsec_eval_test.go index 59b3c2add..9a99b82bf 100644 --- a/pkg/providers/appsec/data_akamai_appsec_eval_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_eval_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiEval_data_basic(t *testing.T) { client := &appsec.Mock{} getEvalResponse := appsec.GetEvalResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSEval/Eval.json"), &getEvalResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSEval/Eval.json"), &getEvalResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiEval_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSEval/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSEval/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_eval.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_export_configuration_test.go b/pkg/providers/appsec/data_akamai_appsec_export_configuration_test.go index 5b6f5e0ab..95c82c0ae 100644 --- a/pkg/providers/appsec/data_akamai_appsec_export_configuration_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_export_configuration_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiExportConfiguration_data_basic(t *testing.T) { client := &appsec.Mock{} getExportConfigurationResponse := appsec.GetExportConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSExportConfiguration/ExportConfiguration.json"), &getExportConfigurationResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSExportConfiguration/ExportConfiguration.json"), &getExportConfigurationResponse) require.NoError(t, err) client.On("GetExportConfiguration", @@ -31,7 +32,7 @@ func TestAkamaiExportConfiguration_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSExportConfiguration/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSExportConfiguration/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_export_configuration.test", "id", "43253"), resource.TestCheckResourceAttr("data.akamai_appsec_export_configuration.evalGroups", "output_text", expectedEvalGroups), diff --git a/pkg/providers/appsec/data_akamai_appsec_failover_hostnames_test.go b/pkg/providers/appsec/data_akamai_appsec_failover_hostnames_test.go index d0611eea4..c10a87b1f 100644 --- a/pkg/providers/appsec/data_akamai_appsec_failover_hostnames_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_failover_hostnames_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiFailoverHostnames_data_basic(t *testing.T) { client := &appsec.Mock{} getFailoverHostnamesResponse := appsec.GetFailoverHostnamesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSFailoverHostnames/FailoverHostnames.json"), &getFailoverHostnamesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSFailoverHostnames/FailoverHostnames.json"), &getFailoverHostnamesResponse) require.NoError(t, err) client.On("GetFailoverHostnames", @@ -29,7 +30,7 @@ func TestAkamaiFailoverHostnames_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSFailoverHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSFailoverHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_failover_hostnames.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_ip_geo_test.go b/pkg/providers/appsec/data_akamai_appsec_ip_geo_test.go index 155ffdf70..9e5848407 100644 --- a/pkg/providers/appsec/data_akamai_appsec_ip_geo_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_ip_geo_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiIPGeo_data_basic(t *testing.T) { client := &appsec.Mock{} getIPGeoResponse := appsec.GetIPGeoResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSIPGeo/IPGeo.json"), &getIPGeoResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSIPGeo/IPGeo.json"), &getIPGeoResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiIPGeo_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSIPGeo/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSIPGeo/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_ip_geo.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_malware_content_types_test.go b/pkg/providers/appsec/data_akamai_appsec_malware_content_types_test.go index 444c03588..1e98298f9 100644 --- a/pkg/providers/appsec/data_akamai_appsec_malware_content_types_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_malware_content_types_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiMalwareContentTypes_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiMalwareContentTypes_data_basic(t *testing.T) { ).Return(&config, nil) getMalwareContentTypesResponse := appsec.GetMalwareContentTypesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSMalwareContentTypes/MalwareContentTypes.json"), &getMalwareContentTypesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMalwareContentTypes/MalwareContentTypes.json"), &getMalwareContentTypesResponse) require.NoError(t, err) client.On("GetMalwareContentTypes", @@ -38,7 +39,7 @@ func TestAkamaiMalwareContentTypes_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSMalwareContentTypes/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSMalwareContentTypes/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_malware_content_types.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_malware_policies_test.go b/pkg/providers/appsec/data_akamai_appsec_malware_policies_test.go index 5e5f852d2..b5e7579e0 100644 --- a/pkg/providers/appsec/data_akamai_appsec_malware_policies_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_malware_policies_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiMalwarePolicies_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiMalwarePolicies_data_basic(t *testing.T) { ).Return(&config, nil) getMalwarePoliciesResponse := appsec.MalwarePoliciesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSMalwarePolicies/MalwarePolicies.json"), &getMalwarePoliciesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMalwarePolicies/MalwarePolicies.json"), &getMalwarePoliciesResponse) require.NoError(t, err) client.On("GetMalwarePolicies", @@ -38,7 +39,7 @@ func TestAkamaiMalwarePolicies_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSMalwarePolicies/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSMalwarePolicies/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_malware_policies.test", "id", "43253"), ), @@ -57,7 +58,7 @@ func TestAkamaiMalwarePolicies_data_single_policy(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -66,7 +67,7 @@ func TestAkamaiMalwarePolicies_data_single_policy(t *testing.T) { ).Return(&config, nil) getMalwarePolicyResponse := appsec.MalwarePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSMalwarePolicies/MalwarePolicy.json"), &getMalwarePolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMalwarePolicies/MalwarePolicy.json"), &getMalwarePolicyResponse) require.NoError(t, err) client.On("GetMalwarePolicy", @@ -80,7 +81,7 @@ func TestAkamaiMalwarePolicies_data_single_policy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSMalwarePolicies/match_by_id_single_policy.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSMalwarePolicies/match_by_id_single_policy.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_malware_policies.test", "id", "43253:999"), resource.TestCheckResourceAttr("data.akamai_appsec_malware_policies.test", "malware_policy_id", "999"), diff --git a/pkg/providers/appsec/data_akamai_appsec_malware_policy_actions_test.go b/pkg/providers/appsec/data_akamai_appsec_malware_policy_actions_test.go index f71e75132..6d922bfff 100644 --- a/pkg/providers/appsec/data_akamai_appsec_malware_policy_actions_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_malware_policy_actions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiMalwarePolicyActions_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiMalwarePolicyActions_data_basic(t *testing.T) { ).Return(&config, nil) getMalwarePolicyActionsResponse := appsec.GetMalwarePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSMalwarePolicyActions/MalwarePolicyActions.json"), &getMalwarePolicyActionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMalwarePolicyActions/MalwarePolicyActions.json"), &getMalwarePolicyActionsResponse) require.NoError(t, err) client.On("GetMalwarePolicyActions", @@ -38,7 +39,7 @@ func TestAkamaiMalwarePolicyActions_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSMalwarePolicyActions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSMalwarePolicyActions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_malware_policy_actions.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_match_targets_test.go b/pkg/providers/appsec/data_akamai_appsec_match_targets_test.go index e6fbb0fa0..e2b2a5339 100644 --- a/pkg/providers/appsec/data_akamai_appsec_match_targets_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_match_targets_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiMatchTargets_data_basic(t *testing.T) { client := &appsec.Mock{} getMatchTargetsResponse := appsec.GetMatchTargetsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSMatchTargets/MatchTargets.json"), &getMatchTargetsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMatchTargets/MatchTargets.json"), &getMatchTargetsResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiMatchTargets_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSMatchTargets/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSMatchTargets/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_match_targets.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_penalty_box_test.go b/pkg/providers/appsec/data_akamai_appsec_penalty_box_test.go index 3e0579bbe..7b2a0a586 100644 --- a/pkg/providers/appsec/data_akamai_appsec_penalty_box_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_penalty_box_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiPenaltyBox_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiPenaltyBox_data_basic(t *testing.T) { ).Return(&config, nil) getPenaltyBoxResponse := appsec.GetPenaltyBoxResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSPenaltyBox/PenaltyBox.json"), &getPenaltyBoxResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSPenaltyBox/PenaltyBox.json"), &getPenaltyBoxResponse) require.NoError(t, err) client.On("GetPenaltyBox", @@ -38,7 +39,7 @@ func TestAkamaiPenaltyBox_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPenaltyBox/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPenaltyBox/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_penalty_box.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_rate_policies_test.go b/pkg/providers/appsec/data_akamai_appsec_rate_policies_test.go index 90b5d3305..9b061136c 100644 --- a/pkg/providers/appsec/data_akamai_appsec_rate_policies_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_rate_policies_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiRatePolicies_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiRatePolicies_data_basic(t *testing.T) { ).Return(&config, nil) getRatePoliciesResponse := appsec.GetRatePoliciesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSRatePolicies/RatePolicies.json"), &getRatePoliciesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSRatePolicies/RatePolicies.json"), &getRatePoliciesResponse) require.NoError(t, err) client.On("GetRatePolicies", @@ -38,7 +39,7 @@ func TestAkamaiRatePolicies_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRatePolicies/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRatePolicies/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_rate_policies.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_rate_policy_actions_test.go b/pkg/providers/appsec/data_akamai_appsec_rate_policy_actions_test.go index 007119061..d71f16f6a 100644 --- a/pkg/providers/appsec/data_akamai_appsec_rate_policy_actions_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_rate_policy_actions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiRatePolicyActions_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiRatePolicyActions_data_basic(t *testing.T) { ).Return(&config, nil) getRatePolicyActionsResponse := appsec.GetRatePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSRatePolicyActions/RatePolicyActions.json"), &getRatePolicyActionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSRatePolicyActions/RatePolicyActions.json"), &getRatePolicyActionsResponse) require.NoError(t, err) client.On("GetRatePolicyActions", @@ -38,7 +39,7 @@ func TestAkamaiRatePolicyActions_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRatePolicyActions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRatePolicyActions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_rate_policy_actions.test", "id", "102720"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_reputation_analysis_test.go b/pkg/providers/appsec/data_akamai_appsec_reputation_analysis_test.go index e610bebbe..ec62d83f8 100644 --- a/pkg/providers/appsec/data_akamai_appsec_reputation_analysis_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_reputation_analysis_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiReputationAnalysis_data_basic(t *testing.T) { client := &appsec.Mock{} getReputationAnalysisResponse := appsec.GetReputationAnalysisResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSReputationAnalysis/ReputationAnalysis.json"), &getReputationAnalysisResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSReputationAnalysis/ReputationAnalysis.json"), &getReputationAnalysisResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiReputationAnalysis_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSReputationAnalysis/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSReputationAnalysis/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_reputation_profile_analysis.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_reputation_profile_actions_test.go b/pkg/providers/appsec/data_akamai_appsec_reputation_profile_actions_test.go index bd858ebee..5a95a3573 100644 --- a/pkg/providers/appsec/data_akamai_appsec_reputation_profile_actions_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_reputation_profile_actions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiReputationProfileActions_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiReputationProfileActions_data_basic(t *testing.T) { ).Return(&config, nil) getReputationProfileActionsResponse := appsec.GetReputationProfileActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSReputationProfileActions/ReputationProfileActions.json"), &getReputationProfileActionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSReputationProfileActions/ReputationProfileActions.json"), &getReputationProfileActionsResponse) require.NoError(t, err) client.On("GetReputationProfileActions", @@ -38,7 +39,7 @@ func TestAkamaiReputationProfileActions_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSReputationProfileActions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSReputationProfileActions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_reputation_profile_actions.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_reputation_profiles_test.go b/pkg/providers/appsec/data_akamai_appsec_reputation_profiles_test.go index cad4f536e..871899d7d 100644 --- a/pkg/providers/appsec/data_akamai_appsec_reputation_profiles_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_reputation_profiles_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiReputationProfiles_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiReputationProfiles_data_basic(t *testing.T) { ).Return(&config, nil) getReputationProfilesResponse := appsec.GetReputationProfilesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSReputationProfiles/ReputationProfiles.json"), &getReputationProfilesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSReputationProfiles/ReputationProfiles.json"), &getReputationProfilesResponse) require.NoError(t, err) client.On("GetReputationProfiles", @@ -38,7 +39,7 @@ func TestAkamaiReputationProfiles_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSReputationProfiles/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSReputationProfiles/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_reputation_profiles.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_rule_upgrade_test.go b/pkg/providers/appsec/data_akamai_appsec_rule_upgrade_test.go index afdaf37f2..0b89bc566 100644 --- a/pkg/providers/appsec/data_akamai_appsec_rule_upgrade_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_rule_upgrade_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiRuleUpgrade_data_basic(t *testing.T) { client := &appsec.Mock{} getRuleUpgradeResponse := appsec.GetRuleUpgradeResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSRuleUpgrade/RuleUpgrade.json"), &getRuleUpgradeResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSRuleUpgrade/RuleUpgrade.json"), &getRuleUpgradeResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiRuleUpgrade_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRuleUpgrade/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRuleUpgrade/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_rule_upgrade_details.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_rules_test.go b/pkg/providers/appsec/data_akamai_appsec_rules_test.go index dd241180a..259d7d622 100644 --- a/pkg/providers/appsec/data_akamai_appsec_rules_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_rules_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiRules_data_basic(t *testing.T) { client := &appsec.Mock{} getRulesResponse := appsec.GetRulesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSRules/Rules.json"), &getRulesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSRules/Rules.json"), &getRulesResponse) require.NoError(t, err) configs := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configs) require.NoError(t, err) client.On("GetRules", @@ -33,7 +34,7 @@ func TestAkamaiRules_data_basic(t *testing.T) { ).Return(&configs, nil) getWAFModeResponse := appsec.GetWAFModeResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFMode/WAFMode.json"), &getWAFModeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFMode/WAFMode.json"), &getWAFModeResponse) require.NoError(t, err) client.On("GetWAFMode", @@ -50,7 +51,7 @@ func TestAkamaiRules_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRules/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRules/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_rules.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_security_policy_protections_test.go b/pkg/providers/appsec/data_akamai_appsec_security_policy_protections_test.go index 28b7a17ab..6ee402bd4 100644 --- a/pkg/providers/appsec/data_akamai_appsec_security_policy_protections_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_security_policy_protections_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiPolicyProtections_data_basic(t *testing.T) { client := &appsec.Mock{} policyProtectionsResponse := appsec.PolicyProtectionsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSPolicyProtections/PolicyProtections.json"), &policyProtectionsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSPolicyProtections/PolicyProtections.json"), &policyProtectionsResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiPolicyProtections_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPolicyProtections/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPolicyProtections/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_security_policy_protections.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_security_policy_test.go b/pkg/providers/appsec/data_akamai_appsec_security_policy_test.go index 607e4b793..18ca96c3f 100644 --- a/pkg/providers/appsec/data_akamai_appsec_security_policy_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_security_policy_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiSecurityPolicy_data_basic(t *testing.T) { t.Run("match by SecurityPolicy ID", func(t *testing.T) { client := &appsec.Mock{} - securityPoliciesBytes := loadFixtureBytes("testdata/TestDSSecurityPolicy/SecurityPolicy.json") + securityPoliciesBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSSecurityPolicy/SecurityPolicy.json") getSecurityPoliciesResponse := appsec.GetSecurityPoliciesResponse{} err := json.Unmarshal(securityPoliciesBytes, &getSecurityPoliciesResponse) require.NoError(t, err) - securityPoliciesJSONBytes := loadFixtureBytes("testdata/TestDSSecurityPolicy/SecurityPolicyJSON.json") + securityPoliciesJSONBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSSecurityPolicy/SecurityPolicyJSON.json") buf := &bytes.Buffer{} err = json.Compact(buf, securityPoliciesJSONBytes) require.NoError(t, err) securityPoliciesJSONString := buf.String() config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -46,7 +47,7 @@ func TestAkamaiSecurityPolicy_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSecurityPolicy/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSecurityPolicy/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_security_policy.test", "id", "43253:7"), resource.TestCheckResourceAttr("data.akamai_appsec_security_policy.test", "json", securityPoliciesJSONString), diff --git a/pkg/providers/appsec/data_akamai_appsec_selectable_hostnames_test.go b/pkg/providers/appsec/data_akamai_appsec_selectable_hostnames_test.go index 15f032eb4..ff33896d3 100644 --- a/pkg/providers/appsec/data_akamai_appsec_selectable_hostnames_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_selectable_hostnames_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSelectableHostnames_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiSelectableHostnames_data_basic(t *testing.T) { ).Return(&config, nil) getSelectableHostnamesResponse := appsec.GetSelectableHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSSelectableHostnames/SelectableHostnames.json"), &getSelectableHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSelectableHostnames/SelectableHostnames.json"), &getSelectableHostnamesResponse) require.NoError(t, err) client.On("GetSelectableHostnames", @@ -38,7 +39,7 @@ func TestAkamaiSelectableHostnames_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSelectableHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSelectableHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_selectable_hostnames.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_selected_hostnames_test.go b/pkg/providers/appsec/data_akamai_appsec_selected_hostnames_test.go index 15f05531c..a1259f5a1 100644 --- a/pkg/providers/appsec/data_akamai_appsec_selected_hostnames_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_selected_hostnames_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSelectedHostnames_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiSelectedHostnames_data_basic(t *testing.T) { ).Return(&config, nil) getSelectedHostnamesResponse := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSSelectedHostnames/SelectedHostnames.json"), &getSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSelectedHostnames/SelectedHostnames.json"), &getSelectedHostnamesResponse) require.NoError(t, err) client.On("GetSelectedHostnames", @@ -38,7 +39,7 @@ func TestAkamaiSelectedHostnames_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_selected_hostnames.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_siem_definitions_test.go b/pkg/providers/appsec/data_akamai_appsec_siem_definitions_test.go index dfe2ac6e4..0342b1b72 100644 --- a/pkg/providers/appsec/data_akamai_appsec_siem_definitions_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_siem_definitions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSiemDefinitions_data_basic(t *testing.T) { client := &appsec.Mock{} getSiemDefinitionsResponse := appsec.GetSiemDefinitionsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSSiemDefinitions/SiemDefinitions.json"), &getSiemDefinitionsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSiemDefinitions/SiemDefinitions.json"), &getSiemDefinitionsResponse) require.NoError(t, err) client.On("GetSiemDefinitions", @@ -29,7 +30,7 @@ func TestAkamaiSiemDefinitions_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSiemDefinitions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSiemDefinitions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_siem_definitions.test", "id", "1"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_siem_settings_test.go b/pkg/providers/appsec/data_akamai_appsec_siem_settings_test.go index a7b467990..bd5fb37c1 100644 --- a/pkg/providers/appsec/data_akamai_appsec_siem_settings_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_siem_settings_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSiemSettings_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiSiemSettings_data_basic(t *testing.T) { ).Return(&config, nil) getSiemSettingsResponse := appsec.GetSiemSettingsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSSiemSettings/SiemSettings.json"), &getSiemSettingsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSiemSettings/SiemSettings.json"), &getSiemSettingsResponse) require.NoError(t, err) client.On("GetSiemSettings", @@ -38,7 +39,7 @@ func TestAkamaiSiemSettings_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSiemSettings/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSiemSettings/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_siem_settings.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_slow_post_protection_settings_test.go b/pkg/providers/appsec/data_akamai_appsec_slow_post_protection_settings_test.go index 35428bf83..9134f8a3a 100644 --- a/pkg/providers/appsec/data_akamai_appsec_slow_post_protection_settings_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_slow_post_protection_settings_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSlowPostProtectionSettings_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiSlowPostProtectionSettings_data_basic(t *testing.T) { ).Return(&config, nil) getSlowPostProtectionSettingsResponse := appsec.GetSlowPostProtectionSettingsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSSlowPostProtectionSettings/SlowPostProtectionSettings.json"), &getSlowPostProtectionSettingsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSlowPostProtectionSettings/SlowPostProtectionSettings.json"), &getSlowPostProtectionSettingsResponse) require.NoError(t, err) client.On("GetSlowPostProtectionSettings", @@ -38,7 +39,7 @@ func TestAkamaiSlowPostProtectionSettings_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSSlowPostProtectionSettings/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSSlowPostProtectionSettings/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_slow_post.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_threat_intel_test.go b/pkg/providers/appsec/data_akamai_appsec_threat_intel_test.go index b3ceb1476..13e8d49bf 100644 --- a/pkg/providers/appsec/data_akamai_appsec_threat_intel_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_threat_intel_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestAkamaiThreatIntel_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -26,7 +27,7 @@ func TestAkamaiThreatIntel_data_basic(t *testing.T) { ).Return(&config, nil) getThreatIntelResponse := appsec.GetThreatIntelResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSThreatIntel/ThreatIntel.json"), &getThreatIntelResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSThreatIntel/ThreatIntel.json"), &getThreatIntelResponse) require.NoError(t, err) client.On("GetThreatIntel", @@ -40,7 +41,7 @@ func TestAkamaiThreatIntel_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSThreatIntel/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSThreatIntel/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_threat_intel.test", "id", "43253"), ), @@ -59,7 +60,7 @@ func TestAkamaiThreatIntel_data_error_retrieving_threat_intel(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -68,7 +69,7 @@ func TestAkamaiThreatIntel_data_error_retrieving_threat_intel(t *testing.T) { ).Return(&config, nil) threatIntelResponse := appsec.GetThreatIntelResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSThreatIntel/ThreatIntel.json"), &threatIntelResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSThreatIntel/ThreatIntel.json"), &threatIntelResponse) require.NoError(t, err) client.On("GetThreatIntel", @@ -82,7 +83,7 @@ func TestAkamaiThreatIntel_data_error_retrieving_threat_intel(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSThreatIntel/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSThreatIntel/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_threat_intel.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_tuning_recommendations_test.go b/pkg/providers/appsec/data_akamai_appsec_tuning_recommendations_test.go index e5bdc00d3..09c4dc948 100644 --- a/pkg/providers/appsec/data_akamai_appsec_tuning_recommendations_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_tuning_recommendations_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestAkamaiTuningRecommendationsDataBasic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -26,15 +27,15 @@ func TestAkamaiTuningRecommendationsDataBasic(t *testing.T) { ).Return(&config, nil) getRecs := appsec.GetTuningRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/Recommendations.json"), &getRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/Recommendations.json"), &getRecs) require.NoError(t, err) getGroupRecs := appsec.GetAttackGroupRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/AttackGroupRecommendations.json"), &getGroupRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/AttackGroupRecommendations.json"), &getGroupRecs) require.NoError(t, err) getRuleRecs := appsec.GetRuleRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/RuleRecommendations.json"), &getRuleRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/RuleRecommendations.json"), &getRuleRecs) require.NoError(t, err) client.On("GetTuningRecommendations", @@ -58,7 +59,7 @@ func TestAkamaiTuningRecommendationsDataBasic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSTuningRecommendations/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSTuningRecommendations/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_tuning_recommendations.recommendations", "id", "43253"), ), @@ -77,7 +78,7 @@ func TestAkamaiTuningRecommenadationsDataErrorRetrievingTuningRecommenadations(t client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -86,15 +87,15 @@ func TestAkamaiTuningRecommenadationsDataErrorRetrievingTuningRecommenadations(t ).Return(&config, nil) getRecs := appsec.GetTuningRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/Recommendations.json"), &getRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/Recommendations.json"), &getRecs) require.NoError(t, err) getGroupRecs := appsec.GetAttackGroupRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/AttackGroupRecommendations.json"), &getGroupRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/AttackGroupRecommendations.json"), &getGroupRecs) require.NoError(t, err) getRuleRecs := appsec.GetAttackGroupRecommendationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSTuningRecommendations/RuleRecommendations.json"), &getRuleRecs) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSTuningRecommendations/RuleRecommendations.json"), &getRuleRecs) require.NoError(t, err) client.On("GetTuningRecommendations", @@ -118,7 +119,7 @@ func TestAkamaiTuningRecommenadationsDataErrorRetrievingTuningRecommenadations(t ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSTuningRecommendations/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSTuningRecommendations/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_tuning_recommendations.recommendations", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_version_notes_test.go b/pkg/providers/appsec/data_akamai_appsec_version_notes_test.go index 00bb7b47e..20a9847d8 100644 --- a/pkg/providers/appsec/data_akamai_appsec_version_notes_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_version_notes_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiVersionNotes_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,7 +25,7 @@ func TestAkamaiVersionNotes_data_basic(t *testing.T) { ).Return(&config, nil) getVersionNotesResponse := appsec.GetVersionNotesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSVersionNotes/VersionNotes.json"), &getVersionNotesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSVersionNotes/VersionNotes.json"), &getVersionNotesResponse) require.NoError(t, err) client.On("GetVersionNotes", @@ -38,7 +39,7 @@ func TestAkamaiVersionNotes_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSVersionNotes/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSVersionNotes/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_version_notes.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_waf_mode_test.go b/pkg/providers/appsec/data_akamai_appsec_waf_mode_test.go index 8dd54a73f..e38a8aaf8 100644 --- a/pkg/providers/appsec/data_akamai_appsec_waf_mode_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_waf_mode_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiWAFMode_data_basic(t *testing.T) { client := &appsec.Mock{} getWAFModeResponse := appsec.GetWAFModeResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSWAFMode/WAFMode.json"), &getWAFModeResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSWAFMode/WAFMode.json"), &getWAFModeResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -38,7 +39,7 @@ func TestAkamaiWAFMode_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSWAFMode/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSWAFMode/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_waf_mode.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/data_akamai_appsec_wap_selected_hostnames_test.go b/pkg/providers/appsec/data_akamai_appsec_wap_selected_hostnames_test.go index daed9feb6..e9ee1a88e 100644 --- a/pkg/providers/appsec/data_akamai_appsec_wap_selected_hostnames_test.go +++ b/pkg/providers/appsec/data_akamai_appsec_wap_selected_hostnames_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestAkamaiWAPSelectedHostnames_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfigurationWAP.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfigurationWAP.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -26,7 +27,7 @@ func TestAkamaiWAPSelectedHostnames_data_basic(t *testing.T) { ).Return(&config, nil) getWAPSelectedHostnamesResponse := appsec.GetWAPSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) require.NoError(t, err) client.On("GetWAPSelectedHostnames", @@ -40,7 +41,7 @@ func TestAkamaiWAPSelectedHostnames_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_wap_selected_hostnames.test", "id", "43253:AAAA_81230"), ), @@ -59,7 +60,7 @@ func TestAkamaiWAPSelectedHostnames_data_error_retrieving_hostnames(t *testing.T client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfigurationWAP.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfigurationWAP.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -68,7 +69,7 @@ func TestAkamaiWAPSelectedHostnames_data_error_retrieving_hostnames(t *testing.T ).Return(&config, nil) getWAPSelectedHostnamesResponse := appsec.GetWAPSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) require.NoError(t, err) client.On("GetWAPSelectedHostnames", @@ -82,7 +83,7 @@ func TestAkamaiWAPSelectedHostnames_data_error_retrieving_hostnames(t *testing.T ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_wap_selected_hostnames.test", "id", "43253:AAAA_81230"), ), @@ -102,7 +103,7 @@ func TestAkamaiWAPSelectedHostnames_NonWAP_data_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -111,11 +112,11 @@ func TestAkamaiWAPSelectedHostnames_NonWAP_data_basic(t *testing.T) { ).Return(&config, nil) getSelectedHostnamesResponse := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSSelectedHostnames/SelectedHostnames.json"), &getSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSSelectedHostnames/SelectedHostnames.json"), &getSelectedHostnamesResponse) require.NoError(t, err) getMatchTargetsResponse := appsec.GetMatchTargetsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestDSMatchTargets/MatchTargets.json"), &getMatchTargetsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSMatchTargets/MatchTargets.json"), &getMatchTargetsResponse) require.NoError(t, err) client.On("GetSelectedHostnames", @@ -134,7 +135,7 @@ func TestAkamaiWAPSelectedHostnames_NonWAP_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSWAPSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_appsec_wap_selected_hostnames.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/provider_test.go b/pkg/providers/appsec/provider_test.go index 0d8241c42..a9ebaa2c1 100644 --- a/pkg/providers/appsec/provider_test.go +++ b/pkg/providers/appsec/provider_test.go @@ -1,7 +1,6 @@ package appsec import ( - "io/ioutil" "log" "os" "sync" @@ -50,17 +49,3 @@ func useClient(client appsec.APPSEC, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(path string) string { - return string(loadFixtureBytes(path)) -} diff --git a/pkg/providers/appsec/resource_akamai_appsec_activations_test.go b/pkg/providers/appsec/resource_akamai_appsec_activations_test.go index 25ed65e96..2d8fe6ad0 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_activations_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_activations_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiActivations_res_basic(t *testing.T) { client := &appsec.Mock{} removeActivationsResponse := appsec.RemoveActivationsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/ActivationsDelete.json"), &removeActivationsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/ActivationsDelete.json"), &removeActivationsResponse) require.NoError(t, err) getActivationsResponse := appsec.GetActivationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/Activations.json"), &getActivationsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/Activations.json"), &getActivationsResponse) require.NoError(t, err) createActivationsResponse := appsec.CreateActivationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/Activations.json"), &createActivationsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/Activations.json"), &createActivationsResponse) require.NoError(t, err) client.On("GetActivations", @@ -64,7 +65,7 @@ func TestAkamaiActivations_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResActivations/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResActivations/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_activations.test", "id", "547694"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_attack_payload_logging_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_attack_payload_logging_test.go index 113b0a6b9..9dddf5597 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_attack_payload_logging_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_attack_payload_logging_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -14,7 +15,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { var ( configVersion = func(t *testing.T, configId int, client *appsec.Mock) appsec.GetConfigurationResponse { configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -27,7 +28,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { attackPayloadLoggingRead = func(t *testing.T, configId int, version int, policyId string, client *appsec.Mock, numberOfTimes int) { attackPayloadLoggingResponse := appsec.GetAdvancedSettingsAttackPayloadLoggingResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &attackPayloadLoggingResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/AdvancedSettingsAttackPayloadLogging.json"), &attackPayloadLoggingResponse) require.NoError(t, err) client.On("GetAdvancedSettingsAttackPayloadLogging", @@ -39,7 +40,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { updateAttackPayloadLogging = func(t *testing.T, updateAttackPayloadLogging appsec.UpdateAdvancedSettingsAttackPayloadLoggingRequest, client *appsec.Mock, numberOfTimes int) { updateAttackPayloadLoggingResponse := appsec.UpdateAdvancedSettingsAttackPayloadLoggingResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json"), &updateAttackPayloadLoggingResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json"), &updateAttackPayloadLoggingResponse) require.NoError(t, err) client.On("UpdateAdvancedSettingsAttackPayloadLogging", @@ -50,7 +51,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { removeAttackPayloadLogging = func(t *testing.T, removeAttackPayloadLogging appsec.RemoveAdvancedSettingsAttackPayloadLoggingRequest, client *appsec.Mock, numberOfTimes int) { removeAttackPayloadLoggingResponse := appsec.RemoveAdvancedSettingsAttackPayloadLoggingResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json"), &removeAttackPayloadLoggingResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json"), &removeAttackPayloadLoggingResponse) require.NoError(t, err) client.On("RemoveAdvancedSettingsAttackPayloadLogging", @@ -65,7 +66,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { configResponse := configVersion(t, 43253, client) attackPayloadLoggingRead(t, 43253, 7, "", client, 2) - updateAdvancedSettingsAttackPayloadLoggingJSON := loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") + updateAdvancedSettingsAttackPayloadLoggingJSON := testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") updateAttackPayloadLoggingRequest := appsec.UpdateAdvancedSettingsAttackPayloadLoggingRequest{ConfigID: configResponse.ID, Version: configResponse.LatestVersion, PolicyID: "", JSONPayloadRaw: updateAdvancedSettingsAttackPayloadLoggingJSON} updateAttackPayloadLogging(t, updateAttackPayloadLoggingRequest, client, 1) @@ -86,7 +87,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_attack_payload_logging.test", "id", "43253:"), ), @@ -104,7 +105,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { configResponse := configVersion(t, 43253, client) attackPayloadLoggingRead(t, configResponse.ID, configResponse.LatestVersion, "", client, 4) - updateAdvancedSettingsAttackPayloadLoggingJSON := loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") + updateAdvancedSettingsAttackPayloadLoggingJSON := testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") updateAttackPayloadLoggingRequest := appsec.UpdateAdvancedSettingsAttackPayloadLoggingRequest{ConfigID: configResponse.ID, Version: configResponse.LatestVersion, PolicyID: "", JSONPayloadRaw: updateAdvancedSettingsAttackPayloadLoggingJSON} updateAttackPayloadLogging(t, updateAttackPayloadLoggingRequest, client, 1) @@ -125,7 +126,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/match_by_id.tf"), }, { ImportState: true, @@ -144,7 +145,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { configResponse := configVersion(t, 43253, client) attackPayloadLoggingRead(t, 43253, 7, "test_policy", client, 4) - updateAdvancedSettingsAttackPayloadLoggingJSON := loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") + updateAdvancedSettingsAttackPayloadLoggingJSON := testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") updateAttackPayloadLoggingRequest := appsec.UpdateAdvancedSettingsAttackPayloadLoggingRequest{ConfigID: configResponse.ID, Version: configResponse.LatestVersion, PolicyID: "test_policy", JSONPayloadRaw: updateAdvancedSettingsAttackPayloadLoggingJSON} updateAttackPayloadLogging(t, updateAttackPayloadLoggingRequest, client, 1) @@ -165,7 +166,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsAttackPayloadLogging/update_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/update_by_policy_id.tf"), }, { ImportState: true, @@ -184,7 +185,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { configResponse := configVersion(t, 43253, client) attackPayloadLoggingRead(t, 43253, 7, "test_policy", client, 2) - updateAdvancedSettingsAttackPayloadLoggingJSON := loadFixtureBytes("testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") + updateAdvancedSettingsAttackPayloadLoggingJSON := testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/UpdateAdvancedSettingsAttackPayloadLogging.json") updateAttackPayloadLoggingRequest := appsec.UpdateAdvancedSettingsAttackPayloadLoggingRequest{ConfigID: configResponse.ID, Version: configResponse.LatestVersion, PolicyID: "test_policy", JSONPayloadRaw: updateAdvancedSettingsAttackPayloadLoggingJSON} updateAttackPayloadLogging(t, updateAttackPayloadLoggingRequest, client, 1) @@ -206,7 +207,7 @@ func TestAkamaiAdvancedSettingsAttackPayloadLoggingConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsAttackPayloadLogging/update_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsAttackPayloadLogging/update_by_policy_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_attack_payload_logging.policy", "id", "43253:test_policy"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_evasive_path_match_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_evasive_path_match_test.go index f40c64e98..282802d79 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_evasive_path_match_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_evasive_path_match_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiAdvancedSettingsEvasivePathMatch_res_basic(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) getResponse := appsec.GetAdvancedSettingsEvasivePathMatchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &getResponse) require.NoError(t, err) updateResponse := appsec.UpdateAdvancedSettingsEvasivePathMatchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &updateResponse) require.NoError(t, err) removeResponse := appsec.RemoveAdvancedSettingsEvasivePathMatchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsEvasivePathMatch/EvasivePathMatch.json"), &removeResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiAdvancedSettingsEvasivePathMatch_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsEvasivePathMatch/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsEvasivePathMatch/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_evasive_path_match.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_logging_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_logging_test.go index fd71c11b2..52f73be5d 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_logging_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_logging_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiAdvancedSettingsLogging_res_basic(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) getResponse := appsec.GetAdvancedSettingsLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &getResponse) require.NoError(t, err) updateResponse := appsec.UpdateAdvancedSettingsLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &updateResponse) require.NoError(t, err) removeResponse := appsec.RemoveAdvancedSettingsLoggingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsLogging/AdvancedSettingsLogging.json"), &removeResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -40,7 +41,7 @@ func TestAkamaiAdvancedSettingsLogging_res_basic(t *testing.T) { appsec.GetAdvancedSettingsLoggingRequest{ConfigID: 43253, Version: 7}, ).Return(&getResponse, nil) - updateAdvancedSettingsLoggingJSON := loadFixtureBytes("testdata/TestResAdvancedSettingsLogging/UpdateAdvancedSettingsLogging.json") + updateAdvancedSettingsLoggingJSON := testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsLogging/UpdateAdvancedSettingsLogging.json") client.On("UpdateAdvancedSettingsLogging", mock.Anything, appsec.UpdateAdvancedSettingsLoggingRequest{ConfigID: 43253, Version: 7, PolicyID: "", JsonPayloadRaw: updateAdvancedSettingsLoggingJSON}, @@ -57,7 +58,7 @@ func TestAkamaiAdvancedSettingsLogging_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsLogging/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsLogging/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_logging.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pii_learning_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pii_learning_test.go index f84d33de0..d48656ac4 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pii_learning_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pii_learning_test.go @@ -8,7 +8,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -18,15 +19,15 @@ func TestAkamaiAdvancedSettingsPIILearning_res_basic(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) getResponse := appsec.AdvancedSettingsPIILearningResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &getResponse) require.NoError(t, err) updateResponse := appsec.AdvancedSettingsPIILearningResponse{} - piiLearningBytes := loadFixtureBytes("testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") + piiLearningBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") var piiLearningJSON bytes.Buffer err = json.Compact(&piiLearningJSON, []byte(piiLearningBytes)) require.NoError(t, err) @@ -34,7 +35,7 @@ func TestAkamaiAdvancedSettingsPIILearning_res_basic(t *testing.T) { require.NoError(t, err) removeResponse := appsec.AdvancedSettingsPIILearningResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &removeResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -77,7 +78,7 @@ func TestAkamaiAdvancedSettingsPIILearning_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsPIILearning/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsPIILearning/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_pii_learning.test", "id", "43253"), resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_pii_learning.test", "enable_pii_learning", "true"), @@ -97,15 +98,15 @@ func TestAkamaiAdvancedSettingsPIILearning_res_api_call_failure(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) getResponse := appsec.AdvancedSettingsPIILearningResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &getResponse) require.NoError(t, err) updateResponse := appsec.AdvancedSettingsPIILearningResponse{} - piiLearningBytes := loadFixtureBytes("testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") + piiLearningBytes := testutils.LoadFixtureBytes(t, "testdata/TestDSAdvancedSettingsPIILearning/PIILearning.json") var piiLearningJSON bytes.Buffer err = json.Compact(&piiLearningJSON, []byte(piiLearningBytes)) require.NoError(t, err) @@ -113,7 +114,7 @@ func TestAkamaiAdvancedSettingsPIILearning_res_api_call_failure(t *testing.T) { require.NoError(t, err) removeResponse := appsec.AdvancedSettingsPIILearningResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPIILearning/PIILearning.json"), &removeResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -137,7 +138,7 @@ func TestAkamaiAdvancedSettingsPIILearning_res_api_call_failure(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsPIILearning/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsPIILearning/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_pii_learning.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pragma_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pragma_test.go index f72d06c9e..efe17cede 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pragma_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_pragma_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiAdvancedSettingsPragma_res_basic(t *testing.T) { client := &appsec.Mock{} updateResponse := appsec.UpdateAdvancedSettingsPragmaResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &updateResponse) require.NoError(t, err) deleteResponse := appsec.UpdateAdvancedSettingsPragmaResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &deleteResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &deleteResponse) require.NoError(t, err) getResponse := appsec.GetAdvancedSettingsPragmaResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPragma/AdvancedSettingsPragma.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiAdvancedSettingsPragma_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsPragma/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsPragma/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_pragma_header.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_prefetch_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_prefetch_test.go index 2c45aa96f..13b2ee976 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_prefetch_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_prefetch_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiAdvancedSettingsPrefetch_res_basic(t *testing.T) { client := &appsec.Mock{} updateResponse := appsec.UpdateAdvancedSettingsPrefetchResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &updateResponse) require.NoError(t, err) deleteResopnse := appsec.UpdateAdvancedSettingsPrefetchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &deleteResopnse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &deleteResopnse) require.NoError(t, err) getResponse := appsec.GetAdvancedSettingsPrefetchResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsPrefetch/AdvancedSettingsPrefetch.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiAdvancedSettingsPrefetch_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsPrefetch/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsPrefetch/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_prefetch.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_request_body_test.go b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_request_body_test.go index 6a757e413..d440e04de 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_request_body_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_advanced_settings_request_body_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -14,7 +15,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { var ( configVersion = func(t *testing.T, configId int, client *appsec.Mock) appsec.GetConfigurationResponse { configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -27,7 +28,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { requestBodyRead = func(t *testing.T, configId int, version int, policyId string, client *appsec.Mock, numberOfTimes int) { requestBodyResponse := appsec.GetAdvancedSettingsRequestBodyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &requestBodyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &requestBodyResponse) require.NoError(t, err) client.On("GetAdvancedSettingsRequestBody", @@ -39,7 +40,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { updateRequestBody = func(t *testing.T, updateRequestBody appsec.UpdateAdvancedSettingsRequestBodyRequest, client *appsec.Mock, numberOfTimes int) { updateRequestBodyResponse := appsec.UpdateAdvancedSettingsRequestBodyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &updateRequestBodyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &updateRequestBodyResponse) require.NoError(t, err) client.On("UpdateAdvancedSettingsRequestBody", @@ -50,7 +51,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { removeRequestBody = func(t *testing.T, updateRequestBody appsec.RemoveAdvancedSettingsRequestBodyRequest, client *appsec.Mock, numberOfTimes int) { removeRequestBodyResponse := appsec.RemoveAdvancedSettingsRequestBodyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &removeRequestBodyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAdvancedSettingsRequestBody/AdvancedSettingsRequestBody.json"), &removeRequestBodyResponse) require.NoError(t, err) client.On("RemoveAdvancedSettingsRequestBody", @@ -78,7 +79,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsRequestBody/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsRequestBody/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_request_body.test", "id", "43253:"), ), @@ -109,7 +110,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsRequestBody/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsRequestBody/match_by_id.tf"), }, { ImportState: true, @@ -142,7 +143,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsRequestBody/update_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsRequestBody/update_by_policy_id.tf"), }, { ImportState: true, @@ -176,7 +177,7 @@ func TestAkamaiAdvancedSettingsRequestBodyResConfig(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAdvancedSettingsRequestBody/update_by_policy_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAdvancedSettingsRequestBody/update_by_policy_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_advanced_settings_request_body.policy", "id", "43253:test_policy"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_api_constraints_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_api_constraints_protection_test.go index 6cf32fa91..742395ae5 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_api_constraints_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_api_constraints_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiAPICoProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateAPIConstraintsProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAPIConstraintsProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAPIConstraintsProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetAPIConstraintsProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAPIConstraintsProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAPIConstraintsProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateAPIConstraintsProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAPIConstraintsProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAPIConstraintsProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetAPIConstraintsProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAPIConstraintsProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAPIConstraintsProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -92,14 +93,14 @@ func TestAkamaiAPICoProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAPIConstraintsProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAPIConstraintsProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_api_constraints_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_api_constraints_protection.test", "enabled", "false"), ), }, { - Config: loadFixtureString("testdata/TestResAPIConstraintsProtection/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAPIConstraintsProtection/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_api_constraints_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_api_constraints_protection.test", "enabled", "true"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_api_request_constraints_test.go b/pkg/providers/appsec/resource_akamai_appsec_api_request_constraints_test.go index 3d894b2ca..44db99332 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_api_request_constraints_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_api_request_constraints_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiApiRequestConstraints_res_basic(t *testing.T) { client := &appsec.Mock{} updateResponse := appsec.UpdateApiRequestConstraintsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &updateResponse) require.NoError(t, err) getResponse := appsec.GetApiRequestConstraintsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &getResponse) require.NoError(t, err) deleteResponse := appsec.RemoveApiRequestConstraintsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &deleteResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResApiRequestConstraints/ApiRequestConstraints.json"), &deleteResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiApiRequestConstraints_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResApiRequestConstraints/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResApiRequestConstraints/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_api_request_constraints.test", "id", "43253:AAAA_81230:1"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_attack_group_test.go b/pkg/providers/appsec/resource_akamai_appsec_attack_group_test.go index 782a14c8c..21b5eb0d7 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_attack_group_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_attack_group_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -16,19 +17,19 @@ func TestAkamaiAttackGroup_res_basic(t *testing.T) { t.Run("match by AttackGroup ID", func(t *testing.T) { client := &appsec.Mock{} - conditionExceptionJSON := loadFixtureString("testdata/TestResAttackGroup/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureString(t, "testdata/TestResAttackGroup/ConditionException.json") conditionExceptionRawMessage := json.RawMessage(conditionExceptionJSON) updateResponse := appsec.UpdateAttackGroupResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAttackGroup/AttackGroup.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAttackGroup/AttackGroup.json"), &updateResponse) require.NoError(t, err) getResponse := appsec.GetAttackGroupResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAttackGroup/AttackGroup.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAttackGroup/AttackGroup.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -57,7 +58,7 @@ func TestAkamaiAttackGroup_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAttackGroup/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAttackGroup/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_attack_group.test", "id", "43253:AAAA_81230:SQL"), ), @@ -75,19 +76,19 @@ func TestAkamaiAttackGroup_res_error_updating_attack_group(t *testing.T) { t.Run("match by AttackGroup ID", func(t *testing.T) { client := &appsec.Mock{} - conditionExceptionJSON := loadFixtureString("testdata/TestResAttackGroup/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureString(t, "testdata/TestResAttackGroup/ConditionException.json") conditionExceptionRawMessage := json.RawMessage(conditionExceptionJSON) updateResponse := appsec.UpdateAttackGroupResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResAttackGroup/AttackGroup.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAttackGroup/AttackGroup.json"), &updateResponse) require.NoError(t, err) getResponse := appsec.GetAttackGroupResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResAttackGroup/AttackGroup.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResAttackGroup/AttackGroup.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -106,7 +107,7 @@ func TestAkamaiAttackGroup_res_error_updating_attack_group(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResAttackGroup/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResAttackGroup/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_attack_group.test", "id", "43253:AAAA_81230:SQL"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_bypass_network_lists_test.go b/pkg/providers/appsec/resource_akamai_appsec_bypass_network_lists_test.go index afe02af71..603150921 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_bypass_network_lists_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_bypass_network_lists_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiBypassNetworkLists_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -24,15 +25,15 @@ func TestAkamaiBypassNetworkLists_res_basic(t *testing.T) { ).Return(&config, nil) updateWAPBypassNetworkListsResponse := appsec.UpdateWAPBypassNetworkListsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResBypassNetworkLists/BypassNetworkLists.json"), &updateWAPBypassNetworkListsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResBypassNetworkLists/BypassNetworkLists.json"), &updateWAPBypassNetworkListsResponse) require.NoError(t, err) getWAPBypassNetworkListsResponse := appsec.GetWAPBypassNetworkListsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResBypassNetworkLists/BypassNetworkLists.json"), &getWAPBypassNetworkListsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResBypassNetworkLists/BypassNetworkLists.json"), &getWAPBypassNetworkListsResponse) require.NoError(t, err) removeWAPBypassNetworkListsResponse := appsec.RemoveWAPBypassNetworkListsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResBypassNetworkLists/RemoveNetworkLists.json"), &removeWAPBypassNetworkListsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResBypassNetworkLists/RemoveNetworkLists.json"), &removeWAPBypassNetworkListsResponse) require.NoError(t, err) client.On("GetWAPBypassNetworkLists", @@ -56,7 +57,7 @@ func TestAkamaiBypassNetworkLists_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResBypassNetworkLists/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResBypassNetworkLists/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_bypass_network_lists.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_configuration_rename_test.go b/pkg/providers/appsec/resource_akamai_appsec_configuration_rename_test.go index 88429209f..fb3ce3e6b 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_configuration_rename_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_configuration_rename_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAkamaiConfigurationRename_res_basic(t *testing.T) { client := &appsec.Mock{} updateConfigurationResponse := appsec.UpdateConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfigurationRename/ConfigurationUpdate.json"), &updateConfigurationResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfigurationRename/ConfigurationUpdate.json"), &updateConfigurationResponse) require.NoError(t, err) getConfigurationResponse := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfigurationRename/Configuration.json"), &getConfigurationResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfigurationRename/Configuration.json"), &getConfigurationResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -38,13 +39,13 @@ func TestAkamaiConfigurationRename_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResConfigurationRename/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResConfigurationRename/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_configuration_rename.test", "id", "432531"), ), }, { - Config: loadFixtureString("testdata/TestResConfigurationRename/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResConfigurationRename/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_configuration_rename.test", "id", "432531"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_configuration_test.go b/pkg/providers/appsec/resource_akamai_appsec_configuration_test.go index 3b1095495..d661b11d8 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_configuration_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_configuration_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,23 +18,23 @@ func TestAkamaiConfiguration_res_basic(t *testing.T) { client := &appsec.Mock{} createConfigResponse := appsec.CreateConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/ConfigurationCreate.json"), &createConfigResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/ConfigurationCreate.json"), &createConfigResponse) require.NoError(t, err) readConfigResponse := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/Configuration.json"), &readConfigResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/Configuration.json"), &readConfigResponse) require.NoError(t, err) deleteConfigResponse := appsec.RemoveConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/Configuration.json"), &deleteConfigResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/Configuration.json"), &deleteConfigResponse) require.NoError(t, err) getConfigurationVersionsResponse := appsec.GetConfigurationVersionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/ConfigurationVersions.json"), &getConfigurationVersionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/ConfigurationVersions.json"), &getConfigurationVersionsResponse) require.NoError(t, err) getSelectedHostnamesResponse := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponse) require.NoError(t, err) client.On("GetSelectedHostnames", @@ -67,7 +68,7 @@ func TestAkamaiConfiguration_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResConfiguration/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_configuration.test", "id", "43253"), ), @@ -85,23 +86,23 @@ func TestAkamaiConfiguration_res_error_updating_configuration(t *testing.T) { client := &appsec.Mock{} createConfigResponse := appsec.CreateConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/ConfigurationCreate.json"), &createConfigResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/ConfigurationCreate.json"), &createConfigResponse) require.NoError(t, err) readConfigResponse := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/Configuration.json"), &readConfigResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/Configuration.json"), &readConfigResponse) require.NoError(t, err) deleteConfigResponse := appsec.RemoveConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/Configuration.json"), &deleteConfigResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/Configuration.json"), &deleteConfigResponse) require.NoError(t, err) getConfigurationVersionsResponse := appsec.GetConfigurationVersionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/ConfigurationVersions.json"), &getConfigurationVersionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/ConfigurationVersions.json"), &getConfigurationVersionsResponse) require.NoError(t, err) hns := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSelectedHostname/SelectedHostname.json"), &hns) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSelectedHostname/SelectedHostname.json"), &hns) require.NoError(t, err) client.On("GetSelectedHostnames", @@ -140,13 +141,13 @@ func TestAkamaiConfiguration_res_error_updating_configuration(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResConfiguration/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_configuration.test", "id", "43253"), ), }, { - Config: loadFixtureString("testdata/TestResConfiguration/modify_contract.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/modify_contract.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_configuration.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_custom_deny_test.go b/pkg/providers/appsec/resource_akamai_appsec_custom_deny_test.go index 379ab436d..223acac04 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_custom_deny_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_custom_deny_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiCustomDeny_res_basic(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) client.On("GetConfiguration", mock.Anything, @@ -23,25 +24,25 @@ func TestAkamaiCustomDeny_res_basic(t *testing.T) { ).Return(&configResponse, nil) createResponse := appsec.CreateCustomDenyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyCreateResponse.json"), &createResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyCreateResponse.json"), &createResponse) require.NoError(t, err) - createRequestJSON := loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyWithPreventBrowserCacheTrue.json") + createRequestJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyWithPreventBrowserCacheTrue.json") client.On("CreateCustomDeny", mock.Anything, appsec.CreateCustomDenyRequest{ConfigID: 43253, Version: 7, JsonPayloadRaw: createRequestJSON}, ).Return(&createResponse, nil) getResponse := appsec.GetCustomDenyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyGetResponse.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyGetResponse.json"), &getResponse) require.NoError(t, err) client.On("GetCustomDeny", mock.Anything, appsec.GetCustomDenyRequest{ConfigID: 43253, Version: 7, ID: "deny_custom_622918"}, ).Return(&getResponse, nil).Times(3) - updateRequestJSON := loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyWithPreventBrowserCacheFalse.json") + updateRequestJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyWithPreventBrowserCacheFalse.json") updateResponse := appsec.UpdateCustomDenyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyUpdateResponse.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyUpdateResponse.json"), &updateResponse) require.NoError(t, err) client.On("UpdateCustomDeny", mock.Anything, @@ -49,7 +50,7 @@ func TestAkamaiCustomDeny_res_basic(t *testing.T) { ).Return(&updateResponse, nil) getResponseAfterUpdate := appsec.GetCustomDenyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomDeny/CustomDenyGetResponseAfterUpdate.json"), &getResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDenyGetResponseAfterUpdate.json"), &getResponseAfterUpdate) require.NoError(t, err) client.On("GetCustomDeny", mock.Anything, @@ -57,7 +58,7 @@ func TestAkamaiCustomDeny_res_basic(t *testing.T) { ).Return(&getResponseAfterUpdate, nil).Twice() removeResponse := appsec.RemoveCustomDenyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomDeny/CustomDeny.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomDeny/CustomDeny.json"), &removeResponse) require.NoError(t, err) client.On("RemoveCustomDeny", mock.Anything, @@ -70,13 +71,13 @@ func TestAkamaiCustomDeny_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCustomDeny/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomDeny/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_deny.test", "id", "43253:deny_custom_622918"), ), }, { - Config: loadFixtureString("testdata/TestResCustomDeny/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomDeny/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_deny.test", "id", "43253:deny_custom_622918"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_custom_rule_action_test.go b/pkg/providers/appsec/resource_akamai_appsec_custom_rule_action_test.go index 83526ebdd..89200ee33 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_custom_rule_action_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_custom_rule_action_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiCustomRuleAction_res_basic(t *testing.T) { client := &appsec.Mock{} getConfigResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &getConfigResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &getConfigResponse) require.NoError(t, err) client.On("GetConfiguration", mock.Anything, @@ -23,7 +24,7 @@ func TestAkamaiCustomRuleAction_res_basic(t *testing.T) { ).Return(&getConfigResponse, nil) updateResponse := appsec.UpdateCustomRuleActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRuleAction/CustomRuleActionUpdated.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRuleAction/CustomRuleActionUpdated.json"), &updateResponse) require.NoError(t, err) client.On("UpdateCustomRuleAction", mock.Anything, @@ -31,7 +32,7 @@ func TestAkamaiCustomRuleAction_res_basic(t *testing.T) { ).Return(&updateResponse, nil) getResponse := appsec.GetCustomRuleActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRuleAction/CustomRuleAction.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRuleAction/CustomRuleAction.json"), &getResponse) require.NoError(t, err) client.On("GetCustomRuleAction", mock.Anything, @@ -44,7 +45,7 @@ func TestAkamaiCustomRuleAction_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCustomRuleAction/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomRuleAction/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_rule_action.test", "id", "43253:AAAA_81230:60036362"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_custom_rule_test.go b/pkg/providers/appsec/resource_akamai_appsec_custom_rule_test.go index 364c7205f..19f68b45b 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_custom_rule_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_custom_rule_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,27 +18,27 @@ func TestAkamaiCustomRule_res_basic(t *testing.T) { client := &appsec.Mock{} createCustomRuleResponse := appsec.CreateCustomRuleResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRule.json"), &createCustomRuleResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRule.json"), &createCustomRuleResponse) require.NoError(t, err) getCustomRuleResponse := appsec.GetCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRule.json"), &getCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRule.json"), &getCustomRuleResponse) require.NoError(t, err) updateCustomRuleResponse := appsec.UpdateCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRuleUpdated.json"), &updateCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRuleUpdated.json"), &updateCustomRuleResponse) require.NoError(t, err) getCustomRuleAfterUpdate := appsec.GetCustomRuleResponse{} // custom rule after update - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRuleUpdated.json"), &getCustomRuleAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRuleUpdated.json"), &getCustomRuleAfterUpdate) require.NoError(t, err) removeCustomRuleResponse := appsec.RemoveCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRulesDeleted.json"), &removeCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRulesDeleted.json"), &removeCustomRuleResponse) require.NoError(t, err) getCustomRulesAfterDelete := appsec.GetCustomRulesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRulesForDelete.json"), &getCustomRulesAfterDelete) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRulesForDelete.json"), &getCustomRulesAfterDelete) require.NoError(t, err) client.On("GetCustomRules", @@ -57,13 +58,13 @@ func TestAkamaiCustomRule_res_basic(t *testing.T) { appsec.GetCustomRuleRequest{ConfigID: 43253, ID: 661699}, ).Return(&getCustomRuleAfterUpdate, nil) - updateCustomRuleJSON := loadFixtureBytes("testdata/TestResCustomRule/UpdateCustomRule.json") + updateCustomRuleJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/UpdateCustomRule.json") client.On("UpdateCustomRule", mock.Anything, appsec.UpdateCustomRuleRequest{ConfigID: 43253, ID: 661699, Version: 0, JsonPayloadRaw: updateCustomRuleJSON}, ).Return(&updateCustomRuleResponse, nil) - createCustomRuleJSON := loadFixtureBytes("testdata/TestResCustomRule/CreateCustomRule.json") + createCustomRuleJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CreateCustomRule.json") client.On("CreateCustomRule", mock.Anything, appsec.CreateCustomRuleRequest{ConfigID: 43253, Version: 0, JsonPayloadRaw: createCustomRuleJSON}, @@ -80,13 +81,13 @@ func TestAkamaiCustomRule_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCustomRule/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomRule/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_rule.test", "id", "43253:661699"), ), }, { - Config: loadFixtureString("testdata/TestResCustomRule/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomRule/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_rule.test", "id", "43253:661699"), ), @@ -105,27 +106,27 @@ func TestAkamaiCustomRule_res_error_removing_active_rule(t *testing.T) { client := &appsec.Mock{} updateCustomRuleResponse := appsec.UpdateCustomRuleResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRuleUpdated.json"), &updateCustomRuleResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRuleUpdated.json"), &updateCustomRuleResponse) require.NoError(t, err) createCustomRuleResponse := appsec.CreateCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRule.json"), &createCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRule.json"), &createCustomRuleResponse) require.NoError(t, err) getCustomRuleResponse := appsec.GetCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRule.json"), &getCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRule.json"), &getCustomRuleResponse) require.NoError(t, err) getCustomRuleResponseAfterUpdate := appsec.GetCustomRuleResponse{} // custom rule after update - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRuleUpdated.json"), &getCustomRuleResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRuleUpdated.json"), &getCustomRuleResponseAfterUpdate) require.NoError(t, err) removeCustomRuleResponse := appsec.RemoveCustomRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRulesDeleted.json"), &removeCustomRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRulesDeleted.json"), &removeCustomRuleResponse) require.NoError(t, err) getCustomRulesAfterDelete := appsec.GetCustomRulesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResCustomRule/CustomRulesForDelete.json"), &getCustomRulesAfterDelete) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CustomRulesForDelete.json"), &getCustomRulesAfterDelete) require.NoError(t, err) client.On("GetCustomRules", @@ -145,13 +146,13 @@ func TestAkamaiCustomRule_res_error_removing_active_rule(t *testing.T) { appsec.GetCustomRuleRequest{ConfigID: 43253, ID: 661699}, ).Return(&getCustomRuleResponseAfterUpdate, nil) - updateCustomRuleJSON := loadFixtureBytes("testdata/TestResCustomRule/UpdateCustomRule.json") + updateCustomRuleJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/UpdateCustomRule.json") client.On("UpdateCustomRule", mock.Anything, appsec.UpdateCustomRuleRequest{ConfigID: 43253, ID: 661699, Version: 0, JsonPayloadRaw: updateCustomRuleJSON}, ).Return(nil, fmt.Errorf("RemoveCustomRule request failed")) - createCustomRuleJSON := loadFixtureBytes("testdata/TestResCustomRule/CreateCustomRule.json") + createCustomRuleJSON := testutils.LoadFixtureBytes(t, "testdata/TestResCustomRule/CreateCustomRule.json") client.On("CreateCustomRule", mock.Anything, appsec.CreateCustomRuleRequest{ConfigID: 43253, Version: 0, JsonPayloadRaw: createCustomRuleJSON}, @@ -168,13 +169,13 @@ func TestAkamaiCustomRule_res_error_removing_active_rule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCustomRule/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomRule/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_rule.test", "id", "43253:661699"), ), }, { - Config: loadFixtureString("testdata/TestResCustomRule/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCustomRule/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_custom_rule.test", "id", "43253:661699"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_eval_group_test.go b/pkg/providers/appsec/resource_akamai_appsec_eval_group_test.go index 1ef99bb19..44bc3bbc9 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_eval_group_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_eval_group_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -16,19 +17,19 @@ func TestAkamaiEvalGroup_res_basic(t *testing.T) { t.Run("match by AttackGroup ID", func(t *testing.T) { client := &appsec.Mock{} - conditionExceptionJSON := loadFixtureString("testdata/TestResEvalGroup/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureString(t, "testdata/TestResEvalGroup/ConditionException.json") conditionExceptionRawMessage := json.RawMessage(conditionExceptionJSON) updateResponse := appsec.UpdateAttackGroupResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResEvalGroup/AttackGroup.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalGroup/AttackGroup.json"), &updateResponse) require.NoError(t, err) getResponse := appsec.GetAttackGroupResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEvalGroup/AttackGroup.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalGroup/AttackGroup.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -57,7 +58,7 @@ func TestAkamaiEvalGroup_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResEvalGroup/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEvalGroup/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval_group.test", "id", "43253:AAAA_81230:SQL"), ), @@ -75,19 +76,19 @@ func TestAkamaiEvalGroup_res_error_updating_eval_group(t *testing.T) { t.Run("match by AttackGroup ID", func(t *testing.T) { client := &appsec.Mock{} - conditionExceptionJSON := loadFixtureString("testdata/TestResEvalGroup/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureString(t, "testdata/TestResEvalGroup/ConditionException.json") conditionExceptionRawMessage := json.RawMessage(conditionExceptionJSON) updateResponse := appsec.UpdateAttackGroupResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResEvalGroup/AttackGroup.json"), &updateResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalGroup/AttackGroup.json"), &updateResponse) require.NoError(t, err) getResponse := appsec.GetAttackGroupResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEvalGroup/AttackGroup.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalGroup/AttackGroup.json"), &getResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -106,7 +107,7 @@ func TestAkamaiEvalGroup_res_error_updating_eval_group(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResEvalGroup/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEvalGroup/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval_group.test", "id", "43253:AAAA_81230:SQL"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_eval_penalty_box_test.go b/pkg/providers/appsec/resource_akamai_appsec_eval_penalty_box_test.go index d7df3a1a9..df68067bb 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_eval_penalty_box_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_eval_penalty_box_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiEvalPenaltyBox_res_basic(t *testing.T) { client := &appsec.Mock{} updResp := appsec.UpdatePenaltyBoxResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResEvalPenaltyBox/PenaltyBox.json"), &updResp) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalPenaltyBox/PenaltyBox.json"), &updResp) require.NoError(t, err) getResp := appsec.GetPenaltyBoxResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEvalPenaltyBox/PenaltyBox.json"), &getResp) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalPenaltyBox/PenaltyBox.json"), &getResp) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiEvalPenaltyBox_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResEvalPenaltyBox/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEvalPenaltyBox/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval_penalty_box.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_eval_rule_test.go b/pkg/providers/appsec/resource_akamai_appsec_eval_rule_test.go index d053c07a9..1dab46cda 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_eval_rule_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_eval_rule_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiEvalRule_res_basic(t *testing.T) { client := &appsec.Mock{} updateEvalRuleResponse := appsec.UpdateEvalRuleResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResEvalRule/EvalRuleUpdated.json"), &updateEvalRuleResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalRule/EvalRuleUpdated.json"), &updateEvalRuleResponse) require.NoError(t, err) getEvalRuleResponse := appsec.GetEvalRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEvalRule/EvalRule.json"), &getEvalRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalRule/EvalRule.json"), &getEvalRuleResponse) require.NoError(t, err) removeEvalRuleActionResponse := appsec.UpdateEvalRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEvalRule/EvalRule.json"), &removeEvalRuleActionResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEvalRule/EvalRule.json"), &removeEvalRuleActionResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -40,7 +41,7 @@ func TestAkamaiEvalRule_res_basic(t *testing.T) { appsec.GetEvalRuleRequest{ConfigID: 43253, Version: 7, PolicyID: "AAAA_81230", RuleID: 12345}, ).Return(&getEvalRuleResponse, nil) - conditionExceptionJSON := loadFixtureBytes("testdata/TestResEvalRule/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureBytes(t, "testdata/TestResEvalRule/ConditionException.json") client.On("UpdateEvalRule", mock.Anything, appsec.UpdateEvalRuleRequest{ConfigID: 43253, Version: 7, PolicyID: "AAAA_81230", Action: "alert", RuleID: 12345, JsonPayloadRaw: conditionExceptionJSON}, ).Return(&updateEvalRuleResponse, nil) @@ -56,7 +57,7 @@ func TestAkamaiEvalRule_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResEvalRule/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEvalRule/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval_rule.test", "id", "43253:AAAA_81230:12345"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_eval_test.go b/pkg/providers/appsec/resource_akamai_appsec_eval_test.go index 20170004a..ced514c53 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_eval_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_eval_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiEval_res_basic(t *testing.T) { client := &appsec.Mock{} updateEvalResponse := appsec.UpdateEvalResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResEval/EvalStart.json"), &updateEvalResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEval/EvalStart.json"), &updateEvalResponse) require.NoError(t, err) getEvalResponse := appsec.GetEvalResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEval/EvalStart.json"), &getEvalResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEval/EvalStart.json"), &getEvalResponse) require.NoError(t, err) removeEvalResponse := appsec.RemoveEvalResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResEval/EvalStop.json"), &removeEvalResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResEval/EvalStop.json"), &removeEvalResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,13 +57,13 @@ func TestAkamaiEval_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResEval/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEval/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval.test", "id", "43253:AAAA_81230"), ), }, { - Config: loadFixtureString("testdata/TestResEval/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResEval/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_eval.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_ip_geo_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_ip_geo_protection_test.go index 58de6b68b..7a33ec54f 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_ip_geo_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_ip_geo_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiIPGeoProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateIPGeoProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResIPGeoProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResIPGeoProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetIPGeoProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResIPGeoProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResIPGeoProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateIPGeoProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResIPGeoProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResIPGeoProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetIPGeoProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResIPGeoProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResIPGeoProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -92,14 +93,14 @@ func TestAkamaiIPGeoProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeoProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeoProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_ip_geo_protection.test", "enabled", "false"), ), }, { - Config: loadFixtureString("testdata/TestResIPGeoProtection/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeoProtection/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_ip_geo_protection.test", "enabled", "true"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_ip_geo_test.go b/pkg/providers/appsec/resource_akamai_appsec_ip_geo_test.go index a8e3a8f95..c29d2bdd7 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_ip_geo_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_ip_geo_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -14,7 +15,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { var ( configVersion = func(t *testing.T, configId int, client *appsec.Mock) appsec.GetConfigurationResponse { configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) client.On("GetConfiguration", @@ -27,7 +28,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { getIPGeoResponse = func(t *testing.T, configId int, version int, policyId string, path string, client *appsec.Mock) appsec.GetIPGeoResponse { getIPGeoResponse := appsec.GetIPGeoResponse{} - err := json.Unmarshal(loadFixtureBytes(path), &getIPGeoResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, path), &getIPGeoResponse) require.NoError(t, err) client.On("GetIPGeo", @@ -40,7 +41,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { updateIPGeoResponse = func(t *testing.T, configId int, version int, policyId string, path string, request appsec.UpdateIPGeoRequest, client *appsec.Mock) appsec.UpdateIPGeoResponse { updateIPGeoResponse := appsec.UpdateIPGeoResponse{} - err := json.Unmarshal(loadFixtureBytes(path), &updateIPGeoResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, path), &updateIPGeoResponse) require.NoError(t, err) client.On("UpdateIPGeo", @@ -52,7 +53,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { updateIPGeoProtectionResponseAllProtectionsFalse = func(t *testing.T, configId int, version int, policyId string, path string, client *appsec.Mock) appsec.UpdateIPGeoProtectionResponse { updateIPGeoProtectionResponseAllProtectionsFalse := appsec.UpdateIPGeoProtectionResponse{} - err := json.Unmarshal(loadFixtureBytes(path), &updateIPGeoProtectionResponseAllProtectionsFalse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, path), &updateIPGeoProtectionResponseAllProtectionsFalse) require.NoError(t, err) client.On("UpdateIPGeoProtection", @@ -104,7 +105,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeo/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeo/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo.test", "id", "43253:AAAA_81230"), ), @@ -160,7 +161,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeo/ukraine_match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeo/ukraine_match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo.test1", "id", "43253:AAAA_81230"), ), @@ -201,7 +202,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeo/allow.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeo/allow.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo.test", "id", "43253:AAAA_81230"), ), @@ -234,7 +235,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeo/block_with_empty_lists.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeo/block_with_empty_lists.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo.test", "id", "43253:AAAA_81230"), ), @@ -268,7 +269,7 @@ func TestAkamaiIPGeo_res_block(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResIPGeo/allow_with_empty_lists.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResIPGeo/allow_with_empty_lists.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_ip_geo.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_action_test.go b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_action_test.go index e547a90e4..99c8d300c 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_action_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_action_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,27 +16,27 @@ func TestAkamaiMalwarePolicyAction_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) actionAfterCreate := appsec.UpdateMalwarePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyAction/ActionAfterCreate.json"), &actionAfterCreate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyAction/ActionAfterCreate.json"), &actionAfterCreate) require.NoError(t, err) allActionsAfterCreate := appsec.GetMalwarePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyAction/AllActionsAfterCreate.json"), &allActionsAfterCreate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyAction/AllActionsAfterCreate.json"), &allActionsAfterCreate) require.NoError(t, err) actionAfterUpdate := appsec.UpdateMalwarePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyAction/ActionAfterUpdate.json"), &actionAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyAction/ActionAfterUpdate.json"), &actionAfterUpdate) require.NoError(t, err) allActionsAfterUpdate := appsec.GetMalwarePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyAction/AllActionsAfterUpdate.json"), &allActionsAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyAction/AllActionsAfterUpdate.json"), &allActionsAfterUpdate) require.NoError(t, err) actionAfterDelete := appsec.UpdateMalwarePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyAction/ActionAfterDelete.json"), &actionAfterDelete) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyAction/ActionAfterDelete.json"), &actionAfterDelete) require.NoError(t, err) client.On("GetConfiguration", @@ -97,7 +98,7 @@ func TestAkamaiMalwarePolicyAction_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMalwarePolicyAction/create.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicyAction/create.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy_action.test", "id", "43253:AAAA_81230:135355"), resource.TestCheckResourceAttr("akamai_appsec_malware_policy_action.test", "action", "none"), @@ -105,7 +106,7 @@ func TestAkamaiMalwarePolicyAction_res_basic(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResMalwarePolicyAction/update.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicyAction/update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy_action.test", "id", "43253:AAAA_81230:135355"), resource.TestCheckResourceAttr("akamai_appsec_malware_policy_action.test", "action", "alert"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_actions_test.go b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_actions_test.go index 534eb3e49..9615c8d39 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_actions_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_actions_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,10 +16,10 @@ func TestAkamaiMalwarePolicyActions_res_basic(t *testing.T) { client := &appsec.Mock{} updateMalwarePolicyActionsResponse := appsec.UpdateMalwarePolicyActionsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyActions/MalwarePolicyActions.json"), &updateMalwarePolicyActionsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyActions/MalwarePolicyActions.json"), &updateMalwarePolicyActionsResponse) require.NoError(t, err) getMalwarePolicyActionsResponse := appsec.GetMalwarePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicyActions/MalwarePolicyActions.json"), &getMalwarePolicyActionsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicyActions/MalwarePolicyActions.json"), &getMalwarePolicyActionsResponse) require.NoError(t, err) client.On("GetMalwarePolicyActions", @@ -37,14 +38,14 @@ func TestAkamaiMalwarePolicyActions_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMalwarePolicyActions/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicyActions/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy_actions.test", "id", "135355"), ), }, { - Config: loadFixtureString("testdata/TestResMalwarePolicyActions/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicyActions/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy_actions.test", "id", "135355"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_test.go b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_test.go index e4f0a7b77..ecdfabebd 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_malware_policy_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_malware_policy_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -16,16 +17,16 @@ func TestAkamaiMalwarePolicy_res_basic(t *testing.T) { // Messages for test step 1 configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) createBody := appsec.MalwarePolicyBody{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/CreateMalwarePolicy.json"), &createBody) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/CreateMalwarePolicy.json"), &createBody) require.NoError(t, err) createResponse := appsec.MalwarePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/MalwarePolicy.json"), &createResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/MalwarePolicy.json"), &createResponse) require.NoError(t, err) getResponse := appsec.MalwarePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/MalwarePolicy.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/MalwarePolicy.json"), &getResponse) require.NoError(t, err) // Calls made during test step 1 @@ -47,13 +48,13 @@ func TestAkamaiMalwarePolicy_res_basic(t *testing.T) { // Messages for test step 2 updateBody := appsec.MalwarePolicyBody{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/UpdateMalwarePolicy.json"), &updateBody) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/UpdateMalwarePolicy.json"), &updateBody) require.NoError(t, err) updateResponse := appsec.MalwarePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/MalwarePolicyUpdated.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/MalwarePolicyUpdated.json"), &updateResponse) require.NoError(t, err) getUpdatedResponse := appsec.MalwarePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwarePolicy/MalwarePolicyUpdated.json"), &getUpdatedResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwarePolicy/MalwarePolicyUpdated.json"), &getUpdatedResponse) require.NoError(t, err) // Calls made during test step 2 @@ -73,13 +74,13 @@ func TestAkamaiMalwarePolicy_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMalwarePolicy/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicy/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy.test", "id", "43253:134644"), ), }, { - Config: loadFixtureString("testdata/TestResMalwarePolicy/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwarePolicy/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_policy.test", "id", "43253:134644"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_malware_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_malware_protection_test.go index bd662108b..f4e23dc23 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_malware_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_malware_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiMalwareProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateMalwareProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwareProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwareProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetMalwareProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwareProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwareProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateMalwareProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwareProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwareProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetMalwareProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMalwareProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMalwareProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -71,7 +72,7 @@ func TestAkamaiMalwareProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMalwareProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMalwareProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_malware_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_malware_protection.test", "enabled", "false"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_match_target_sequence_test.go b/pkg/providers/appsec/resource_akamai_appsec_match_target_sequence_test.go index 505fabe25..c782ff282 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_match_target_sequence_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_match_target_sequence_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiMatchTargetSequence_res_basic(t *testing.T) { client := &appsec.Mock{} updateSequenceResponse := appsec.UpdateMatchTargetSequenceResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTargetSequence/MatchTargetSequenceResp.json"), &updateSequenceResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTargetSequence/MatchTargetSequenceResp.json"), &updateSequenceResponse) require.NoError(t, err) getSequenceResponse := appsec.GetMatchTargetSequenceResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTargetSequence/MatchTargetSequence.json"), &getSequenceResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTargetSequence/MatchTargetSequence.json"), &getSequenceResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,13 +48,13 @@ func TestAkamaiMatchTargetSequence_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMatchTargetSequence/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMatchTargetSequence/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_match_target_sequence.test", "id", "43253:website"), ), }, { - Config: loadFixtureString("testdata/TestResMatchTargetSequence/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMatchTargetSequence/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_match_target_sequence.test", "id", "43253:website"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_match_target_test.go b/pkg/providers/appsec/resource_akamai_appsec_match_target_test.go index 6c3da7c7e..8bd5748c8 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_match_target_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_match_target_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,27 +16,27 @@ func TestAkamaiMatchTarget_res_basic(t *testing.T) { client := &appsec.Mock{} updateMatchTargetResponse := appsec.UpdateMatchTargetResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTarget/MatchTargetUpdated.json"), &updateMatchTargetResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/MatchTargetUpdated.json"), &updateMatchTargetResponse) require.NoError(t, err) getMatchTargetResponse := appsec.GetMatchTargetResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTarget/MatchTarget.json"), &getMatchTargetResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/MatchTarget.json"), &getMatchTargetResponse) require.NoError(t, err) getMatchTargetResponseAfterUpdate := appsec.GetMatchTargetResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTarget/MatchTargetUpdated.json"), &getMatchTargetResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/MatchTargetUpdated.json"), &getMatchTargetResponseAfterUpdate) require.NoError(t, err) createMatchTargetResponse := appsec.CreateMatchTargetResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTarget/MatchTargetCreated.json"), &createMatchTargetResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/MatchTargetCreated.json"), &createMatchTargetResponse) require.NoError(t, err) removeMatchTargetResponse := appsec.RemoveMatchTargetResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResMatchTarget/MatchTargetCreated.json"), &removeMatchTargetResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/MatchTargetCreated.json"), &removeMatchTargetResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -53,13 +54,13 @@ func TestAkamaiMatchTarget_res_basic(t *testing.T) { appsec.GetMatchTargetRequest{ConfigID: 43253, ConfigVersion: 7, TargetID: 3008967}, ).Return(&getMatchTargetResponseAfterUpdate, nil) - createMatchTargetJSON := loadFixtureBytes("testdata/TestResMatchTarget/CreateMatchTarget.json") + createMatchTargetJSON := testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/CreateMatchTarget.json") client.On("CreateMatchTarget", mock.Anything, appsec.CreateMatchTargetRequest{Type: "", ConfigID: 43253, ConfigVersion: 7, JsonPayloadRaw: createMatchTargetJSON}, ).Return(&createMatchTargetResponse, nil) - updateMatchTargetJSON := loadFixtureBytes("testdata/TestResMatchTarget/UpdateMatchTarget.json") + updateMatchTargetJSON := testutils.LoadFixtureBytes(t, "testdata/TestResMatchTarget/UpdateMatchTarget.json") client.On("UpdateMatchTarget", mock.Anything, appsec.UpdateMatchTargetRequest{ConfigID: 43253, ConfigVersion: 7, TargetID: 3008967, JsonPayloadRaw: updateMatchTargetJSON}, @@ -76,13 +77,13 @@ func TestAkamaiMatchTarget_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResMatchTarget/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMatchTarget/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_match_target.test", "id", "43253:3008967"), ), }, { - Config: loadFixtureString("testdata/TestResMatchTarget/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResMatchTarget/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_match_target.test", "id", "43253:3008967"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_penalty_box_test.go b/pkg/providers/appsec/resource_akamai_appsec_penalty_box_test.go index a5d3fc6a6..bfde39952 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_penalty_box_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_penalty_box_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiPenaltyBox_res_basic(t *testing.T) { client := &appsec.Mock{} updatePenaltyBoxResponse := appsec.UpdatePenaltyBoxResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResPenaltyBox/PenaltyBox.json"), &updatePenaltyBoxResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResPenaltyBox/PenaltyBox.json"), &updatePenaltyBoxResponse) require.NoError(t, err) getPenaltyBoxResponse := appsec.GetPenaltyBoxResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResPenaltyBox/PenaltyBox.json"), &getPenaltyBoxResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResPenaltyBox/PenaltyBox.json"), &getPenaltyBoxResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiPenaltyBox_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResPenaltyBox/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResPenaltyBox/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_penalty_box.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_rate_policy_action_test.go b/pkg/providers/appsec/resource_akamai_appsec_rate_policy_action_test.go index c521bbd8b..0b2741bda 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_rate_policy_action_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_rate_policy_action_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,27 +16,27 @@ func TestAkamaiRatePolicyAction_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) actionAfterCreate := appsec.UpdateRatePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicyAction/ActionAfterCreate.json"), &actionAfterCreate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicyAction/ActionAfterCreate.json"), &actionAfterCreate) require.NoError(t, err) allActionsAfterCreate := appsec.GetRatePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicyAction/AllActionsAfterCreate.json"), &allActionsAfterCreate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicyAction/AllActionsAfterCreate.json"), &allActionsAfterCreate) require.NoError(t, err) actionAfterUpdate := appsec.UpdateRatePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicyAction/ActionAfterUpdate.json"), &actionAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicyAction/ActionAfterUpdate.json"), &actionAfterUpdate) require.NoError(t, err) allActionsAfterUpdate := appsec.GetRatePolicyActionsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicyAction/AllActionsAfterUpdate.json"), &allActionsAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicyAction/AllActionsAfterUpdate.json"), &allActionsAfterUpdate) require.NoError(t, err) actionAfterDelete := appsec.UpdateRatePolicyActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicyAction/ActionAfterDelete.json"), &actionAfterDelete) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicyAction/ActionAfterDelete.json"), &actionAfterDelete) require.NoError(t, err) client.On("GetConfiguration", @@ -97,7 +98,7 @@ func TestAkamaiRatePolicyAction_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResRatePolicyAction/create.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRatePolicyAction/create.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_policy_action.test", "id", "43253:AAAA_81230:135355"), resource.TestCheckResourceAttr("akamai_appsec_rate_policy_action.test", "ipv4_action", "none"), @@ -105,7 +106,7 @@ func TestAkamaiRatePolicyAction_res_basic(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResRatePolicyAction/update.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRatePolicyAction/update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_policy_action.test", "id", "43253:AAAA_81230:135355"), resource.TestCheckResourceAttr("akamai_appsec_rate_policy_action.test", "ipv4_action", "alert"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_rate_policy_test.go b/pkg/providers/appsec/resource_akamai_appsec_rate_policy_test.go index a474de929..7fa936196 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_rate_policy_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_rate_policy_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiRatePolicy_res_basic(t *testing.T) { client := &appsec.Mock{} configResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &configResponse) require.NoError(t, err) client.On("GetConfiguration", mock.Anything, @@ -23,16 +24,16 @@ func TestAkamaiRatePolicy_res_basic(t *testing.T) { ).Return(&configResponse, nil) createResponse := appsec.CreateRatePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicy/RatePolicy.json"), &createResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/RatePolicy.json"), &createResponse) require.NoError(t, err) - createRatePolicyJSON := loadFixtureBytes("testdata/TestResRatePolicy/CreateRatePolicy.json") + createRatePolicyJSON := testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/CreateRatePolicy.json") client.On("CreateRatePolicy", mock.Anything, appsec.CreateRatePolicyRequest{ConfigID: 43253, ConfigVersion: 7, JsonPayloadRaw: createRatePolicyJSON}, ).Return(&createResponse, nil) getResponse := appsec.GetRatePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicy/RatePolicy.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/RatePolicy.json"), &getResponse) require.NoError(t, err) client.On("GetRatePolicy", mock.Anything, @@ -48,16 +49,16 @@ func TestAkamaiRatePolicy_res_basic(t *testing.T) { ).Return(&getResponse, nil).Once() updateResponse := appsec.UpdateRatePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicy/RatePolicyUpdated.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/RatePolicyUpdated.json"), &updateResponse) require.NoError(t, err) - updateRatePolicyJSON := loadFixtureBytes("testdata/TestResRatePolicy/UpdateRatePolicy.json") + updateRatePolicyJSON := testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/UpdateRatePolicy.json") client.On("UpdateRatePolicy", mock.Anything, appsec.UpdateRatePolicyRequest{RatePolicyID: 134644, ConfigID: 43253, ConfigVersion: 7, JsonPayloadRaw: updateRatePolicyJSON}, ).Return(&updateResponse, nil) getResponseAfterUpdate := appsec.GetRatePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicy/RatePolicyUpdated.json"), &getResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/RatePolicyUpdated.json"), &getResponseAfterUpdate) require.NoError(t, err) client.On("GetRatePolicy", mock.Anything, @@ -65,7 +66,7 @@ func TestAkamaiRatePolicy_res_basic(t *testing.T) { ).Return(&getResponseAfterUpdate, nil).Twice() removeResponse := appsec.RemoveRatePolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRatePolicy/RatePolicyEmpty.json"), &removeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRatePolicy/RatePolicyEmpty.json"), &removeResponse) require.NoError(t, err) client.On("RemoveRatePolicy", mock.Anything, @@ -78,13 +79,13 @@ func TestAkamaiRatePolicy_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResRatePolicy/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRatePolicy/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_policy.test", "id", "43253:134644"), ), }, { - Config: loadFixtureString("testdata/TestResRatePolicy/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRatePolicy/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_policy.test", "id", "43253:134644"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_rate_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_rate_protection_test.go index 2f858f8dd..7c8e4d331 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_rate_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_rate_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiRateProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateRateProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRateProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRateProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetRateProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRateProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRateProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateRateProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRateProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRateProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetRateProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRateProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRateProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -92,14 +93,14 @@ func TestAkamaiRateProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResRateProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRateProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_rate_protection.test", "enabled", "false"), ), }, { - Config: loadFixtureString("testdata/TestResRateProtection/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRateProtection/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rate_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_rate_protection.test", "enabled", "true"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_reputation_analysis_test.go b/pkg/providers/appsec/resource_akamai_appsec_reputation_analysis_test.go index 448464a7e..cf6d6100f 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_reputation_analysis_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_reputation_analysis_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiReputationAnalysis_res_basic(t *testing.T) { client := &appsec.Mock{} updateReputationAnalysisResponse := appsec.UpdateReputationAnalysisResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResReputationAnalysis/ReputationAnalysisUpdated.json"), &updateReputationAnalysisResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationAnalysis/ReputationAnalysisUpdated.json"), &updateReputationAnalysisResponse) require.NoError(t, err) getReputationAnalysisResponse := appsec.GetReputationAnalysisResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationAnalysis/ReputationAnalysis.json"), &getReputationAnalysisResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationAnalysis/ReputationAnalysis.json"), &getReputationAnalysisResponse) require.NoError(t, err) removeReputationAnalysisResponse := appsec.RemoveReputationAnalysisResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationAnalysis/ReputationAnalysisDelete.json"), &removeReputationAnalysisResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationAnalysis/ReputationAnalysisDelete.json"), &removeReputationAnalysisResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,13 +57,13 @@ func TestAkamaiReputationAnalysis_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResReputationAnalysis/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationAnalysis/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_profile_analysis.test", "id", "43253:AAAA_81230"), ), }, { - Config: loadFixtureString("testdata/TestResReputationAnalysis/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationAnalysis/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_profile_analysis.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_action_test.go b/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_action_test.go index 606bbfe93..b9cc7abe9 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_action_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_action_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiReputationProfileAction_res_basic(t *testing.T) { client := &appsec.Mock{} updateReputationProfileActionResponse := appsec.UpdateReputationProfileActionResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfileAction/ReputationProfileAction.json"), &updateReputationProfileActionResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfileAction/ReputationProfileAction.json"), &updateReputationProfileActionResponse) require.NoError(t, err) getReputationProfileActionResponse := appsec.GetReputationProfileActionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfileAction/ReputationProfileAction.json"), &getReputationProfileActionResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfileAction/ReputationProfileAction.json"), &getReputationProfileActionResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiReputationProfileAction_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResReputationProfileAction/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationProfileAction/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_profile_action.test", "id", "43253:AAAA_81230:1685099"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_test.go b/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_test.go index e19d0b176..80035258d 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_reputation_profile_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiReputationProfile_res_basic(t *testing.T) { client := &appsec.Mock{} updateReputationProfileResponse := appsec.UpdateReputationProfileResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfile/ReputationProfileUpdated.json"), &updateReputationProfileResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfile/ReputationProfileUpdated.json"), &updateReputationProfileResponse) require.NoError(t, err) getReputationProfileResponse := appsec.GetReputationProfileResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfile/ReputationProfiles.json"), &getReputationProfileResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfile/ReputationProfiles.json"), &getReputationProfileResponse) require.NoError(t, err) createReputationProfileResponse := appsec.CreateReputationProfileResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfile/ReputationProfileCreated.json"), &createReputationProfileResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfile/ReputationProfileCreated.json"), &createReputationProfileResponse) require.NoError(t, err) removeReputationProfileResponse := appsec.RemoveReputationProfileResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProfile/ReputationProfileCreated.json"), &removeReputationProfileResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProfile/ReputationProfileCreated.json"), &removeReputationProfileResponse) require.NoError(t, err) client.On("GetReputationProfile", @@ -56,7 +57,7 @@ func TestAkamaiReputationProfile_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResReputationProfile/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationProfile/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_profile.test", "id", "12345"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_reputation_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_reputation_protection_test.go index 3ba61c87a..49979613a 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_reputation_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_reputation_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiReputationProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateReputationProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetReputationProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateReputationProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetReputationProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResReputationProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResReputationProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -92,14 +93,14 @@ func TestAkamaiReputationProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResReputationProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_reputation_protection.test", "enabled", "false"), ), }, { - Config: loadFixtureString("testdata/TestResReputationProtection/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResReputationProtection/update_by_id.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_reputation_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_reputation_protection.test", "enabled", "true"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_rule_test.go b/pkg/providers/appsec/resource_akamai_appsec_rule_test.go index efecfd865..cfd0b569d 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_rule_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_rule_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiRule_res_basic(t *testing.T) { client := &appsec.Mock{} updateRuleResponse := appsec.UpdateRuleResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResRule/Rule.json"), &updateRuleResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRule/Rule.json"), &updateRuleResponse) require.NoError(t, err) getRuleResponse := appsec.GetRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRule/Rule.json"), &getRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRule/Rule.json"), &getRuleResponse) require.NoError(t, err) deleteRuleResponse := appsec.UpdateRuleResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRule/Rule.json"), &deleteRuleResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRule/Rule.json"), &deleteRuleResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -40,7 +41,7 @@ func TestAkamaiRule_res_basic(t *testing.T) { appsec.GetRuleRequest{ConfigID: 43253, Version: 7, PolicyID: "AAAA_81230", RuleID: 12345}, ).Return(&getRuleResponse, nil) - conditionExceptionJSON := loadFixtureBytes("testdata/TestResRule/ConditionException.json") + conditionExceptionJSON := testutils.LoadFixtureBytes(t, "testdata/TestResRule/ConditionException.json") client.On("UpdateRule", mock.Anything, appsec.UpdateRuleRequest{ConfigID: 43253, Version: 7, PolicyID: "AAAA_81230", Action: "alert", RuleID: 12345, JsonPayloadRaw: conditionExceptionJSON}, @@ -57,7 +58,7 @@ func TestAkamaiRule_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResRule/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRule/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rule.test", "id", "43253:AAAA_81230:12345"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_rule_upgrade_test.go b/pkg/providers/appsec/resource_akamai_appsec_rule_upgrade_test.go index 9e75bc1a2..223b9123e 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_rule_upgrade_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_rule_upgrade_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiRuleUpgrade_res_basic(t *testing.T) { client := &appsec.Mock{} updateRuleUpgradeResponse := appsec.UpdateRuleUpgradeResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResRuleUpgrade/RuleUpgrade.json"), &updateRuleUpgradeResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRuleUpgrade/RuleUpgrade.json"), &updateRuleUpgradeResponse) require.NoError(t, err) getWAFModeResponse := appsec.GetWAFModeResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResRuleUpgrade/WAFMode.json"), &getWAFModeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResRuleUpgrade/WAFMode.json"), &getWAFModeResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiRuleUpgrade_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResRuleUpgrade/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResRuleUpgrade/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_rule_upgrade.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_security_policy_default_protections_test.go b/pkg/providers/appsec/resource_akamai_appsec_security_policy_default_protections_test.go index a46b912ec..768a92789 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_security_policy_default_protections_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_security_policy_default_protections_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,27 +18,27 @@ func TestAkamaiSecurityPolicyDefaultProtections_res_basic(t *testing.T) { client := &appsec.Mock{} getSecurityPolicyResponse := appsec.GetSecurityPolicyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicy.json"), &getSecurityPolicyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicy.json"), &getSecurityPolicyResponse) require.NoError(t, err) getSecurityPolicyAfterUpdateResponse := appsec.GetSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsUpdated.json"), &getSecurityPolicyAfterUpdateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsUpdated.json"), &getSecurityPolicyAfterUpdateResponse) require.NoError(t, err) createSecurityPolicyResponse := appsec.CreateSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsCreate.json"), &createSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsCreate.json"), &createSecurityPolicyResponse) require.NoError(t, err) updateSecurityPolicyResponse := appsec.UpdateSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsUpdated.json"), &updateSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicyDefaultProtectionsUpdated.json"), &updateSecurityPolicyResponse) require.NoError(t, err) removeSecurityPolicyResponse := appsec.RemoveSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicy.json"), &removeSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyDefaultProtections/SecurityPolicy.json"), &removeSecurityPolicyResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -76,13 +77,13 @@ func TestAkamaiSecurityPolicyDefaultProtections_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSecurityPolicyDefaultProtections/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicyDefaultProtections/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy_default_protections.test", "id", "43253:PLEB_114049"), ), }, { - Config: loadFixtureString("testdata/TestResSecurityPolicyDefaultProtections/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicyDefaultProtections/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy_default_protections.test", "security_policy_name", "PLEB Cloned Test for Launchpad 15 New"), ), @@ -101,7 +102,7 @@ func TestAkamaiSecurityPolicyDefaultProtections_res_failure_creating_policy(t *t client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -120,7 +121,7 @@ func TestAkamaiSecurityPolicyDefaultProtections_res_failure_creating_policy(t *t ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSecurityPolicyDefaultProtections/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicyDefaultProtections/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy_default_protections.test", "id", "43253:PLEB_114049"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_security_policy_rename_test.go b/pkg/providers/appsec/resource_akamai_appsec_security_policy_rename_test.go index 2108a3b17..24eddcd90 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_security_policy_rename_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_security_policy_rename_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiSecurityPolicyRename_res_basic(t *testing.T) { client := &appsec.Mock{} updateSecurityPolicyResponse := appsec.UpdateSecurityPolicyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyRename/SecurityPolicyUpdate.json"), &updateSecurityPolicyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyRename/SecurityPolicyUpdate.json"), &updateSecurityPolicyResponse) require.NoError(t, err) getSecurityPolicyResponse := appsec.GetSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicyRename/SecurityPolicy.json"), &getSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicyRename/SecurityPolicy.json"), &getSecurityPolicyResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,13 +48,13 @@ func TestAkamaiSecurityPolicyRename_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSecurityPolicyRename/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicyRename/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy_rename.test", "id", "43253:PLE_114049"), ), }, { - Config: loadFixtureString("testdata/TestResSecurityPolicyRename/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicyRename/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy_rename.test", "id", "43253:PLE_114049"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_security_policy_test.go b/pkg/providers/appsec/resource_akamai_appsec_security_policy_test.go index 1d61af51a..7d6e085b8 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_security_policy_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_security_policy_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiSecurityPolicy_res_basic(t *testing.T) { client := &appsec.Mock{} getSecurityPolicyResponse := appsec.GetSecurityPolicyResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicy/SecurityPolicy.json"), &getSecurityPolicyResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicy/SecurityPolicy.json"), &getSecurityPolicyResponse) require.NoError(t, err) createSecurityPolicyResponse := appsec.CreateSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicy/SecurityPolicyCreate.json"), &createSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicy/SecurityPolicyCreate.json"), &createSecurityPolicyResponse) require.NoError(t, err) removeSecurityPolicyResponse := appsec.RemoveSecurityPolicyResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSecurityPolicy/SecurityPolicy.json"), &removeSecurityPolicyResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSecurityPolicy/SecurityPolicy.json"), &removeSecurityPolicyResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiSecurityPolicy_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSecurityPolicy/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSecurityPolicy/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_security_policy.test", "id", "43253:PLE_114049"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_selected_hostname_test.go b/pkg/providers/appsec/resource_akamai_appsec_selected_hostname_test.go index c77a7c6ef..368366429 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_selected_hostname_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_selected_hostname_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiSelectedHostname_res_basic(t *testing.T) { client := &appsec.Mock{} updateSelectedHostnamesResponse := appsec.UpdateSelectedHostnamesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResSelectedHostname/SelectedHostname.json"), &updateSelectedHostnamesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSelectedHostname/SelectedHostname.json"), &updateSelectedHostnamesResponse) require.NoError(t, err) getSelectedHostnamesResponse := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponse) require.NoError(t, err) getSelectedHostnamesResponseAfterUpdate := appsec.GetSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSelectedHostname/SelectedHostname.json"), &getSelectedHostnamesResponseAfterUpdate) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -59,7 +60,7 @@ func TestAkamaiSelectedHostname_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSelectedHostname/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSelectedHostname/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_selected_hostnames.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_siem_settings_test.go b/pkg/providers/appsec/resource_akamai_appsec_siem_settings_test.go index 3d92e39cd..e9433c5cf 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_siem_settings_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_siem_settings_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,19 +16,19 @@ func TestAkamaiSiemSettings_res_basic(t *testing.T) { client := &appsec.Mock{} updateSiemSettingsResponse := appsec.UpdateSiemSettingsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResSiemSettings/SiemSettings.json"), &updateSiemSettingsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSiemSettings/SiemSettings.json"), &updateSiemSettingsResponse) require.NoError(t, err) getSiemSettingsResponse := appsec.GetSiemSettingsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSiemSettings/SiemSettings.json"), &getSiemSettingsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSiemSettings/SiemSettings.json"), &getSiemSettingsResponse) require.NoError(t, err) removeSiemSettingsResponse := appsec.RemoveSiemSettingsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSiemSettings/SiemSettings.json"), &removeSiemSettingsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSiemSettings/SiemSettings.json"), &removeSiemSettingsResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiSiemSettings_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSiemSettings/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSiemSettings/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_siem_settings.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_slow_post_protection_setting_test.go b/pkg/providers/appsec/resource_akamai_appsec_slow_post_protection_setting_test.go index 7736805db..d1ed74d42 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_slow_post_protection_setting_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_slow_post_protection_setting_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAkamaiSlowPostProtectionSetting_res_basic(t *testing.T) { client := &appsec.Mock{} getConfigurationResponse := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &getConfigurationResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &getConfigurationResponse) require.NoError(t, err) client.On("GetConfiguration", mock.Anything, @@ -23,7 +24,7 @@ func TestAkamaiSlowPostProtectionSetting_res_basic(t *testing.T) { ).Return(&getConfigurationResponse, nil) updateSlowPostProtectionSettingResponse := appsec.UpdateSlowPostProtectionSettingResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtectionSetting/SlowPostProtectionSetting.json"), &updateSlowPostProtectionSettingResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtectionSetting/SlowPostProtectionSetting.json"), &updateSlowPostProtectionSettingResponse) require.NoError(t, err) client.On("UpdateSlowPostProtectionSetting", mock.Anything, @@ -36,7 +37,7 @@ func TestAkamaiSlowPostProtectionSetting_res_basic(t *testing.T) { ).Return(&updateSlowPostProtectionSettingResponse, nil) getSlowPostProtectionSettingsResponse := appsec.GetSlowPostProtectionSettingsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtectionSetting/SlowPostProtectionSetting.json"), &getSlowPostProtectionSettingsResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtectionSetting/SlowPostProtectionSetting.json"), &getSlowPostProtectionSettingsResponse) require.NoError(t, err) client.On("GetSlowPostProtectionSettings", mock.Anything, @@ -44,7 +45,7 @@ func TestAkamaiSlowPostProtectionSetting_res_basic(t *testing.T) { ).Return(&getSlowPostProtectionSettingsResponse, nil).Twice() updateSlowPostProtectionResponse := appsec.UpdateSlowPostProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtectionSetting/SlowPostProtection.json"), &updateSlowPostProtectionResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtectionSetting/SlowPostProtection.json"), &updateSlowPostProtectionResponse) require.NoError(t, err) client.On("UpdateSlowPostProtection", mock.Anything, @@ -57,7 +58,7 @@ func TestAkamaiSlowPostProtectionSetting_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSlowPostProtectionSetting/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSlowPostProtectionSetting/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_slow_post.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_slowpost_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_slowpost_protection_test.go index 2e1d773df..ef222c6ac 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_slowpost_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_slowpost_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiSlowPostProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateSlowPostProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetSlowPostProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateSlowPostProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetSlowPostProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResSlowPostProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResSlowPostProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -71,7 +72,7 @@ func TestAkamaiSlowPostProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResSlowPostProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResSlowPostProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_slowpost_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_slowpost_protection.test", "enabled", "false"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_threat_intel_test.go b/pkg/providers/appsec/resource_akamai_appsec_threat_intel_test.go index c808a5ee2..91fc722de 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_threat_intel_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_threat_intel_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiThreatIntel_res_basic(t *testing.T) { client := &appsec.Mock{} updateThreatIntelResponse := appsec.UpdateThreatIntelResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResThreatIntel/ThreatIntel.json"), &updateThreatIntelResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResThreatIntel/ThreatIntel.json"), &updateThreatIntelResponse) require.NoError(t, err) getThreatIntelResponse := appsec.GetThreatIntelResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResThreatIntel/ThreatIntel.json"), &getThreatIntelResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResThreatIntel/ThreatIntel.json"), &getThreatIntelResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiThreatIntel_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThreatIntel/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThreatIntel/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_threat_intel.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_version_notes_test.go b/pkg/providers/appsec/resource_akamai_appsec_version_notes_test.go index 58e0647b6..fe9edff1d 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_version_notes_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_version_notes_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiVersionNotes_res_basic(t *testing.T) { client := &appsec.Mock{} updateVersionNotesResponse := appsec.UpdateVersionNotesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResVersionNotes/VersionNotes.json"), &updateVersionNotesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResVersionNotes/VersionNotes.json"), &updateVersionNotesResponse) require.NoError(t, err) getVersionNotesResponse := appsec.GetVersionNotesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResVersionNotes/VersionNotes.json"), &getVersionNotesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResVersionNotes/VersionNotes.json"), &getVersionNotesResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiVersionNotes_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResVersionNotes/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResVersionNotes/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_version_notes.test", "id", "43253"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_waf_mode_test.go b/pkg/providers/appsec/resource_akamai_appsec_waf_mode_test.go index 59e508567..57e93ac21 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_waf_mode_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_waf_mode_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAkamaiWAFMode_res_basic(t *testing.T) { client := &appsec.Mock{} updateWAFModeResponse := appsec.UpdateWAFModeResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResWAFMode/WAFMode.json"), &updateWAFModeResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFMode/WAFMode.json"), &updateWAFModeResponse) require.NoError(t, err) getWAFModeResponse := appsec.GetWAFModeResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFMode/WAFMode.json"), &getWAFModeResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFMode/WAFMode.json"), &getWAFModeResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -47,7 +48,7 @@ func TestAkamaiWAFMode_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResWAFMode/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResWAFMode/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_waf_mode.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/appsec/resource_akamai_appsec_waf_protection_test.go b/pkg/providers/appsec/resource_akamai_appsec_waf_protection_test.go index 0852009d9..19139a2c8 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_waf_protection_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_waf_protection_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,23 +16,23 @@ func TestAkamaiWAFProtection_res_basic(t *testing.T) { client := &appsec.Mock{} config := appsec.GetConfigurationResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) updateResponseAllProtectionsFalse := appsec.UpdateWAFProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFProtection/PolicyProtections.json"), &updateResponseAllProtectionsFalse) require.NoError(t, err) getResponseAllProtectionsFalse := appsec.GetWAFProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFProtection/PolicyProtections.json"), &getResponseAllProtectionsFalse) require.NoError(t, err) updateResponseOneProtectionTrue := appsec.UpdateWAFProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFProtection/UpdatedPolicyProtections.json"), &updateResponseOneProtectionTrue) require.NoError(t, err) getResponseOneProtectionTrue := appsec.GetWAFProtectionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAFProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAFProtection/UpdatedPolicyProtections.json"), &getResponseOneProtectionTrue) require.NoError(t, err) // Mock each call to the EdgeGrid library. With the exception of GetConfiguration, each call @@ -71,7 +72,7 @@ func TestAkamaiWAFProtection_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResWAFProtection/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResWAFProtection/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_waf_protection.test", "id", "43253:AAAA_81230"), resource.TestCheckResourceAttr("akamai_appsec_waf_protection.test", "enabled", "false"), diff --git a/pkg/providers/appsec/resource_akamai_appsec_wap_selected_hostnames_test.go b/pkg/providers/appsec/resource_akamai_appsec_wap_selected_hostnames_test.go index eb09b53d3..518883098 100644 --- a/pkg/providers/appsec/resource_akamai_appsec_wap_selected_hostnames_test.go +++ b/pkg/providers/appsec/resource_akamai_appsec_wap_selected_hostnames_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/appsec" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -17,15 +18,15 @@ func TestAkamaiWAPSelectedHostnames_res_basic(t *testing.T) { client := &appsec.Mock{} updateWAPSelectedHostnamesResponse := appsec.UpdateWAPSelectedHostnamesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &updateWAPSelectedHostnamesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &updateWAPSelectedHostnamesResponse) require.NoError(t, err) getWAPSelectedHostnamesResponse := appsec.GetWAPSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -56,7 +57,7 @@ func TestAkamaiWAPSelectedHostnames_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResWAPSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResWAPSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_wap_selected_hostnames.test", "id", "43253:AAAA_81230"), ), @@ -75,15 +76,15 @@ func TestAkamaiWAPSelectedHostnames_res_error_retrieving_hostnames(t *testing.T) client := &appsec.Mock{} updateWAPSelectedHostnamesResponse := appsec.UpdateWAPSelectedHostnamesResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &updateWAPSelectedHostnamesResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &updateWAPSelectedHostnamesResponse) require.NoError(t, err) getWAPSelectedHostnamesResponse := appsec.GetWAPSelectedHostnamesResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResWAPSelectedHostnames/WAPSelectedHostnames.json"), &getWAPSelectedHostnamesResponse) require.NoError(t, err) config := appsec.GetConfigurationResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResConfiguration/LatestConfiguration.json"), &config) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResConfiguration/LatestConfiguration.json"), &config) require.NoError(t, err) client.On("GetConfiguration", @@ -114,7 +115,7 @@ func TestAkamaiWAPSelectedHostnames_res_error_retrieving_hostnames(t *testing.T) ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResWAPSelectedHostnames/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResWAPSelectedHostnames/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_appsec_wap_selected_hostnames.test", "id", "43253:AAAA_81230"), ), diff --git a/pkg/providers/botman/data_akamai_botman_akamai_bot_category_action_test.go b/pkg/providers/botman/data_akamai_botman_akamai_bot_category_action_test.go index 73936daf3..8eaec348f 100644 --- a/pkg/providers/botman/data_akamai_botman_akamai_bot_category_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_akamai_bot_category_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_akamai_bot_category_test.go b/pkg/providers/botman/data_akamai_botman_akamai_bot_category_test.go index 891fc76a6..42bff636c 100644 --- a/pkg/providers/botman/data_akamai_botman_akamai_bot_category_test.go +++ b/pkg/providers/botman/data_akamai_botman_akamai_bot_category_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_akamai_defined_bot_test.go b/pkg/providers/botman/data_akamai_botman_akamai_defined_bot_test.go index fb98c84cf..a6eee13f8 100644 --- a/pkg/providers/botman/data_akamai_botman_akamai_defined_bot_test.go +++ b/pkg/providers/botman/data_akamai_botman_akamai_defined_bot_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_test.go b/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_test.go index e6ed87e47..cdc134e77 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_values_test.go b/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_values_test.go index e0580e95c..91f6b53ba 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_values_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_analytics_cookie_values_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_category_exception_test.go b/pkg/providers/botman/data_akamai_botman_bot_category_exception_test.go index 69691fce0..7f321903a 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_category_exception_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_category_exception_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_detection_action_test.go b/pkg/providers/botman/data_akamai_botman_bot_detection_action_test.go index a68c808ee..245aa485b 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_detection_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_detection_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_detection_test.go b/pkg/providers/botman/data_akamai_botman_bot_detection_test.go index 9c0dc59c9..e9dd6e1d5 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_detection_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_detection_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_endpoint_coverage_report_test.go b/pkg/providers/botman/data_akamai_botman_bot_endpoint_coverage_report_test.go index f4fccb0fd..644f7d5d3 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_endpoint_coverage_report_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_endpoint_coverage_report_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_bot_management_settings_test.go b/pkg/providers/botman/data_akamai_botman_bot_management_settings_test.go index c3f5ef391..36dcbbc04 100644 --- a/pkg/providers/botman/data_akamai_botman_bot_management_settings_test.go +++ b/pkg/providers/botman/data_akamai_botman_bot_management_settings_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_challenge_action_test.go b/pkg/providers/botman/data_akamai_botman_challenge_action_test.go index 7471c933c..db325a52d 100644 --- a/pkg/providers/botman/data_akamai_botman_challenge_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_challenge_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_challenge_injection_rules_test.go b/pkg/providers/botman/data_akamai_botman_challenge_injection_rules_test.go index 59c617839..ea36f67fe 100644 --- a/pkg/providers/botman/data_akamai_botman_challenge_injection_rules_test.go +++ b/pkg/providers/botman/data_akamai_botman_challenge_injection_rules_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_challenge_interception_rules_test.go b/pkg/providers/botman/data_akamai_botman_challenge_interception_rules_test.go index f88d45cb9..c2713ba26 100644 --- a/pkg/providers/botman/data_akamai_botman_challenge_interception_rules_test.go +++ b/pkg/providers/botman/data_akamai_botman_challenge_interception_rules_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_client_side_security_test.go b/pkg/providers/botman/data_akamai_botman_client_side_security_test.go index 2863f8408..415eb1a1c 100644 --- a/pkg/providers/botman/data_akamai_botman_client_side_security_test.go +++ b/pkg/providers/botman/data_akamai_botman_client_side_security_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_conditional_action_test.go b/pkg/providers/botman/data_akamai_botman_conditional_action_test.go index de5680433..bd5733acf 100644 --- a/pkg/providers/botman/data_akamai_botman_conditional_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_conditional_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_bot_category_action_test.go b/pkg/providers/botman/data_akamai_botman_custom_bot_category_action_test.go index 03f8af80d..343b3ee45 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_bot_category_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_bot_category_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_bot_category_sequence_test.go b/pkg/providers/botman/data_akamai_botman_custom_bot_category_sequence_test.go index bd4c0e291..fb656bd9c 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_bot_category_sequence_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_bot_category_sequence_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_bot_category_test.go b/pkg/providers/botman/data_akamai_botman_custom_bot_category_test.go index 0130dfbe5..1b0b408e2 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_bot_category_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_bot_category_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_client_sequence.go b/pkg/providers/botman/data_akamai_botman_custom_client_sequence.go new file mode 100644 index 000000000..2a4231025 --- /dev/null +++ b/pkg/providers/botman/data_akamai_botman_custom_client_sequence.go @@ -0,0 +1,64 @@ +package botman + +import ( + "context" + "strconv" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceCustomClientSequence() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceCustomClientSequenceRead, + Schema: map[string]*schema.Schema{ + "config_id": { + Type: schema.TypeInt, + Required: true, + }, + "custom_client_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func dataSourceCustomClientSequenceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("botman", "dataSourceCustomClientSequenceRead") + logger.Debugf("in dataSourceCustomClientSequenceRead") + + configID, err := tf.GetIntValue("config_id", d) + if err != nil { + return diag.FromErr(err) + } + + version, err := getLatestConfigVersion(ctx, configID, m) + if err != nil { + return diag.FromErr(err) + } + + request := botman.GetCustomClientSequenceRequest{ + ConfigID: int64(configID), + Version: int64(version), + } + + response, err := client.GetCustomClientSequence(ctx, request) + if err != nil { + logger.Errorf("calling 'GetCustomClientSequence': %s", err.Error()) + return diag.FromErr(err) + } + + if err := d.Set("custom_client_ids", response.Sequence); err != nil { + return diag.Errorf("%s: %s", tf.ErrValueSet, err.Error()) + } + + d.SetId(strconv.Itoa(configID)) + return nil +} diff --git a/pkg/providers/botman/data_akamai_botman_custom_client_sequence_test.go b/pkg/providers/botman/data_akamai_botman_custom_client_sequence_test.go new file mode 100644 index 000000000..94fc0966f --- /dev/null +++ b/pkg/providers/botman/data_akamai_botman_custom_client_sequence_test.go @@ -0,0 +1,44 @@ +package botman + +import ( + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" + "github.com/akamai/terraform-provider-akamai/v5/pkg/test" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestDataCustomClientSequence(t *testing.T) { + t.Run("DataCustomClientSequence", func(t *testing.T) { + + mockedBotmanClient := &botman.Mock{} + response := botman.CustomClientSequenceResponse{ + Sequence: []string{"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "d79285df-e399-43e8-bb0f-c0d980a88e4f", "afa309b8-4fd5-430e-a061-1c61df1d2ac2"}, + } + mockedBotmanClient.On("GetCustomClientSequence", + mock.Anything, + botman.GetCustomClientSequenceRequest{ConfigID: 43253, Version: 15}, + ).Return(&response, nil) + + useClient(mockedBotmanClient, func() { + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: test.Fixture("testdata/TestDataCustomClientSequence/basic.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.akamai_botman_custom_client_sequence.test", "custom_client_ids.#", "3"), + resource.TestCheckResourceAttr("data.akamai_botman_custom_client_sequence.test", "custom_client_ids.0", "cc9c3f89-e179-4892-89cf-d5e623ba9dc7"), + resource.TestCheckResourceAttr("data.akamai_botman_custom_client_sequence.test", "custom_client_ids.1", "d79285df-e399-43e8-bb0f-c0d980a88e4f"), + resource.TestCheckResourceAttr("data.akamai_botman_custom_client_sequence.test", "custom_client_ids.2", "afa309b8-4fd5-430e-a061-1c61df1d2ac2")), + }, + }, + }) + }) + + mockedBotmanClient.AssertExpectations(t) + }) +} diff --git a/pkg/providers/botman/data_akamai_botman_custom_client_test.go b/pkg/providers/botman/data_akamai_botman_custom_client_test.go index 8fe9d78a9..3a092e9c5 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_client_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_client_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_defined_bot_test.go b/pkg/providers/botman/data_akamai_botman_custom_defined_bot_test.go index be7496858..dd088e115 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_defined_bot_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_defined_bot_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_custom_deny_action_test.go b/pkg/providers/botman/data_akamai_botman_custom_deny_action_test.go index 27db98668..ca2d5476c 100644 --- a/pkg/providers/botman/data_akamai_botman_custom_deny_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_custom_deny_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_javascript_injection_test.go b/pkg/providers/botman/data_akamai_botman_javascript_injection_test.go index d54386e3c..9b023ce25 100644 --- a/pkg/providers/botman/data_akamai_botman_javascript_injection_test.go +++ b/pkg/providers/botman/data_akamai_botman_javascript_injection_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_recategorized_akamai_defined_bot_test.go b/pkg/providers/botman/data_akamai_botman_recategorized_akamai_defined_bot_test.go index 870fac180..dc9958ddd 100644 --- a/pkg/providers/botman/data_akamai_botman_recategorized_akamai_defined_bot_test.go +++ b/pkg/providers/botman/data_akamai_botman_recategorized_akamai_defined_bot_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_response_action_test.go b/pkg/providers/botman/data_akamai_botman_response_action_test.go index c3377b00f..2bef29f50 100644 --- a/pkg/providers/botman/data_akamai_botman_response_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_response_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_serve_alternate_action_test.go b/pkg/providers/botman/data_akamai_botman_serve_alternate_action_test.go index f27e530af..3e1ae617f 100644 --- a/pkg/providers/botman/data_akamai_botman_serve_alternate_action_test.go +++ b/pkg/providers/botman/data_akamai_botman_serve_alternate_action_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_transactional_endpoint_protection_test.go b/pkg/providers/botman/data_akamai_botman_transactional_endpoint_protection_test.go index ef9a0bddb..d1a0e10f4 100644 --- a/pkg/providers/botman/data_akamai_botman_transactional_endpoint_protection_test.go +++ b/pkg/providers/botman/data_akamai_botman_transactional_endpoint_protection_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/data_akamai_botman_transactional_endpoint_test.go b/pkg/providers/botman/data_akamai_botman_transactional_endpoint_test.go index f3999957c..67fba03fe 100644 --- a/pkg/providers/botman/data_akamai_botman_transactional_endpoint_test.go +++ b/pkg/providers/botman/data_akamai_botman_transactional_endpoint_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/provider.go b/pkg/providers/botman/provider.go index 0e09cf172..1facd1556 100644 --- a/pkg/providers/botman/provider.go +++ b/pkg/providers/botman/provider.go @@ -75,6 +75,7 @@ func (p *Subprovider) Resources() map[string]*schema.Resource { "akamai_botman_custom_bot_category_action": resourceCustomBotCategoryAction(), "akamai_botman_custom_bot_category_sequence": resourceCustomBotCategorySequence(), "akamai_botman_custom_client": resourceCustomClient(), + "akamai_botman_custom_client_sequence": resourceCustomClientSequence(), "akamai_botman_custom_defined_bot": resourceCustomDefinedBot(), "akamai_botman_custom_deny_action": resourceCustomDenyAction(), "akamai_botman_javascript_injection": resourceJavascriptInjection(), @@ -107,6 +108,7 @@ func (p *Subprovider) DataSources() map[string]*schema.Resource { "akamai_botman_custom_bot_category_action": dataSourceCustomBotCategoryAction(), "akamai_botman_custom_bot_category_sequence": dataSourceCustomBotCategorySequence(), "akamai_botman_custom_client": dataSourceCustomClient(), + "akamai_botman_custom_client_sequence": dataSourceCustomClientSequence(), "akamai_botman_custom_defined_bot": dataSourceCustomDefinedBot(), "akamai_botman_custom_deny_action": dataSourceCustomDenyAction(), "akamai_botman_javascript_injection": dataSourceJavascriptInjection(), diff --git a/pkg/providers/botman/resource_akamai_botman_akamai_bot_category_action_test.go b/pkg/providers/botman/resource_akamai_botman_akamai_bot_category_action_test.go index 7bdf129cd..4e650394e 100644 --- a/pkg/providers/botman/resource_akamai_botman_akamai_bot_category_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_akamai_bot_category_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_bot_analytics_cookie_test.go b/pkg/providers/botman/resource_akamai_botman_bot_analytics_cookie_test.go index 5e582c346..21f405355 100644 --- a/pkg/providers/botman/resource_akamai_botman_bot_analytics_cookie_test.go +++ b/pkg/providers/botman/resource_akamai_botman_bot_analytics_cookie_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_bot_category_exception_test.go b/pkg/providers/botman/resource_akamai_botman_bot_category_exception_test.go index 5264f9f96..bdd701917 100644 --- a/pkg/providers/botman/resource_akamai_botman_bot_category_exception_test.go +++ b/pkg/providers/botman/resource_akamai_botman_bot_category_exception_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_bot_detection_action_test.go b/pkg/providers/botman/resource_akamai_botman_bot_detection_action_test.go index 278a311bd..51b438792 100644 --- a/pkg/providers/botman/resource_akamai_botman_bot_detection_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_bot_detection_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_bot_management_settings_test.go b/pkg/providers/botman/resource_akamai_botman_bot_management_settings_test.go index dc801caad..8d39b1700 100644 --- a/pkg/providers/botman/resource_akamai_botman_bot_management_settings_test.go +++ b/pkg/providers/botman/resource_akamai_botman_bot_management_settings_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_challenge_action_test.go b/pkg/providers/botman/resource_akamai_botman_challenge_action_test.go index e96cb3d89..e28b284a2 100644 --- a/pkg/providers/botman/resource_akamai_botman_challenge_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_challenge_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_challenge_injection_rules_test.go b/pkg/providers/botman/resource_akamai_botman_challenge_injection_rules_test.go index e3383211f..8921d5124 100644 --- a/pkg/providers/botman/resource_akamai_botman_challenge_injection_rules_test.go +++ b/pkg/providers/botman/resource_akamai_botman_challenge_injection_rules_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_challenge_interception_rules_test.go b/pkg/providers/botman/resource_akamai_botman_challenge_interception_rules_test.go index 146c5ed6a..025d32af8 100644 --- a/pkg/providers/botman/resource_akamai_botman_challenge_interception_rules_test.go +++ b/pkg/providers/botman/resource_akamai_botman_challenge_interception_rules_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_client_side_security_test.go b/pkg/providers/botman/resource_akamai_botman_client_side_security_test.go index cee9093e3..bc021cdfc 100644 --- a/pkg/providers/botman/resource_akamai_botman_client_side_security_test.go +++ b/pkg/providers/botman/resource_akamai_botman_client_side_security_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_conditional_action_test.go b/pkg/providers/botman/resource_akamai_botman_conditional_action_test.go index 2c34754ed..28b8a857d 100644 --- a/pkg/providers/botman/resource_akamai_botman_conditional_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_conditional_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_action_test.go b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_action_test.go index f603d59bf..8b8e1aba8 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_sequence_test.go b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_sequence_test.go index 965f3a32f..91d52771b 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_sequence_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_sequence_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_test.go b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_test.go index 2092775d2..b206bc62e 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_bot_category_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_bot_category_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_client_sequence.go b/pkg/providers/botman/resource_akamai_botman_custom_client_sequence.go new file mode 100644 index 000000000..2e856a7ca --- /dev/null +++ b/pkg/providers/botman/resource_akamai_botman_custom_client_sequence.go @@ -0,0 +1,141 @@ +package botman + +import ( + "context" + "strconv" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func resourceCustomClientSequence() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceCustomClientSequenceCreate, + ReadContext: resourceCustomClientSequenceRead, + UpdateContext: resourceCustomClientSequenceUpdate, + DeleteContext: resourceCustomClientSequenceDelete, + CustomizeDiff: customdiff.All( + verifyConfigIDUnchanged, + ), + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + Schema: map[string]*schema.Schema{ + "config_id": { + Type: schema.TypeInt, + Required: true, + }, + "custom_client_ids": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func resourceCustomClientSequenceCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + configID, diagnostics := resourceCustomClientSequenceUpsert(ctx, d, m, "resourceCustomClientSequenceCreate") + if diagnostics != nil { + return diagnostics + } + d.SetId(strconv.Itoa(configID)) + return resourceCustomClientSequenceRead(ctx, d, m) +} + +func resourceCustomClientSequenceUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + _, diagnostics := resourceCustomClientSequenceUpsert(ctx, d, m, "resourceCustomClientSequenceUpdate") + if diagnostics != nil { + return diagnostics + } + return resourceCustomClientSequenceRead(ctx, d, m) +} + +func resourceCustomClientSequenceUpsert(ctx context.Context, d *schema.ResourceData, m interface{}, operation string) (int, diag.Diagnostics) { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("botman", operation) + logger.Debugf("in %s", operation) + + configID, err := tf.GetIntValue("config_id", d) + if err != nil { + return configID, diag.FromErr(err) + } + + version, err := getModifiableConfigVersion(ctx, configID, "customClientSequence", m) + if err != nil { + return configID, diag.FromErr(err) + } + sequence, err := tf.GetListValue("custom_client_ids", d) + if err != nil { + return configID, diag.FromErr(err) + } + var stringSequence []string + for _, val := range sequence { + stringSequence = append(stringSequence, val.(string)) + } + + request := botman.UpdateCustomClientSequenceRequest{ + ConfigID: int64(configID), + Version: int64(version), + Sequence: stringSequence, + } + + _, err = client.UpdateCustomClientSequence(ctx, request) + if err != nil { + logger.Errorf("calling 'UpdateCustomClientSequence': %s", err.Error()) + return configID, diag.FromErr(err) + } + + return configID, nil +} + +func resourceCustomClientSequenceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("botman", "resourceCustomClientSequenceRead") + logger.Debugf("in resourceCustomClientSequenceRead") + + configID, err := strconv.Atoi(d.Id()) + if err != nil { + return diag.FromErr(err) + } + + version, err := getLatestConfigVersion(ctx, configID, m) + if err != nil { + return diag.FromErr(err) + } + + request := botman.GetCustomClientSequenceRequest{ + ConfigID: int64(configID), + Version: int64(version), + } + + response, err := client.GetCustomClientSequence(ctx, request) + if err != nil { + logger.Errorf("calling 'GetCustomClientSequence': %s", err.Error()) + return diag.FromErr(err) + } + + fields := map[string]interface{}{ + "config_id": configID, + "custom_client_ids": response.Sequence, + } + if err := tf.SetAttrs(d, fields); err != nil { + return diag.Errorf("%s: %s", tf.ErrValueSet, err.Error()) + } + return nil +} + +func resourceCustomClientSequenceDelete(_ context.Context, _ *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + logger := meta.Log("botman", "resourceCustomClientSequenceDelete") + logger.Debugf("in resourceCustomClientSequenceDelete") + logger.Info("Botman API does not support custom client sequence deletion - resource will only be removed from state") + + return nil +} diff --git a/pkg/providers/botman/resource_akamai_botman_custom_client_sequence_test.go b/pkg/providers/botman/resource_akamai_botman_custom_client_sequence_test.go new file mode 100644 index 000000000..e9d9b9c1e --- /dev/null +++ b/pkg/providers/botman/resource_akamai_botman_custom_client_sequence_test.go @@ -0,0 +1,85 @@ +package botman + +import ( + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" + "github.com/akamai/terraform-provider-akamai/v5/pkg/test" + "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestResourceCustomClientSequence(t *testing.T) { + t.Run("ResourceCustomClientSequence", func(t *testing.T) { + + mockedBotmanClient := &botman.Mock{} + createCustomClientIds := []string{"cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "d79285df-e399-43e8-bb0f-c0d980a88e4f", "afa309b8-4fd5-430e-a061-1c61df1d2ac2"} + createResponse := botman.CustomClientSequenceResponse{Sequence: createCustomClientIds} + mockedBotmanClient.On("UpdateCustomClientSequence", + mock.Anything, + botman.UpdateCustomClientSequenceRequest{ + ConfigID: 43253, + Version: 15, + Sequence: createCustomClientIds, + }, + ).Return(&createResponse, nil).Once() + + mockedBotmanClient.On("GetCustomClientSequence", + mock.Anything, + botman.GetCustomClientSequenceRequest{ + ConfigID: 43253, + Version: 15, + }, + ).Return(&createResponse, nil).Times(3) + + updateCustomClientIds := []string{createCustomClientIds[1], createCustomClientIds[2], createCustomClientIds[0]} + updateResponse := botman.CustomClientSequenceResponse{Sequence: updateCustomClientIds} + mockedBotmanClient.On("UpdateCustomClientSequence", + mock.Anything, + botman.UpdateCustomClientSequenceRequest{ + ConfigID: 43253, + Version: 15, + Sequence: updateCustomClientIds, + }, + ).Return(&updateResponse, nil).Once() + + mockedBotmanClient.On("GetCustomClientSequence", + mock.Anything, + botman.GetCustomClientSequenceRequest{ + ConfigID: 43253, + Version: 15, + }, + ).Return(&updateResponse, nil).Times(2) + + useClient(mockedBotmanClient, func() { + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: test.Fixture("testdata/TestResourceCustomClientSequence/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "id", "43253"), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.#", tools.ConvertToString(len(createCustomClientIds))), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.0", createCustomClientIds[0]), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.1", createCustomClientIds[1]), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.2", createCustomClientIds[2])), + }, + { + Config: test.Fixture("testdata/TestResourceCustomClientSequence/update.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "id", "43253"), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.#", tools.ConvertToString(len(updateCustomClientIds))), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.0", updateCustomClientIds[0]), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.1", updateCustomClientIds[1]), + resource.TestCheckResourceAttr("akamai_botman_custom_client_sequence.test", "custom_client_ids.2", updateCustomClientIds[2])), + }, + }, + }) + }) + + mockedBotmanClient.AssertExpectations(t) + }) +} diff --git a/pkg/providers/botman/resource_akamai_botman_custom_client_test.go b/pkg/providers/botman/resource_akamai_botman_custom_client_test.go index 8bb09d8f6..66af90b27 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_client_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_client_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_defined_bot_test.go b/pkg/providers/botman/resource_akamai_botman_custom_defined_bot_test.go index 926a28cb8..3a148020a 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_defined_bot_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_defined_bot_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_custom_deny_action_test.go b/pkg/providers/botman/resource_akamai_botman_custom_deny_action_test.go index 8f0154955..e7c9aa98f 100644 --- a/pkg/providers/botman/resource_akamai_botman_custom_deny_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_custom_deny_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_javascript_injection_test.go b/pkg/providers/botman/resource_akamai_botman_javascript_injection_test.go index b2b4c588f..72c750a85 100644 --- a/pkg/providers/botman/resource_akamai_botman_javascript_injection_test.go +++ b/pkg/providers/botman/resource_akamai_botman_javascript_injection_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_recategorized_akamai_defined_bot_test.go b/pkg/providers/botman/resource_akamai_botman_recategorized_akamai_defined_bot_test.go index fdca79f1c..238e9abf6 100644 --- a/pkg/providers/botman/resource_akamai_botman_recategorized_akamai_defined_bot_test.go +++ b/pkg/providers/botman/resource_akamai_botman_recategorized_akamai_defined_bot_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_serve_alternate_action_test.go b/pkg/providers/botman/resource_akamai_botman_serve_alternate_action_test.go index fb944c3ee..5010bcd70 100644 --- a/pkg/providers/botman/resource_akamai_botman_serve_alternate_action_test.go +++ b/pkg/providers/botman/resource_akamai_botman_serve_alternate_action_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_protection_test.go b/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_protection_test.go index 6204b85b0..789bb0344 100644 --- a/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_protection_test.go +++ b/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_protection_test.go @@ -5,7 +5,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_test.go b/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_test.go index 082831815..6e168b0de 100644 --- a/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_test.go +++ b/pkg/providers/botman/resource_akamai_botman_transactional_endpoint_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/botman" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/botman/testdata/TestDataCustomClientSequence/basic.tf b/pkg/providers/botman/testdata/TestDataCustomClientSequence/basic.tf new file mode 100644 index 000000000..6fc823593 --- /dev/null +++ b/pkg/providers/botman/testdata/TestDataCustomClientSequence/basic.tf @@ -0,0 +1,8 @@ +provider "akamai" { + edgerc = "../../test/edgerc" + cache_enabled = false +} + +data "akamai_botman_custom_client_sequence" "test" { + config_id = 43253 +} \ No newline at end of file diff --git a/pkg/providers/botman/testdata/TestResourceCustomClientSequence/create.tf b/pkg/providers/botman/testdata/TestResourceCustomClientSequence/create.tf new file mode 100644 index 000000000..40d1b4a60 --- /dev/null +++ b/pkg/providers/botman/testdata/TestResourceCustomClientSequence/create.tf @@ -0,0 +1,9 @@ +provider "akamai" { + edgerc = "../../test/edgerc" + cache_enabled = false +} + +resource "akamai_botman_custom_client_sequence" "test" { + config_id = 43253 + custom_client_ids = ["cc9c3f89-e179-4892-89cf-d5e623ba9dc7", "d79285df-e399-43e8-bb0f-c0d980a88e4f", "afa309b8-4fd5-430e-a061-1c61df1d2ac2"] +} \ No newline at end of file diff --git a/pkg/providers/botman/testdata/TestResourceCustomClientSequence/update.tf b/pkg/providers/botman/testdata/TestResourceCustomClientSequence/update.tf new file mode 100644 index 000000000..4e9d4d321 --- /dev/null +++ b/pkg/providers/botman/testdata/TestResourceCustomClientSequence/update.tf @@ -0,0 +1,9 @@ +provider "akamai" { + edgerc = "../../test/edgerc" + cache_enabled = false +} + +resource "akamai_botman_custom_client_sequence" "test" { + config_id = 43253 + custom_client_ids = ["d79285df-e399-43e8-bb0f-c0d980a88e4f", "afa309b8-4fd5-430e-a061-1c61df1d2ac2", "cc9c3f89-e179-4892-89cf-d5e623ba9dc7"] +} \ No newline at end of file diff --git a/pkg/providers/clientlists/clientlists.go b/pkg/providers/clientlists/clientlists.go new file mode 100644 index 000000000..6bf74b7e3 --- /dev/null +++ b/pkg/providers/clientlists/clientlists.go @@ -0,0 +1,7 @@ +package clientlists + +import "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/registry" + +func init() { + registry.RegisterPluginSubprovider(NewSubprovider()) +} diff --git a/pkg/providers/clientlists/data_akamai_clientlist_lists.go b/pkg/providers/clientlists/data_akamai_clientlist_lists.go new file mode 100644 index 000000000..ba5615f3d --- /dev/null +++ b/pkg/providers/clientlists/data_akamai_clientlist_lists.go @@ -0,0 +1,255 @@ +package clientlists + +import ( + "context" + "encoding/json" + "errors" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func dataSourceClientLists() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceClientListRead, + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Optional: true, + }, + "type": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(getValidListTypes(), false)), + }, + }, + "list_ids": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + Description: "A set of client list ids.", + }, + "lists": { + Type: schema.TypeList, + Computed: true, + Description: "A set of client lists.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Optional: true, + Description: "The name of the client list", + }, + "type": { + Type: schema.TypeString, + Optional: true, + Description: "The type of the client list", + }, + "notes": { + Type: schema.TypeString, + Computed: true, + Description: "The client list notes", + }, + "tags": { + Type: schema.TypeList, + Computed: true, + Description: "The client list tags", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "list_id": { + Type: schema.TypeString, + Computed: true, + Description: "The ID of the client list.", + }, + "version": { + Type: schema.TypeInt, + Computed: true, + Description: "The current version of the client list.", + }, + "items_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of items that a client list contains.", + }, + "create_date": { + Type: schema.TypeString, + Computed: true, + Description: "The client list creation date.", + }, + "created_by": { + Type: schema.TypeString, + Computed: true, + Description: "The username of the user who created the client list.", + }, + "update_date": { + Type: schema.TypeString, + Computed: true, + Description: "The date of last update.", + }, + "updated_by": { + Type: schema.TypeString, + Computed: true, + Description: "The username of the user that updated the client list last.", + }, + "production_activation_status": { + Type: schema.TypeString, + Computed: true, + Description: "The activation status in production environment.", + }, + "staging_activation_status": { + Type: schema.TypeString, + Computed: true, + Description: "The activation status in staging environment.", + }, + "list_type": { + Type: schema.TypeString, + Computed: true, + Description: "The client list type.", + }, + "shared": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the client list is shared.", + }, + "read_only": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the client is editable for the authenticated user.", + }, + "deprecated": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the client list was removed.", + }, + }, + }, + }, + "json": { + Type: schema.TypeString, + Computed: true, + Description: "JSON representation of the client lists.", + }, + "output_text": { + Type: schema.TypeString, + Computed: true, + Description: "Tabular representation of the client lists.", + }, + }, + } +} + +func dataSourceClientListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "dataSourceClientListRead") + + name, err := tf.GetStringValue("name", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return diag.FromErr(err) + } + + listTypesSet, err := tf.GetSetValue("type", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return diag.FromErr(err) + } + listTypesList := tf.SetToStringSlice(listTypesSet) + listTypes := make([]clientlists.ClientListType, 0, listTypesSet.Len()) + for _, v := range listTypesList { + listTypes = append(listTypes, clientlists.ClientListType(v)) + } + + lists, err := client.GetClientLists(ctx, clientlists.GetClientListsRequest{ + Name: name, + Type: listTypes, + }) + if err != nil { + logger.Errorf("calling 'GetClientLists': %s", err.Error()) + return diag.FromErr(err) + } + + mappedLists := mapClientListsToSchema(lists) + if err := d.Set("lists", mappedLists); err != nil { + return diag.Errorf("%v: %s", tf.ErrValueSet, err.Error()) + } + + jsonBody, err := json.MarshalIndent(lists.Content, "", " ") + if err != nil { + return diag.FromErr(err) + } + if err := d.Set("json", string(jsonBody)); err != nil { + return diag.Errorf("%v: %s", tf.ErrValueSet, err.Error()) + } + + IDs := make([]string, 0, len(lists.Content)) + for _, cl := range lists.Content { + IDs = append(IDs, cl.ListID) + } + if err := d.Set("list_ids", IDs); err != nil { + logger.Errorf("error setting 'list_ids': %s", err.Error()) + return diag.Errorf("%v: %s", tf.ErrValueSet, err.Error()) + } + + ots := OutputTemplates{} + InitTemplates(ots) + + outputText, err := RenderTemplates(ots, "clientListsDS", lists) + if err != nil { + return diag.FromErr(err) + } + if err := d.Set("output_text", outputText); err != nil { + return diag.Errorf("%v: %s", tf.ErrValueSet, err.Error()) + } + + d.SetId(tools.GetSHAString(string(jsonBody))) + + return nil +} + +func mapClientListsToSchema(lists *clientlists.GetClientListsResponse) []interface{} { + if lists != nil && len(lists.Content) > 0 { + result := make([]interface{}, 0, len(lists.Content)) + + for _, list := range lists.Content { + result = append(result, map[string]interface{}{ + "name": list.Name, + "type": list.Type, + "notes": list.Notes, + "tags": list.Tags, + "list_id": list.ListID, + "version": list.Version, + "items_count": list.ItemsCount, + "create_date": list.CreateDate, + "created_by": list.CreatedBy, + "update_date": list.UpdateDate, + "updated_by": list.UpdatedBy, + "production_activation_status": list.ProductionActivationStatus, + "staging_activation_status": list.StagingActivationStatus, + "list_type": list.ListType, + "shared": list.Shared, + "read_only": list.ReadOnly, + "deprecated": list.Deprecated, + }) + } + + return result + } + + return make([]interface{}, 0) +} + +func getValidListTypes() []string { + return []string{ + string(clientlists.IP), + string(clientlists.GEO), + string(clientlists.ASN), + string(clientlists.TLSFingerprint), + string(clientlists.FileHash), + } +} diff --git a/pkg/providers/clientlists/data_akamai_clientlist_lists_test.go b/pkg/providers/clientlists/data_akamai_clientlist_lists_test.go new file mode 100644 index 000000000..6ea1778b8 --- /dev/null +++ b/pkg/providers/clientlists/data_akamai_clientlist_lists_test.go @@ -0,0 +1,109 @@ +package clientlists + +import ( + "bytes" + "encoding/json" + "fmt" + "strconv" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestClientList_data_all_lists(t *testing.T) { + dataSourceName := "data.akamai_clientlist_lists.lists" + tests := map[string]struct { + params clientlists.GetClientListsRequest + config string + responseBody []byte + }{ + "All lists": { + params: clientlists.GetClientListsRequest{ + Type: []clientlists.ClientListType{}, + }, + config: loadFixtureString("testData/TestDSClientList/match_all.tf"), + responseBody: loadFixtureBytes("testData/TestDSClientList/ClientLists.json"), + }, + "Filtered lists": { + params: clientlists.GetClientListsRequest{ + Name: "test", + Type: []clientlists.ClientListType{clientlists.IP, clientlists.GEO}, + }, + config: loadFixtureString("testData/TestDSClientList/match_by_filters.tf"), + responseBody: loadFixtureBytes("testData/TestDSClientList/ClientLists.json"), + }, + "Empty content list": { + params: clientlists.GetClientListsRequest{ + Type: []clientlists.ClientListType{}, + }, + config: loadFixtureString("testData/TestDSClientList/match_all.tf"), + responseBody: []byte(`{ + "content": [] + }`), + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + client := &clientlists.Mock{} + clientListsResponse := clientlists.GetClientListsResponse{} + err := json.Unmarshal(test.responseBody, &clientListsResponse) + require.NoError(t, err) + + r, err := json.Marshal(clientListsResponse.Content) + require.NoError(t, err) + + buf := &bytes.Buffer{} + err = json.Indent(buf, r, "", " ") + require.NoError(t, err) + + clientListsResponseJSONString := buf.String() + + client.On("GetClientLists", + mock.Anything, + test.params, + ).Return(&clientListsResponse, nil) + + useClient(client, func() { + checks := []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(dataSourceName, "json", clientListsResponseJSONString), + resource.TestCheckResourceAttr(dataSourceName, "list_ids.#", strconv.Itoa(len(clientListsResponse.Content))), + resource.TestCheckResourceAttr(dataSourceName, "lists.#", strconv.Itoa(len(clientListsResponse.Content))), + } + for k, v := range clientListsResponse.Content { + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("list_ids.%d", k), v.ListID)) + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("lists.%d.list_id", k), v.ListID)) + } + + if test.params.Name != "" { + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, "name", test.params.Name)) + } else { + checks = append(checks, resource.TestCheckNoResourceAttr(dataSourceName, "name")) + } + if len(test.params.Type) > 0 { + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, "type.#", strconv.Itoa(len(test.params.Type)))) + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, "type.0", string(test.params.Type[1]))) + checks = append(checks, resource.TestCheckResourceAttr(dataSourceName, "type.1", string(test.params.Type[0]))) + } else { + checks = append(checks, resource.TestCheckNoResourceAttr(dataSourceName, "type")) + } + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: test.config, + Check: resource.ComposeAggregateTestCheckFunc(checks...), + }, + }, + }) + }) + + client.AssertExpectations(t) + }) + } +} diff --git a/pkg/providers/clientlists/provider.go b/pkg/providers/clientlists/provider.go new file mode 100644 index 000000000..1eb341320 --- /dev/null +++ b/pkg/providers/clientlists/provider.go @@ -0,0 +1,69 @@ +// Package clientlists contains implementation for Akamai Terraform sub-provider responsible for creation, deployment, and management of client lists +package clientlists + +import ( + "sync" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +type ( + // Subprovider gathers clientlists resources and data sources + Subprovider struct { + client clientlists.ClientLists + } + // Option is a clientlists provider option + Option func(p *Subprovider) +) + +var ( + once sync.Once + + inst *Subprovider +) + +// NewSubprovider returns a core sub provider +func NewSubprovider(opts ...Option) *Subprovider { + once.Do(func() { + inst = &Subprovider{} + + for _, opt := range opts { + opt(inst) + } + }) + + return inst +} + +// WithClient sets the client interface function, used for mocking and testing +func WithClient(c clientlists.ClientLists) Option { + return func(p *Subprovider) { + p.client = c + } +} + +// Client returns the CLIENTLISTS interface +func (p *Subprovider) Client(meta meta.Meta) clientlists.ClientLists { + if p.client != nil { + return p.client + } + return clientlists.Client(meta.Session()) +} + +// Resources returns terraform resources for clientlists +func (p *Subprovider) Resources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "akamai_clientlist_activation": resourceClientListActivation(), + "akamai_clientlist_list": resourceClientList(), + } +} + +// DataSources returns terraform data sources for clientlists +func (p *Subprovider) DataSources() map[string]*schema.Resource { + return map[string]*schema.Resource{ + "akamai_clientlist_lists": dataSourceClientLists(), + } +} diff --git a/pkg/providers/clientlists/provider_test.go b/pkg/providers/clientlists/provider_test.go new file mode 100644 index 000000000..c6ff1f012 --- /dev/null +++ b/pkg/providers/clientlists/provider_test.go @@ -0,0 +1,66 @@ +package clientlists + +import ( + "io/ioutil" + "log" + "os" + "sync" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/akamai/terraform-provider-akamai/v5/pkg/akamai" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +var testAccProviders map[string]func() (*schema.Provider, error) + +var testAccProvider *schema.Provider + +func TestMain(m *testing.M) { + testAccProvider = akamai.NewPluginProvider(NewSubprovider())() + testAccProviders = map[string]func() (*schema.Provider, error){ + "akamai": func() (*schema.Provider, error) { + return testAccProvider, nil + }, + } + if err := testutils.TFTestSetup(); err != nil { + log.Fatal(err) + } + exitCode := m.Run() + if err := testutils.TFTestTeardown(); err != nil { + log.Fatal(err) + } + os.Exit(exitCode) +} + +// Only allow one test at a time to patch the client via useClient() +var clientLock sync.Mutex + +// useClient swaps out the client on the global instance for the duration of the given func +func useClient(client clientlists.ClientLists, f func()) { + clientLock.Lock() + orig := inst.client + inst.client = client + + defer func() { + inst.client = orig + clientLock.Unlock() + }() + + f() +} + +// loadFixtureBytes returns the entire contents of the given file as a byte slice +func loadFixtureBytes(path string) []byte { + contents, err := ioutil.ReadFile(path) + if err != nil { + panic(err) + } + return contents +} + +// loadFixtureString returns the entire contents of the given file as a string +func loadFixtureString(path string) string { + return string(loadFixtureBytes(path)) +} diff --git a/pkg/providers/clientlists/resource_akamai_clientlists_list.go b/pkg/providers/clientlists/resource_akamai_clientlists_list.go new file mode 100644 index 000000000..1c9d268fb --- /dev/null +++ b/pkg/providers/clientlists/resource_akamai_clientlists_list.go @@ -0,0 +1,518 @@ +package clientlists + +import ( + "context" + "errors" + "fmt" + "net/http" + "reflect" + "sort" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceClientList() *schema.Resource { + return &schema.Resource{ + ReadContext: resourceClientListRead, + CreateContext: resourceClientListCreate, + UpdateContext: resourceClientListUpdate, + DeleteContext: resourceClientListDelete, + CustomizeDiff: customdiff.All( + markVersionComputedIfListModified, + ), + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "The name of the client list.", + }, + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: fmt.Sprintf("The type of the client list. Valid types: %s", getValidListTypes()), + ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(getValidListTypes(), false)), + }, + "notes": { + Type: schema.TypeString, + Optional: true, + Description: "The client list notes.", + }, + "tags": { + Type: schema.TypeSet, + Optional: true, + Description: "The client list tags.", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "contract_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Contract ID for which client list is assigned.", + }, + "group_id": { + Type: schema.TypeInt, + Required: true, + ForceNew: true, + Description: "Group ID for which client list is assigned.", + }, + "list_id": { + Type: schema.TypeString, + Computed: true, + Description: "The ID of the client list.", + }, + "version": { + Type: schema.TypeInt, + Computed: true, + Description: "The current version of the client list.", + }, + "items_count": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of items that a client list contains.", + }, + "items": { + Type: schema.TypeSet, + Optional: true, + Description: "Set of items containing item information.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "value": { + Type: schema.TypeString, + Required: true, + Description: "Value of the item. (i.e. IP address, AS Number, GEO, ...etc)", + }, + "description": { + Type: schema.TypeString, + Optional: true, + Description: "A description of the item.", + Default: "", + }, + "tags": { + Type: schema.TypeSet, + Optional: true, + Description: "The item tags.", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "expiration_date": { + Type: schema.TypeString, + Optional: true, + Description: "The item expiration date.", + Default: "", + }, + }, + }, + }, + }, + } +} + +func resourceClientListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceClientListRead") + logger.Debug("Reading client list") + + getCLientList := clientlists.GetClientListRequest{ + ListID: d.Id(), + IncludeItems: true, + } + + list, err := client.GetClientList(ctx, getCLientList) + if e, ok := err.(*clientlists.Error); ok && e.StatusCode == http.StatusNotFound || list.Deprecated { + d.SetId("") + return nil + } else if err != nil { + logger.Errorf("calling 'getClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + + items := make([]interface{}, 0, len(list.Items)) + for _, v := range list.Items { + i := map[string]interface{}{ + "value": v.Value, + "description": v.Description, + "expiration_date": v.ExpirationDate, + "tags": v.Tags, + } + + items = append(items, i) + } + + fields := map[string]interface{}{ + "name": list.Name, + "type": list.Type, + "notes": list.Notes, + "tags": list.Tags, + "list_id": list.ListID, + "version": list.Version, + "items_count": list.ItemsCount, + "items": items, + } + + if err = tf.SetAttrs(d, fields); err != nil { + return diag.Errorf("%s: %s", tf.ErrValueSet, err.Error()) + } + + return nil +} + +func resourceClientListCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceClientListCreate") + logger.Debug("Creating client list") + + if err := validateItemsUniqueness(d); err != nil { + return diag.FromErr(err) + } + + listAttrs, err := getClientListAttr(d) + if err != nil { + return diag.FromErr(err) + } + + createCLientListRequest := clientlists.CreateClientListRequest{ + Name: listAttrs.Name, + Type: clientlists.ClientListType(listAttrs.ListType), + Notes: listAttrs.Notes, + Tags: listAttrs.Tags, + ContractID: listAttrs.ContractID, + GroupID: listAttrs.GroupID, + Items: listAttrs.Items, + } + + list, err := client.CreateClientList(ctx, createCLientListRequest) + if err != nil { + logger.Errorf("calling 'createClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + + d.SetId(list.ListID) + + return resourceClientListRead(ctx, d, m) +} + +func resourceClientListUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceClientListUpdate") + logger.Debug("Updating client list") + + if err := validateItemsUniqueness(d); err != nil { + return diag.FromErr(err) + } + + if d.HasChange("items") { + getListRes, err := client.GetClientList(ctx, clientlists.GetClientListRequest{ + ListID: d.Id(), + IncludeItems: true, + }) + if err != nil { + logger.Errorf("calling 'getClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + + itemsUpdateReq, err := getListItemsUpdateReq(*getListRes, d) + if err != nil { + logger.Errorf("constructing items update request failed: %s", err.Error()) + return diag.FromErr(err) + } + + _, err = client.UpdateClientListItems(ctx, *itemsUpdateReq) + if err != nil { + logger.Errorf("calling 'UpdateClientListItems' failed: %s", err.Error()) + return diag.FromErr(err) + } + } + + if d.HasChanges("name", "notes", "tags") { + listAttrs, err := getClientListAttr(d) + if err != nil { + return diag.FromErr(err) + } + + updateClientListRequest := clientlists.UpdateClientListRequest{ + ListID: d.Id(), + UpdateClientList: clientlists.UpdateClientList{ + Name: listAttrs.Name, + Notes: listAttrs.Notes, + Tags: listAttrs.Tags, + }, + } + + _, err = client.UpdateClientList(ctx, updateClientListRequest) + if err != nil { + logger.Errorf("calling 'updateClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + } + + return resourceClientListRead(ctx, d, m) +} + +func resourceClientListDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceClientListDelete") + logger.Debug("Deleting client list") + + deleteCLientListRequest := clientlists.DeleteClientListRequest{ + ListID: d.Id(), + } + + err := client.DeleteClientList(ctx, deleteCLientListRequest) + if err != nil { + logger.Errorf("calling 'deleteClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + + d.SetId("") + + return nil +} + +type clientListAttrs struct { + Name string + ListType string + Notes string + Tags []string + ContractID string + GroupID int64 + Items []clientlists.ListItemPayload +} + +func getClientListAttr(d *schema.ResourceData) (*clientListAttrs, error) { + name, err := tf.GetStringValue("name", d) + if err != nil { + return nil, err + } + listType, err := tf.GetStringValue("type", d) + if err != nil { + return nil, err + } + notes, err := tf.GetStringValue("notes", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + + ts, err := tf.GetSetValue("tags", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + tags := make([]string, 0, len(ts.List())) + for _, t := range ts.List() { + tags = append(tags, t.(string)) + } + + contractID, err := tf.GetStringValue("contract_id", d) + if err != nil { + return nil, err + } + groupID, err := tf.GetIntValue("group_id", d) + if err != nil { + return nil, err + } + + itemsSet, err := tf.GetSetValue("items", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + items := make([]clientlists.ListItemPayload, 0, itemsSet.Len()) + for _, v := range itemsSet.List() { + itemMap := v.(map[string]interface{}) + + t := itemMap["tags"].(*schema.Set) + items = append(items, clientlists.ListItemPayload{ + Value: itemMap["value"].(string), + Description: itemMap["description"].(string), + Tags: tf.SetToStringSlice(t), + ExpirationDate: itemMap["expiration_date"].(string), + }) + } + + return &clientListAttrs{ + Name: name, + ListType: listType, + Notes: notes, + Tags: tags, + ContractID: contractID, + GroupID: int64(groupID), + Items: items, + }, nil +} + +func getListItemsUpdateReq(list clientlists.GetClientListResponse, d *schema.ResourceData) (*clientlists.UpdateClientListItemsRequest, error) { + itemsSet, err := tf.GetSetValue("items", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + // Map of item value to ListItemPayload representing items in the config + configItemsMap := make(map[string]clientlists.ListItemPayload) + for _, v := range itemsSet.List() { + itemMap := v.(map[string]interface{}) + + configItemsMap[itemMap["value"].(string)] = clientlists.ListItemPayload{ + Value: itemMap["value"].(string), + Description: itemMap["description"].(string), + Tags: tf.SetToStringSlice(itemMap["tags"].(*schema.Set)), + ExpirationDate: itemMap["expiration_date"].(string), + } + } + + // Map of item value to item representing list of item in remote state + listItemsMap := make(map[string]clientlists.ListItemContent) + for _, v := range list.Items { + listItemsMap[v.Value] = v + } + + res := &clientlists.UpdateClientListItemsRequest{ + ListID: list.ListID, + UpdateClientListItems: clientlists.UpdateClientListItems{ + Append: []clientlists.ListItemPayload{}, + Update: []clientlists.ListItemPayload{}, + Delete: []clientlists.ListItemPayload{}, + }, + } + + for _, configItem := range configItemsMap { + if listItem, ok := listItemsMap[configItem.Value]; ok { + if shouldUpdateItem(configItem, listItem) { + res.UpdateClientListItems.Update = append(res.UpdateClientListItems.Update, configItem) + } + } else { + res.UpdateClientListItems.Append = append(res.UpdateClientListItems.Append, configItem) + } + } + + for _, listItem := range listItemsMap { + if _, ok := configItemsMap[listItem.Value]; !ok { + res.UpdateClientListItems.Delete = append(res.UpdateClientListItems.Delete, clientlists.ListItemPayload{ + Value: listItem.Value, + }) + } + } + + return res, nil +} + +func shouldUpdateItem(a clientlists.ListItemPayload, b clientlists.ListItemContent) bool { + if a.Value == b.Value && + a.Description == b.Description && + a.ExpirationDate == b.ExpirationDate && + isEqualTags(a.Tags, b.Tags) { + return false + } + return true +} + +func isEqualTags(t1, t2 []string) bool { + if len(t1) != len(t2) { + return false + } + + a := make([]string, len(t1)) + b := make([]string, len(t2)) + + copy(a, t1) + copy(b, t2) + + sort.Strings(a) + sort.Strings(b) + + return reflect.DeepEqual(a, b) +} + +func validateItemsUniqueness(d *schema.ResourceData) error { + itemsSet, err := tf.GetSetValue("items", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return err + } + + values := map[string]interface{}{} + for _, v := range itemsSet.List() { + itemMap := v.(map[string]interface{}) + value := itemMap["value"].(string) + + if _, ok := values[value]; ok { + return fmt.Errorf("'Items' collection contains duplicate values for 'value' field. Duplicate value: %s", value) + } + values[value] = itemMap + } + + return nil +} + +// markVersionComputedIfListModified sets 'version' field as new computed +// if a new version of client list is expected to be created. +func markVersionComputedIfListModified(_ context.Context, d *schema.ResourceDiff, m interface{}) error { + meta := meta.Must(m) + logger := meta.Log("CLIENTLIST", "markVersionComputedIfListModified") + + itemsHasChange := d.HasChange("items") + oldItems, newItems := d.GetChange("items") + + isVersionUpdateRequired, err := isVersionUpdateRequired(oldItems, newItems) + if err != nil { + return err + } + + if itemsHasChange && isVersionUpdateRequired { + logger.Debug("setting version as new computed") + if err := d.SetNewComputed("version"); err != nil { + return fmt.Errorf("%w: %s", tf.ErrValueSet, err.Error()) + } + } + + return nil +} + +// isVersionUpdateRequired determines if list version update is required based on items changes +func isVersionUpdateRequired(oldValue, newValue interface{}) (bool, error) { + if oldValue == nil || newValue == nil { + return oldValue != newValue, nil + } + + o, ok := oldValue.(*schema.Set) + if !ok { + return false, fmt.Errorf("'items' old value is not of type schema.Set") + } + n, ok := newValue.(*schema.Set) + if !ok { + return false, fmt.Errorf("'items' new value is not of type schema.Set") + } + + if o.Len() != n.Len() { + return true, nil + } + + oldMap := mapExpirationDateToValue(o) + newMap := mapExpirationDateToValue(n) + + for newValue, newExpDate := range newMap { + // if value does not exist or expiration dates are different, + // then version update is required + if oldExpDate, ok := oldMap[newValue]; !ok || oldExpDate != newExpDate { + return true, nil + } + } + + return false, nil +} + +func mapExpirationDateToValue(items *schema.Set) map[string]string { + res := make(map[string]string) + + for _, v := range items.List() { + item := v.(map[string]interface{}) + res[item["value"].(string)] = item["expiration_date"].(string) + } + + return res +} diff --git a/pkg/providers/clientlists/resource_akamai_clientlists_list_activation.go b/pkg/providers/clientlists/resource_akamai_clientlists_list_activation.go new file mode 100644 index 000000000..378a93dce --- /dev/null +++ b/pkg/providers/clientlists/resource_akamai_clientlists_list_activation.go @@ -0,0 +1,289 @@ +package clientlists + +import ( + "context" + "errors" + "fmt" + "strconv" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +var ( + pollActivationInterval = 30 * time.Second +) + +func resourceClientListActivation() *schema.Resource { + return &schema.Resource{ + ReadContext: resourceActivationRead, + CreateContext: resourceActivationCreate, + UpdateContext: resourceActivationUpdate, + DeleteContext: resourceActivationDelete, + Schema: map[string]*schema.Schema{ + "list_id": { + Type: schema.TypeString, + Required: true, + Description: "The client list unique identifier.", + }, + "version": { + Type: schema.TypeInt, + Required: true, + Description: "The client list version.", + }, + "network": { + Type: schema.TypeString, + Required: true, + Description: "The network environment where you activate your client list: either STAGING or PRODUCTION.", + ValidateDiagFunc: validation.ToDiagFunc( + validation.StringInSlice([]string{string(clientlists.Staging), string(clientlists.Production)}, false), + ), + }, + "comments": { + Type: schema.TypeString, + Optional: true, + Description: "A brief description for the activation.", + DiffSuppressFunc: suppressCommentsDiff, + }, + "notification_recipients": { + Type: schema.TypeSet, + Optional: true, + Description: "Users to notify via email.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "siebel_ticket_id": { + Type: schema.TypeString, + Optional: true, + Description: "Identifies the Siebel ticket, if the activation is linked to one.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "The current activation status, either ACTIVE, INACTIVE, MODIFIED, PENDING_ACTIVATION, PENDING_DEACTIVATION, or FAILED.", + }, + }, + } +} + +func resourceActivationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceActivationRead") + logger.Debug("Reading client list activation") + + id, err := strconv.ParseInt(d.Id(), 10, 64) + if err != nil { + return diag.FromErr(err) + } + + activationRes, err := client.GetActivation(ctx, clientlists.GetActivationRequest{ + ActivationID: id, + }) + if err != nil { + logger.Errorf("calling 'GetActivation' failed: %s", err.Error()) + return diag.FromErr(err) + } + + // Get client list latest version + listRes, err := client.GetClientList(ctx, clientlists.GetClientListRequest{ + ListID: activationRes.ListID, + IncludeItems: false, + }) + if err != nil { + logger.Errorf("calling 'GetClientList' failed: %s", err.Error()) + return diag.FromErr(err) + } + + fields := map[string]interface{}{ + "list_id": activationRes.ListID, + "comments": activationRes.Comments, + "network": activationRes.Network, + "notification_recipients": activationRes.NotificationRecipients, + "siebel_ticket_id": activationRes.SiebelTicketID, + "version": listRes.Version, + "status": activationRes.ActivationStatus, + } + + if err = tf.SetAttrs(d, fields); err != nil { + return diag.Errorf("%s: %s", tf.ErrValueSet, err.Error()) + } + + return nil +} + +func resourceActivationCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceActivationCreate") + logger.Debug("Creating client list activation") + + attrs, err := getResourceAttrs(d) + if err != nil { + diag.FromErr(err) + } + + req := clientlists.CreateActivationRequest{ + ListID: attrs.ListID, + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Comments: attrs.Comments, + SiebelTicketID: attrs.SiebelTicketID, + Network: clientlists.ActivationNetwork(attrs.Network), + NotificationRecipients: attrs.Emails, + }, + } + + res, err := client.CreateActivation(ctx, req) + if err != nil { + logger.Errorf("calling 'CreateActivation' failed: %s", err.Error()) + return diag.FromErr(err) + } + + d.SetId(fmt.Sprintf("%d", res.ActivationID)) + + err = waitForActivationCompletion(ctx, client, res.ActivationID) + if err != nil { + return diag.FromErr(err) + } + + return resourceActivationRead(ctx, d, m) +} + +func resourceActivationUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + client := inst.Client(meta) + logger := meta.Log("CLIENTLIST", "resourceActivationUpdate") + logger.Debug("Updating client list activation") + + if d.HasChanges("list_id", "version", "network") { + attrs, err := getResourceAttrs(d) + if err != nil { + return diag.FromErr(err) + } + + req := clientlists.CreateActivationRequest{ + ListID: attrs.ListID, + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Comments: attrs.Comments, + SiebelTicketID: attrs.SiebelTicketID, + Network: clientlists.ActivationNetwork(attrs.Network), + NotificationRecipients: attrs.Emails, + }, + } + + res, err := client.CreateActivation(ctx, req) + if err != nil { + logger.Errorf("calling 'CreateActivation' failed: %s", err.Error()) + return diag.FromErr(err) + } + + d.SetId(fmt.Sprintf("%d", res.ActivationID)) + + err = waitForActivationCompletion(ctx, client, res.ActivationID) + if err != nil { + return diag.FromErr(err) + } + } else if d.HasChanges("notification_recipients", "siebel_ticket_id") { + return diag.Errorf("The following attributes 'notification_recipients', 'siebel_ticket_id' " + + "cannot be modified after activation.") + } + + return resourceActivationRead(ctx, d, m) +} + +func resourceActivationDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + meta := meta.Must(m) + logger := meta.Log("CLIENTLIST", "resourceActivationDelete") + logger.Debug("Deleting client list activation") + + d.SetId("") + return diag.Diagnostics{ + diag.Diagnostic{ + Severity: diag.Warning, + Summary: "Client Lists API does not support activation deletion - resource will only be removed from state", + }, + } +} + +type resourceAttrs struct { + ListID string + Network string + Comments string + SiebelTicketID string + Emails []string + Version int64 +} + +func getResourceAttrs(d *schema.ResourceData) (*resourceAttrs, error) { + listID, err := tf.GetStringValue("list_id", d) + if err != nil { + return nil, err + } + version, err := tf.GetInt64Value("version", tf.NewRawConfig(d)) + if err != nil { + return nil, err + } + network, err := tf.GetStringValue("network", d) + if err != nil { + return nil, err + } + comments, err := tf.GetStringValue("comments", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + siebelTicketID, err := tf.GetStringValue("siebel_ticket_id", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + emailsSet, err := tf.GetSetValue("notification_recipients", d) + if err != nil && !errors.Is(err, tf.ErrNotFound) { + return nil, err + } + emails := tf.SetToStringSlice(emailsSet) + + return &resourceAttrs{ + ListID: listID, + Version: version, + Network: network, + Comments: comments, + SiebelTicketID: siebelTicketID, + Emails: emails, + }, nil +} + +func waitForActivationCompletion(ctx context.Context, client clientlists.ClientLists, activationID int64) error { + for { + select { + case <-time.After(pollActivationInterval): + r, err := client.GetActivation(ctx, clientlists.GetActivationRequest{ActivationID: activationID}) + if err != nil { + return fmt.Errorf("polling activation failed: %s", err) + } + + if r.ActivationStatus == clientlists.Active { + return nil + } else if r.ActivationStatus == clientlists.Failed { + return fmt.Errorf("activation failed") + } + case <-ctx.Done(): + return fmt.Errorf("activation context terminated: %s", ctx.Err()) + } + } +} + +// Suppress comments diff when activation is not required, +// and activation resource cannot be updated. +func suppressCommentsDiff(_, oldValue, newValue string, d *schema.ResourceData) bool { + if oldValue != newValue && d.HasChanges("list_id", "version", "network") { + return false + } + return true +} diff --git a/pkg/providers/clientlists/resource_akamai_clientlists_list_activation_test.go b/pkg/providers/clientlists/resource_akamai_clientlists_list_activation_test.go new file mode 100644 index 000000000..477407718 --- /dev/null +++ b/pkg/providers/clientlists/resource_akamai_clientlists_list_activation_test.go @@ -0,0 +1,460 @@ +package clientlists + +import ( + "fmt" + "regexp" + "strconv" + "testing" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestClientListActivationResource(t *testing.T) { + pollActivationInterval = time.Microsecond + + type ActivationAttrs struct { + ListID, Comments, SiebelTicketID, Network string + NotificationRecipients []string + Version, ActivationID int + Status clientlists.ActivationStatus + } + + const testDir = "testData/TestResActivation" + + var ( + createActivationAPIError = "{\n \"type\": \"https://problems.luna.akamaiapis.net/client-list-api/error-types/INVALID-INPUT-ERROR\",\n \"status\": 400,\n \"title\": \"Invalid Input Error\",\n \"detail\": \"Validation failed: Invalid network\",\n \"instance\": \"https://problems.luna.akamaiapis.net/client-list-api/error-instances/9ff3649993cb002b\",\n \"\n }\n" + + expectCreateActivation = func(t *testing.T, client *clientlists.Mock, req clientlists.CreateActivationRequest, version int64, activationID int64) *clientlists.CreateActivationResponse { + res := clientlists.CreateActivationResponse{ + ActivationID: activationID, + ListID: req.ListID, + Comments: req.Comments, + SiebelTicketID: req.SiebelTicketID, + Network: req.Network, + NotificationRecipients: req.NotificationRecipients, + ActivationStatus: clientlists.PendingActivation, + Version: version, + } + + client.On("CreateActivation", mock.Anything, req).Return(&res, nil).Once() + + return &res + } + + expectReadActivation = func(t *testing.T, client *clientlists.Mock, req clientlists.GetActivationRequest, attrs ActivationAttrs, times int) *clientlists.GetActivationResponse { + res := clientlists.GetActivationResponse{ + ActivationID: int64(attrs.ActivationID), + ListID: attrs.ListID, + Version: int64(attrs.Version), + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Comments: attrs.Comments, + Network: clientlists.ActivationNetwork(attrs.Network), + SiebelTicketID: attrs.SiebelTicketID, + NotificationRecipients: attrs.NotificationRecipients, + }, + InitialActivation: true, + Fast: true, + ActivationStatus: clientlists.ActivationStatus(attrs.Status), + } + + client.On("GetActivation", mock.Anything, req).Return(&res, nil).Times(times) + + return &res + } + + expectGetClientlist = func(t *testing.T, client *clientlists.Mock, listID string, version int64, callTimes int) { + clientListGetReq := clientlists.GetClientListRequest{ + ListID: listID, + IncludeItems: false, + } + + clientList := clientlists.GetClientListResponse{ListContent: clientlists.ListContent{Version: version}} + client.On("GetClientList", mock.Anything, clientListGetReq).Return(&clientList, nil).Times(callTimes) + } + + expectAPIErrorWithCreateActivation = func(t *testing.T, client *clientlists.Mock, req clientlists.CreateActivationRequest) { + err := fmt.Errorf(createActivationAPIError) + client.On("CreateActivation", mock.Anything, req).Return(nil, err).Once() + } + + checkAttributes = func(a ActivationAttrs) resource.TestCheckFunc { + resourceName := "akamai_clientlist_activation.activation_ASN_LIST_1" + + checks := []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(resourceName, "list_id", a.ListID), + resource.TestCheckResourceAttr(resourceName, "comments", a.Comments), + resource.TestCheckResourceAttr(resourceName, "notification_recipients.#", strconv.Itoa(len(a.NotificationRecipients))), + resource.TestCheckResourceAttr(resourceName, "siebel_ticket_id", a.SiebelTicketID), + resource.TestCheckResourceAttr(resourceName, "network", a.Network), + resource.TestCheckResourceAttr(resourceName, "version", strconv.Itoa(a.Version)), + } + return resource.ComposeAggregateTestCheckFunc(checks...) + } + + getActivationAttrs = func(actRes *clientlists.CreateActivationResponse, status clientlists.ActivationStatus) ActivationAttrs { + return ActivationAttrs{ + ActivationID: int(actRes.ActivationID), + SiebelTicketID: actRes.SiebelTicketID, + Network: string(actRes.Network), + Comments: actRes.Comments, + NotificationRecipients: actRes.NotificationRecipients, + ListID: actRes.ListID, + Version: int(actRes.Version), + Status: status, + } + } + ) + + t.Run("create activation", func(t *testing.T) { + client := new(clientlists.Mock) + + activationReq := clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + } + activationRes := expectCreateActivation(t, client, activationReq, 2, 33) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.PendingActivation), 2) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.Active), 3) + + expectGetClientlist(t, client, "12_AB", 2, 2) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: activationRes.Comments, + Version: int(activationRes.Version), + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("update activation - version and other fields update", func(t *testing.T) { + client := new(clientlists.Mock) + + activationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }, 2, 33) + updatedActivationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "UPDATED-12345", + NotificationRecipients: []string{"update_user@example.com"}, + Comments: "Activation Comments Updated", + }, + }, 3, 34) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.PendingActivation), 1) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.Active), 4) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: updatedActivationRes.ActivationID}, + getActivationAttrs(updatedActivationRes, clientlists.PendingActivation), 2) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: updatedActivationRes.ActivationID}, + getActivationAttrs(updatedActivationRes, clientlists.Active), 3) + + expectGetClientlist(t, client, "12_AB", 2, 3) + + expectGetClientlist(t, client, "12_AB", 3, 2) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: activationRes.Comments, + Version: int(activationRes.Version), + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_update.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: updatedActivationRes.ListID, + Network: string(updatedActivationRes.Network), + NotificationRecipients: updatedActivationRes.NotificationRecipients, + SiebelTicketID: updatedActivationRes.SiebelTicketID, + Comments: updatedActivationRes.Comments, + Version: int(updatedActivationRes.Version), + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("update activation - version only update", func(t *testing.T) { + client := new(clientlists.Mock) + + activationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }, 2, 33) + updatedActivationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }, 3, 34) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.PendingActivation), 1) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.Active), 4) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: updatedActivationRes.ActivationID}, + getActivationAttrs(updatedActivationRes, clientlists.PendingActivation), 2) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: updatedActivationRes.ActivationID}, + getActivationAttrs(updatedActivationRes, clientlists.Active), 3) + + expectGetClientlist(t, client, "12_AB", 2, 3) + + expectGetClientlist(t, client, "12_AB", 3, 2) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: activationRes.Comments, + Version: int(activationRes.Version), + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_update_version_only.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: updatedActivationRes.ListID, + Network: string(updatedActivationRes.Network), + NotificationRecipients: updatedActivationRes.NotificationRecipients, + SiebelTicketID: updatedActivationRes.SiebelTicketID, + Comments: updatedActivationRes.Comments, + Version: int(updatedActivationRes.Version), + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("update activation - siebelTicketId only update ", func(t *testing.T) { + client := new(clientlists.Mock) + + activationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }, 2, 33) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.PendingActivation), 2) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.Active), 4) + + expectGetClientlist(t, client, "12_AB", 2, 3) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: activationRes.Comments, + Version: int(activationRes.Version), + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_update_siebelTicketId.tf", testDir)), + ExpectError: regexp.MustCompile("Error: The following attributes 'notification_recipients', 'siebel_ticket_id' " + + "cannot be modified after activation."), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("update activation - comments only update suppressed", func(t *testing.T) { + client := new(clientlists.Mock) + + activationRes := expectCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }, 2, 33) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.PendingActivation), 1) + + expectReadActivation(t, client, + clientlists.GetActivationRequest{ActivationID: activationRes.ActivationID}, + getActivationAttrs(activationRes, clientlists.Active), 5) + + expectGetClientlist(t, client, "12_AB", 2, 4) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: activationRes.Comments, + Version: int(activationRes.Version), + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_update_comments_suppressed.tf", testDir)), + Check: checkAttributes(ActivationAttrs{ + ListID: activationRes.ListID, + Network: string(activationRes.Network), + NotificationRecipients: activationRes.NotificationRecipients, + SiebelTicketID: activationRes.SiebelTicketID, + Comments: "Activation Comments", + Version: int(activationRes.Version), + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Create activation with missing list id fails", func(t *testing.T) { + client := new(clientlists.Mock) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_missing_param.tf", testDir)), + ExpectError: regexp.MustCompile("The argument \"list_id\" is required, but no definition was found"), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Create activation api fails", func(t *testing.T) { + client := new(clientlists.Mock) + + expectAPIErrorWithCreateActivation(t, client, clientlists.CreateActivationRequest{ + ListID: "12_AB", + ActivationParams: clientlists.ActivationParams{ + Action: clientlists.Activate, + Network: clientlists.Staging, + SiebelTicketID: "ABC-12345", + NotificationRecipients: []string{"user@example.com"}, + Comments: "Activation Comments", + }, + }) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/activation_create.tf", testDir)), + ExpectError: regexp.MustCompile(createActivationAPIError), + }, + }, + }) + }) + client.AssertExpectations(t) + }) +} diff --git a/pkg/providers/clientlists/resource_akamai_clientlists_list_test.go b/pkg/providers/clientlists/resource_akamai_clientlists_list_test.go new file mode 100644 index 000000000..7848482e9 --- /dev/null +++ b/pkg/providers/clientlists/resource_akamai_clientlists_list_test.go @@ -0,0 +1,791 @@ +package clientlists + +import ( + "fmt" + "regexp" + "strconv" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/clientlists" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestResourceClientList(t *testing.T) { + type listAttributes struct { + ListID, Name, Notes, Type, ContractID string + Tags []string + GroupID int + Version int + ItemsCount int + Items []clientlists.ListItemPayload + } + + const testDir = "testData/TestResClientList" + + var ( + updateAPIError = "{\n \"type\": \"https://problems.luna.akamaiapis.net/client-list-api/error-types/INVALID-INPUT-ERROR\",\n \"status\": 400,\n \"title\": \"Invalid Input Error\",\n \"detail\": \"Validation failed: tags: tags exceeds max size of 5 entries\",\n \"instance\": \"https://problems.luna.akamaiapis.net/client-list-api/error-instances/9ff3649993cb002b\",\n \"\n }\n" + + mapItemsPayloadToContent = func(items []clientlists.ListItemPayload) []clientlists.ListItemContent { + result := make([]clientlists.ListItemContent, 0, len(items)) + for _, v := range items { + result = append(result, clientlists.ListItemContent{ + Value: v.Value, + Description: v.Description, + Tags: v.Tags, + ExpirationDate: v.ExpirationDate, + }) + } + return result + } + + expectCreateList = func(t *testing.T, client *clientlists.Mock, req clientlists.CreateClientListRequest) *clientlists.CreateClientListResponse { + + createResponse := clientlists.CreateClientListResponse{ + ListContent: clientlists.ListContent{ + ListID: "1_AB", + Name: req.Name, + Notes: req.Notes, + Tags: req.Tags, + Type: req.Type, + Version: 1, + ItemsCount: int64(len(req.Items)), + }, + ContractID: req.ContractID, + GroupName: "Group-Name", + Items: mapItemsPayloadToContent(req.Items), + } + + client.On("CreateClientList", mock.Anything, req).Return(&createResponse, nil).Once() + return &createResponse + } + + expectUpdateList = func(t *testing.T, client *clientlists.Mock, listType clientlists.ClientListType, itemsCount int64, req clientlists.UpdateClientListRequest) *clientlists.UpdateClientListResponse { + + updateResponse := clientlists.UpdateClientListResponse{ + ListContent: clientlists.ListContent{ + ListID: "1_AB", + Name: req.Name, + Notes: req.Notes, + Tags: req.Tags, + Type: listType, + Version: 1, + ItemsCount: itemsCount, + }, + } + + client.On("UpdateClientList", mock.Anything, req).Return(&updateResponse, nil).Once() + return &updateResponse + } + + expectUpdateListItems = func(t *testing.T, client *clientlists.Mock, req clientlists.UpdateClientListItemsRequest) *clientlists.UpdateClientListItemsResponse { + appended := make([]clientlists.ListItemContent, 0, len(req.Append)) + for _, v := range req.Append { + appended = append(appended, clientlists.ListItemContent{ + Value: v.Value, + Description: v.Description, + Tags: v.Tags, + ExpirationDate: v.ExpirationDate, + }) + } + updated := make([]clientlists.ListItemContent, 0, len(req.Update)) + for _, v := range req.Update { + updated = append(updated, clientlists.ListItemContent{ + Value: v.Value, + Description: v.Description, + Tags: v.Tags, + ExpirationDate: v.ExpirationDate, + }) + } + deleted := make([]clientlists.ListItemContent, 0, len(req.Delete)) + for _, v := range req.Delete { + deleted = append(deleted, clientlists.ListItemContent{ + Value: v.Value, + Description: v.Description, + Tags: v.Tags, + ExpirationDate: v.ExpirationDate, + }) + } + + updateResponse := clientlists.UpdateClientListItemsResponse{ + Appended: appended, + Updated: updated, + Deleted: deleted, + } + + client.On("UpdateClientListItems", mock.Anything, req).Return(&updateResponse, nil).Once() + return &updateResponse + } + + expectReadList = func(t *testing.T, client *clientlists.Mock, list clientlists.ListContent, items []clientlists.ListItemContent, callTimes int) { + clientListGetReq := clientlists.GetClientListRequest{ + ListID: list.ListID, + IncludeItems: true, + } + + clientList := clientlists.GetClientListResponse{ + ListContent: list, + Items: items, + } + client.On("GetClientList", mock.Anything, clientListGetReq).Return(&clientList, nil).Times(callTimes) + } + + expectDeleteList = func(t *testing.T, client *clientlists.Mock, list clientlists.ListContent) { + clientListDeleteReq := clientlists.DeleteClientListRequest{ + ListID: list.ListID, + } + client.On("DeleteClientList", mock.Anything, clientListDeleteReq).Return(nil).Once() + } + + expectAPIErrorWithUpdateList = func(t *testing.T, client *clientlists.Mock, req clientlists.UpdateClientListRequest) { + err := fmt.Errorf(updateAPIError) + client.On("UpdateClientList", mock.Anything, req).Return(nil, err).Once() + } + + checkAttributes = func(attrs listAttributes) resource.TestCheckFunc { + resourceName := "akamai_clientlist_list.test_list" + checks := []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(resourceName, "list_id", attrs.ListID), + resource.TestCheckResourceAttr(resourceName, "name", attrs.Name), + resource.TestCheckResourceAttr(resourceName, "notes", attrs.Notes), + resource.TestCheckResourceAttr(resourceName, "type", attrs.Type), + resource.TestCheckResourceAttr(resourceName, "tags.#", strconv.Itoa(len(attrs.Tags))), + resource.TestCheckResourceAttr(resourceName, "contract_id", attrs.ContractID), + resource.TestCheckResourceAttr(resourceName, "group_id", strconv.Itoa(attrs.GroupID)), + resource.TestCheckResourceAttr(resourceName, "version", strconv.Itoa(attrs.Version)), + resource.TestCheckResourceAttr(resourceName, "items_count", strconv.Itoa(attrs.ItemsCount)), + resource.TestCheckResourceAttr(resourceName, "items.#", strconv.Itoa(len(attrs.Items))), + } + + return resource.ComposeAggregateTestCheckFunc(checks...) + } + ) + + t.Run("Create a new client list", func(t *testing.T) { + client := new(clientlists.Mock) + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: []clientlists.ListItemPayload{}, + }) + expectReadList(t, client, clientList.ListContent, []clientlists.ListItemContent{}, 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + Items: []clientlists.ListItemPayload{}, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update client list", func(t *testing.T) { + client := new(clientlists.Mock) + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: []clientlists.ListItemPayload{}, + }) + expectReadList(t, client, clientList.ListContent, []clientlists.ListItemContent{}, 3) + updateResponse := expectUpdateList(t, client, clientlists.ASN, 0, clientlists.UpdateClientListRequest{ + UpdateClientList: clientlists.UpdateClientList{ + Name: "List Name Updated", + Notes: "List Notes Updated", + Tags: []string{"a", "c", "d"}, + }, + ListID: clientList.ListID, + }) + expectReadList(t, client, updateResponse.ListContent, []clientlists.ListItemContent{}, 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_update.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name Updated", + Notes: "List Notes Updated", + Tags: []string{"a", "c", "d"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update client list not expected when empty tags list removed", func(t *testing.T) { + client := new(clientlists.Mock) + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{}, + Type: clientlists.IP, + ContractID: "12_ABC", + GroupID: 12, + Items: []clientlists.ListItemPayload{}, + }) + expectReadList(t, client, clientList.ListContent, []clientlists.ListItemContent{}, 4) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_create_empty_tags.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Type: "IP", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_update_remove_tags.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{}, + Type: "IP", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update client list returns an API error", func(t *testing.T) { + client := new(clientlists.Mock) + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: []clientlists.ListItemPayload{}, + }) + expectReadList(t, client, clientList.ListContent, []clientlists.ListItemContent{}, 3) + + expectAPIErrorWithUpdateList(t, client, clientlists.UpdateClientListRequest{ + UpdateClientList: clientlists.UpdateClientList{ + Name: "List Name Updated", + Notes: "List Notes Updated", + Tags: []string{"a", "c", "d"}, + }, + ListID: clientList.ListID, + }) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 0, + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_update.tf", testDir)), + ExpectError: regexp.MustCompile(updateAPIError), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Create a new client list with items", func(t *testing.T) { + client := new(clientlists.Mock) + items := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }, + clientlists.ListItemPayload{ + Value: "123", + ExpirationDate: "2026-12-26T01:00:00+00:00", + Tags: []string{}, + }, + clientlists.ListItemPayload{ + Value: "12", + Description: "Item 12 Desc", + Tags: []string{"item12Tag1", "item12Tag2"}, + }) + + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: items, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(items), 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: len(items), + Items: items, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update client list items and list", func(t *testing.T) { + client := new(clientlists.Mock) + items := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }, + clientlists.ListItemPayload{ + Value: "123", + ExpirationDate: "2026-12-26T01:00:00+00:00", + Tags: []string{}, + }, + clientlists.ListItemPayload{ + Value: "12", + Description: "Item 12 Desc", + Tags: []string{"item12Tag1", "item12Tag2"}, + }) + updatedItems := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }, + clientlists.ListItemPayload{ + Value: "12", + Description: "Item 12 Desc Updated", + Tags: []string{"item12Tag1", "item12Tag2"}, + }, + clientlists.ListItemPayload{ + Value: "1234", + Description: "Item 1234 Desc", + Tags: []string{"1234Tag"}, + }) + + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: items, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(items), 4) + updateResponse := expectUpdateList(t, client, clientlists.ASN, 3, clientlists.UpdateClientListRequest{ + UpdateClientList: clientlists.UpdateClientList{ + Name: "List Name Updated", + Notes: "List Notes Updated", + Tags: []string{"a", "c", "d"}, + }, + ListID: clientList.ListID, + }) + expectUpdateListItems(t, client, clientlists.UpdateClientListItemsRequest{ + ListID: clientList.ListID, + UpdateClientListItems: clientlists.UpdateClientListItems{ + Append: []clientlists.ListItemPayload{ + { + Value: "1234", + Description: "Item 1234 Desc", + Tags: []string{"1234Tag"}, + }, + }, + Update: []clientlists.ListItemPayload{ + { + Value: "12", + Description: "Item 12 Desc Updated", + Tags: []string{"item12Tag1", "item12Tag2"}, + }, + }, + Delete: []clientlists.ListItemPayload{ + { + Value: "123", + }, + }, + }, + }) + expectReadList(t, client, updateResponse.ListContent, mapItemsPayloadToContent(updatedItems), 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 3, + Items: items, + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_update.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name Updated", + Notes: "List Notes Updated", + Tags: []string{"a", "c", "d"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 3, + Items: updatedItems, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update client list items only", func(t *testing.T) { + client := new(clientlists.Mock) + items := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }, + clientlists.ListItemPayload{ + Value: "123", + ExpirationDate: "2026-12-26T01:00:00+00:00", + Tags: []string{}, + }, + clientlists.ListItemPayload{ + Value: "12", + Description: "Item 12 Desc", + Tags: []string{"item12Tag1", "item12Tag2"}, + }) + updatedItems := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }, + clientlists.ListItemPayload{ + Value: "12", + Description: "Item 12 Desc Updated", + Tags: []string{"item12Tag1", "item12Tag2"}, + }, + clientlists.ListItemPayload{ + Value: "1234", + Description: "Item 1234 Desc", + Tags: []string{"1234Tag"}, + }) + + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: items, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(items), 4) + expectUpdateListItems(t, client, clientlists.UpdateClientListItemsRequest{ + ListID: clientList.ListID, + UpdateClientListItems: clientlists.UpdateClientListItems{ + Append: []clientlists.ListItemPayload{ + { + Value: "1234", + Description: "Item 1234 Desc", + Tags: []string{"1234Tag"}, + }, + }, + Update: []clientlists.ListItemPayload{ + { + Value: "12", + Description: "Item 12 Desc Updated", + Tags: []string{"item12Tag1", "item12Tag2"}, + }, + }, + Delete: []clientlists.ListItemPayload{ + { + Value: "123", + }, + }, + }, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(updatedItems), 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_create.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 3, + Items: items, + }), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_items_only_update.tf", testDir)), + Check: checkAttributes(listAttributes{ + ListID: clientList.ListID, + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: "ASN", + ContractID: "12_ABC", + GroupID: 12, + Version: 1, + ItemsCount: 3, + Items: updatedItems, + }), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update items set new computed version", func(t *testing.T) { + client := new(clientlists.Mock) + items := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }) + updatedItems := []clientlists.ListItemPayload{} + + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: items, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(items), 4) + expectUpdateListItems(t, client, clientlists.UpdateClientListItemsRequest{ + ListID: clientList.ListID, + UpdateClientListItems: clientlists.UpdateClientListItems{ + Append: []clientlists.ListItemPayload{}, + Update: []clientlists.ListItemPayload{}, + Delete: []clientlists.ListItemPayload{{Value: "1"}}, + }, + }) + // Update version + updatedClientList := clientList.ListContent + updatedClientList.Version = 2 + + expectReadList(t, client, updatedClientList, mapItemsPayloadToContent(updatedItems), 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_create_one_item.tf", testDir)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("version", "1"), + ), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_items_update_compute_version.tf", testDir)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("version", "2"), + ), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Update items NOT set new computed version", func(t *testing.T) { + client := new(clientlists.Mock) + items := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + Description: "Item 1 Desc", + Tags: []string{"item1Tag2", "item1Tag1"}, + }) + updatedItems := append([]clientlists.ListItemPayload{}, + clientlists.ListItemPayload{ + Value: "1", + }) + + clientList := expectCreateList(t, client, clientlists.CreateClientListRequest{ + Name: "List Name", + Notes: "List Notes", + Tags: []string{"a", "b"}, + Type: clientlists.ASN, + ContractID: "12_ABC", + GroupID: 12, + Items: items, + }) + expectReadList(t, client, clientList.ListContent, mapItemsPayloadToContent(items), 4) + expectUpdateListItems(t, client, clientlists.UpdateClientListItemsRequest{ + ListID: clientList.ListID, + UpdateClientListItems: clientlists.UpdateClientListItems{ + Append: []clientlists.ListItemPayload{}, + Update: []clientlists.ListItemPayload{ + { + Value: "1", + Tags: []string{}, + }, + }, + Delete: []clientlists.ListItemPayload{}, + }, + }) + // Fake version update + updatedClientList := clientList.ListContent + updatedClientList.Version = 2 + expectReadList(t, client, updatedClientList, mapItemsPayloadToContent(updatedItems), 2) + expectDeleteList(t, client, clientList.ListContent) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_items_create_one_item.tf", testDir)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("version", "1"), + ), + }, + { + Config: loadFixtureString(fmt.Sprintf("%s/list_items_update_not_compute_version.tf", testDir)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckOutput("version", "1"), + ), + }, + }, + }) + }) + client.AssertExpectations(t) + }) + + t.Run("Create list with duplicate items fails", func(t *testing.T) { + client := new(clientlists.Mock) + + useClient(client, func() { + resource.UnitTest(t, resource.TestCase{ + ProviderFactories: testAccProviders, + Steps: []resource.TestStep{ + { + Config: loadFixtureString(fmt.Sprintf("%s/list_and_duplicate_items_create.tf", testDir)), + ExpectError: regexp.MustCompile("Error: 'Items' collection contains duplicate values for 'value' field. Duplicate value: 12"), + }, + }, + }) + }) + client.AssertExpectations(t) + }) +} diff --git a/pkg/providers/clientlists/templates.go b/pkg/providers/clientlists/templates.go new file mode 100644 index 000000000..604da0414 --- /dev/null +++ b/pkg/providers/clientlists/templates.go @@ -0,0 +1,93 @@ +package clientlists + +import ( + "bytes" + "fmt" + "strings" + "text/template" + + "github.com/jedib0t/go-pretty/v6/table" +) + +// OutputTemplates is a map of templates +type OutputTemplates map[string]*OutputTemplate + +// OutputTemplate contains template data +type OutputTemplate struct { + TemplateName string + TemplateType string + TableTitle string + TemplateString string +} + +// GetTemplate given map of templates and a key, returns template stored under this key +func GetTemplate(ots map[string]*OutputTemplate, key string) (*OutputTemplate, error) { + if f, ok := ots[key]; ok && f != nil { + return f, nil + } + + return nil, fmt.Errorf("error: template '%s' not found", key) +} + +// RenderTemplates renders template and returns it as a string +func RenderTemplates(ots map[string]*OutputTemplate, key string, str interface{}) (string, error) { + var ostr, tstr bytes.Buffer + templ, err := GetTemplate(ots, key) + + if err != nil { + return "", nil + } + + t := template.Must(template.New("").Parse(templ.TemplateString)) + if err := t.Execute(&tstr, str); err != nil { + return "", nil + } + + temptype := templ.TemplateType + + if temptype == "TABULAR" { + tbl := table.NewWriter() + tbl.SetOutputMirror(&ostr) + tbl.SetTitle(key) + headers := templ.TableTitle + + headercolumns := strings.Split(headers, "|") + trhdr := table.Row{} + for _, header := range headercolumns { + trhdr = append(trhdr, header) + } + tbl.AppendHeader(trhdr) + + ar := strings.Split(tstr.String(), "<<>>") + for _, recContent := range ar { + trc := []table.Row{} + ac := strings.Split(recContent, ">><<") + tr := table.Row{} + for _, colContent := range ac { + tr = append(tr, colContent) + } + trc = append(trc, tr) + tbl.AppendRows(trc) + } + + tbl.Render() + } else { + return "\n" + tstr.String(), nil + } + return "\n" + ostr.String(), nil + +} + +// InitTemplates populates map of templates given as argument with output templates +func InitTemplates(otm map[string]*OutputTemplate) { + + // DS templates + otm["clientListsDS"] = &OutputTemplate{ + TemplateType: "TABULAR", + TemplateName: "clientLists", + TableTitle: "ListId|Name|Tags|Type|ItemsCount|Version|ReadOnly|UpdateDate|Notes", + // Rows delimiter is <<>> + // Cells delimiter is >><< + TemplateString: `{{range $index, $element := .Content}}{{if $index}}<<>>{{end}}{{.ListID}}>><<{{.Name}}>><<{{.Tags}}>><<{{.Type}}>><<{{.ItemsCount}}>><<{{.Version}}>><<{{.ReadOnly}}>><<{{.UpdateDate}}>><<{{.Notes}}{{end}}`, + } +} diff --git a/pkg/providers/clientlists/testData/TestDSClientList/ClientLists.json b/pkg/providers/clientlists/testData/TestDSClientList/ClientLists.json new file mode 100644 index 000000000..53880dba6 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestDSClientList/ClientLists.json @@ -0,0 +1,245 @@ +{ + "content": [ + { + "createDate": "2023-06-06T15:58:39.225+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 1, + "listId": "91596_AUDITLOGSTESTLIST", + "listType": "CL", + "name": "AUDIT LOGS - TEST LIST", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "green", + "red" + ], + "type": "IP", + "updateDate": "2023-06-06T15:58:39.225+00:00", + "updatedBy": "ccare2", + "version": 1 + }, + { + "createDate": "2023-04-03T15:50:34.074+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 50, + "listId": "89496_AUDITLOGSTESTLIST", + "listType": "CL", + "name": "Testing event logs -4", + "notes": "new Notes - it was", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [], + "type": "IP", + "updateDate": "2023-06-06T15:30:16.430+00:00", + "updatedBy": "ccare2", + "version": 74 + }, + { + "createDate": "2022-05-26T19:18:25.203+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "82957_ANTHONYIPLIST", + "listType": "CL", + "name": "Anthony - IP List", + "notes": "This is another IP client list on May 26", + "productionActivationStatus": "PENDING_ACTIVATION", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "blue", + "green", + "purple", + "red", + "yellow" + ], + "type": "IP", + "updateDate": "2023-06-06T07:02:54.760+00:00", + "updatedBy": "ccare2", + "version": 75 + }, + { + "createDate": "2022-02-23T21:59:22.314+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "81818_IPCLIENTLISTFEB23", + "listType": "CL", + "name": "IpClientListFeb23", + "notes": "This is another IP client list for February 23", + "productionActivationStatus": "PENDING_ACTIVATION", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "FAILED", + "tags": [ + "blue", + "green", + "purple", + "red", + "yellow" + ], + "type": "IP", + "updateDate": "2023-06-06T07:01:37.411+00:00", + "updatedBy": "ccare2", + "version": 93 + }, + { + "createDate": "2022-11-15T15:56:01.681+00:00", + "createdBy": "gbukhmat", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "86124_PROXYTEST", + "listType": "CL", + "name": "Proxy test", + "notes": "Proxy test", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "proxy" + ], + "type": "IP", + "updateDate": "2023-06-06T06:57:02.990+00:00", + "updatedBy": "ccare2", + "version": 325 + }, + { + "createDate": "2023-05-03T09:43:59.337+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "90397_CREATEDUSINGUIAUTOMATION", + "listType": "CL", + "name": "Created using UI automation - GEO client list - o7hid", + "notes": "Notes added using UI automation - o7hid", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "4acbl", + "60f1w", + "b2gx2", + "j002y" + ], + "type": "GEO", + "updateDate": "2023-06-06T06:55:30.428+00:00", + "updatedBy": "ccare2", + "version": 14 + }, + { + "createDate": "2022-11-15T20:18:07.391+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "86139_ANTHONYGEOLISTOPEN", + "listType": "CL", + "name": "AnthonyGeoListOPEN", + "notes": "Geo client list from OPEN for Nov 15", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "blue", + "green", + "purple", + "red", + "yellow" + ], + "type": "GEO", + "updateDate": "2023-06-06T06:51:27.002+00:00", + "updatedBy": "ccare2", + "version": 84 + }, + { + "createDate": "2022-11-15T17:24:18.666+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "86134_ANTHONYGEOLISTOPEN", + "listType": "CL", + "name": "AnthonyGeoListOPEN", + "notes": "This is another Geo client list for Nov 11", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "blue", + "green", + "purple", + "red", + "yellow" + ], + "type": "GEO", + "updateDate": "2023-06-06T06:51:25.100+00:00", + "updatedBy": "ccare2", + "version": 115 + }, + { + "createDate": "2022-11-15T15:24:20.872+00:00", + "createdBy": "gbukhmat", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "86118_PROXYTEST", + "listType": "CL", + "name": "Proxy test", + "notes": "Proxy test", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "proxy" + ], + "type": "IP", + "updateDate": "2023-06-06T06:51:09.034+00:00", + "updatedBy": "ccare2", + "version": 219 + }, + { + "createDate": "2022-01-21T14:20:25.653+00:00", + "createdBy": "ccare2", + "deprecated": false, + "filePrefix": "CL", + "itemsCount": 0, + "listId": "81644_IPCLIENTLISTJAN21", + "listType": "CL", + "name": "IpClientListJan21", + "notes": "This is another IP client list for January 21", + "productionActivationStatus": "INACTIVE", + "readOnly": false, + "shared": false, + "stagingActivationStatus": "INACTIVE", + "tags": [ + "blue", + "green", + "purple", + "red", + "yellow" + ], + "type": "IP", + "updateDate": "2023-06-06T06:33:35.031+00:00", + "updatedBy": "ccare2", + "version": 111 + } + ] +} \ No newline at end of file diff --git a/pkg/providers/clientlists/testData/TestDSClientList/match_all.tf b/pkg/providers/clientlists/testData/TestDSClientList/match_all.tf new file mode 100644 index 000000000..21aa02f6d --- /dev/null +++ b/pkg/providers/clientlists/testData/TestDSClientList/match_all.tf @@ -0,0 +1,5 @@ +provider "akamai" { + edgerc = "../../test/edgerc" +} + +data "akamai_clientlist_lists" "lists" {} diff --git a/pkg/providers/clientlists/testData/TestDSClientList/match_by_filters.tf b/pkg/providers/clientlists/testData/TestDSClientList/match_by_filters.tf new file mode 100644 index 000000000..f4b97bb2c --- /dev/null +++ b/pkg/providers/clientlists/testData/TestDSClientList/match_by_filters.tf @@ -0,0 +1,8 @@ +provider "akamai" { + edgerc = "../../test/edgerc" +} + +data "akamai_clientlist_lists" "lists" { + name = "test" + type = ["IP", "GEO"] +} \ No newline at end of file diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_create.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_create.tf new file mode 100644 index 000000000..b053b473f --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_create.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + list_id = "12_AB" + version = 2 + network = "STAGING" + comments = "Activation Comments" + notification_recipients = ["user@example.com"] + siebel_ticket_id = "ABC-12345" +} diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_missing_param.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_missing_param.tf new file mode 100644 index 000000000..8748f316c --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_missing_param.tf @@ -0,0 +1,7 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + version = 2 + network = "STAGING" + comments = "Activation Comments" + notification_recipients = ["user@example.com"] + siebel_ticket_id = "ABC-12345" +} diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_update.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_update.tf new file mode 100644 index 000000000..f3262f1bc --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_update.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + list_id = "12_AB" + version = 3 + network = "STAGING" + comments = "Activation Comments Updated" + notification_recipients = ["update_user@example.com"] + siebel_ticket_id = "UPDATED-12345" +} diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_update_comments_suppressed.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_update_comments_suppressed.tf new file mode 100644 index 000000000..07014f2d7 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_update_comments_suppressed.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + list_id = "12_AB" + version = 2 + network = "STAGING" + comments = "Activation Comments Updated" + notification_recipients = ["user@example.com"] + siebel_ticket_id = "ABC-12345" +} diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_update_siebelTicketId.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_update_siebelTicketId.tf new file mode 100644 index 000000000..18b128450 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_update_siebelTicketId.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + list_id = "12_AB" + version = 2 + network = "STAGING" + comments = "Activation Comments" + notification_recipients = ["user@example.com"] + siebel_ticket_id = "ABC-12345-UPDATED" +} diff --git a/pkg/providers/clientlists/testData/TestResActivation/activation_update_version_only.tf b/pkg/providers/clientlists/testData/TestResActivation/activation_update_version_only.tf new file mode 100644 index 000000000..bf09e5cf7 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResActivation/activation_update_version_only.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_activation" "activation_ASN_LIST_1" { + list_id = "12_AB" + version = 3 + network = "STAGING" + comments = "Activation Comments" + notification_recipients = ["user@example.com"] + siebel_ticket_id = "ABC-12345" +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_and_duplicate_items_create.tf b/pkg/providers/clientlists/testData/TestResClientList/list_and_duplicate_items_create.tf new file mode 100644 index 000000000..da607f3b8 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_and_duplicate_items_create.tf @@ -0,0 +1,17 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "12" + description = "Item 12 Desc" + tags = ["item12Tag1", "item12Tag2"] + } + items { + value = "12" + } +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create.tf b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create.tf new file mode 100644 index 000000000..b1b33a99f --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create.tf @@ -0,0 +1,27 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "1" + description = "Item 1 Desc" + tags = ["item1Tag1", "item1Tag2"] + } + items { + value = "123" + expiration_date = "2026-12-26T01:00:00+00:00" + } + items { + value = "12" + description = "Item 12 Desc" + tags = ["item12Tag1", "item12Tag2"] + } +} + +output "version" { + value = akamai_clientlist_list.test_list.version +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create_one_item.tf b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create_one_item.tf new file mode 100644 index 000000000..4da2eb579 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_create_one_item.tf @@ -0,0 +1,18 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "1" + description = "Item 1 Desc" + tags = ["item1Tag1", "item1Tag2"] + } +} + +output "version" { + value = akamai_clientlist_list.test_list.version +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_and_items_update.tf b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_update.tf new file mode 100644 index 000000000..c71d124ea --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_and_items_update.tf @@ -0,0 +1,24 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name Updated" + tags = ["a", "c", "d"] + notes = "List Notes Updated" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "1" + description = "Item 1 Desc" + tags = ["item1Tag1", "item1Tag2"] + } + items { + value = "12" + description = "Item 12 Desc Updated" + tags = ["item12Tag1", "item12Tag2"] + } + items { + value = "1234" + description = "Item 1234 Desc" + tags = ["1234Tag"] + } +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_create.tf b/pkg/providers/clientlists/testData/TestResClientList/list_create.tf new file mode 100644 index 000000000..a065cfd17 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_create.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_create_empty_tags.tf b/pkg/providers/clientlists/testData/TestResClientList/list_create_empty_tags.tf new file mode 100644 index 000000000..b63b42623 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_create_empty_tags.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = [] + notes = "List Notes" + type = "IP" + contract_id = "12_ABC" + group_id = 12 +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_items_only_update.tf b/pkg/providers/clientlists/testData/TestResClientList/list_items_only_update.tf new file mode 100644 index 000000000..9731fa2f8 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_items_only_update.tf @@ -0,0 +1,24 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "1" + description = "Item 1 Desc" + tags = ["item1Tag1", "item1Tag2"] + } + items { + value = "12" + description = "Item 12 Desc Updated" + tags = ["item12Tag1", "item12Tag2"] + } + items { + value = "1234" + description = "Item 1234 Desc" + tags = ["1234Tag"] + } +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_items_update_compute_version.tf b/pkg/providers/clientlists/testData/TestResClientList/list_items_update_compute_version.tf new file mode 100644 index 000000000..99051123b --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_items_update_compute_version.tf @@ -0,0 +1,13 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + +} + +output "version" { + value = akamai_clientlist_list.test_list.version +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_items_update_not_compute_version.tf b/pkg/providers/clientlists/testData/TestResClientList/list_items_update_not_compute_version.tf new file mode 100644 index 000000000..04792b598 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_items_update_not_compute_version.tf @@ -0,0 +1,16 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + tags = ["a", "b"] + notes = "List Notes" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 + + items { + value = "1" + } +} + +output "version" { + value = akamai_clientlist_list.test_list.version +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_update.tf b/pkg/providers/clientlists/testData/TestResClientList/list_update.tf new file mode 100644 index 000000000..cf0a11993 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_update.tf @@ -0,0 +1,8 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name Updated" + tags = ["a", "c", "d"] + notes = "List Notes Updated" + type = "ASN" + contract_id = "12_ABC" + group_id = 12 +} diff --git a/pkg/providers/clientlists/testData/TestResClientList/list_update_remove_tags.tf b/pkg/providers/clientlists/testData/TestResClientList/list_update_remove_tags.tf new file mode 100644 index 000000000..5220d6b50 --- /dev/null +++ b/pkg/providers/clientlists/testData/TestResClientList/list_update_remove_tags.tf @@ -0,0 +1,7 @@ +resource "akamai_clientlist_list" "test_list" { + name = "List Name" + notes = "List Notes" + type = "IP" + contract_id = "12_ABC" + group_id = 12 +} diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_api_prioritization_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_api_prioritization_match_rule_test.go index 8ddb3c644..f7091b99a 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_api_prioritization_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_api_prioritization_match_rule_test.go @@ -6,7 +6,8 @@ import ( "strconv" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsAPIPrioritizationMatchRule(t *testing.T) { @@ -44,11 +45,11 @@ func TestDataCloudletsAPIPrioritizationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_api_prioritization_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_api_prioritization_match_rule.test", "match_rules.0.type", "apMatchRule"), resource.TestCheckResourceAttr( @@ -109,7 +110,7 @@ func TestIncorrectDataCloudletsAPIPrioritizationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_api_prioritization_match_rule.test", "match_rules.0.type", "apMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_match_rule_test.go index 18837b716..e57bc0c03 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_match_rule_test.go @@ -4,7 +4,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsLoadBalancerMatchRule(t *testing.T) { @@ -41,11 +42,11 @@ func TestDataCloudletsLoadBalancerMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_application_load_balancer_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_application_load_balancer_match_rule.test", "match_rules.0.type", "albMatchRule"), ), @@ -96,7 +97,7 @@ func TestIncorrectDataCloudletsLoadBalancerMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_application_load_balancer_match_rule.test", "match_rules.0.type", "albMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_test.go index 4cc1c0f40..3cd6fbd19 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_application_load_balancer_test.go @@ -5,8 +5,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -166,7 +167,7 @@ func TestDataApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc(test.checkFunctions...), ExpectError: test.withError, }, diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_audience_segmentation_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_audience_segmentation_match_rule_test.go index 04cc8c1d9..7fb68751f 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_audience_segmentation_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_audience_segmentation_match_rule_test.go @@ -4,7 +4,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsAudienceSegmentationMatchRule(t *testing.T) { @@ -44,11 +45,11 @@ func TestDataCloudletsAudienceSegmentationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_audience_segmentation_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_audience_segmentation_match_rule.test", "match_rules.0.type", "asMatchRule"), ), @@ -107,7 +108,7 @@ func TestIncorrectDataCloudletsAudienceSegmentationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_audience_segmentation_match_rule.test", "match_rules.0.type", "asMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_edge_redirector_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_edge_redirector_match_rule_test.go index 3862c0a87..7bcab99c8 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_edge_redirector_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_edge_redirector_match_rule_test.go @@ -4,7 +4,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsEdgeRedirectorMatchRule(t *testing.T) { @@ -43,11 +44,11 @@ func TestDataCloudletsEdgeRedirectorMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_edge_redirector_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_edge_redirector_match_rule.test", "match_rules.0.type", "erMatchRule"), ), @@ -98,7 +99,7 @@ func TestIncorrectDataCloudletsEdgeRedirectorMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_edge_redirector_match_rule.test", "match_rules.0.type", "erMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_forward_rewrite_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_forward_rewrite_match_rule_test.go index f78c603ce..2093be2bb 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_forward_rewrite_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_forward_rewrite_match_rule_test.go @@ -4,7 +4,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsForwardRewriteMatchRule(t *testing.T) { @@ -37,11 +38,11 @@ func TestDataCloudletsForwardRewriteMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_forward_rewrite_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_forward_rewrite_match_rule.test", "match_rules.0.type", "frMatchRule"), ), @@ -88,7 +89,7 @@ func TestIncorrectDataCloudletsForwardRewriteMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_forward_rewrite_match_rule.test", "match_rules.0.type", "frMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_phased_release_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_phased_release_match_rule_test.go index 89cb92891..2caf34148 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_phased_release_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_phased_release_match_rule_test.go @@ -5,7 +5,8 @@ import ( "strconv" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsPhasedReleaseMatchRule(t *testing.T) { @@ -43,11 +44,11 @@ func TestDataCloudletsPhasedReleaseMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_phased_release_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_phased_release_match_rule.test", "match_rules.0.type", "cdMatchRule"), resource.TestCheckResourceAttr( @@ -100,7 +101,7 @@ func TestIncorrectDataPhasedReleaseDeploymentMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_phased_release_match_rule.test", "match_rules.0.type", "cdMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_policy_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_policy_test.go index 10c5d7f79..1fdb70498 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_policy_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_policy_test.go @@ -6,9 +6,10 @@ import ( "github.com/stretchr/testify/mock" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDataCloudletsPolicy(t *testing.T) { @@ -76,7 +77,7 @@ func TestDataCloudletsPolicy(t *testing.T) { resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "api_version", "2.0"), resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "revision_id", "4824132"), resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "rules_locked", "false"), - resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "match_rules", loadFixtureString("testdata/TestDataCloudletsPolicy/rules/match_rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "match_rules", testutils.LoadFixtureString(t, "testdata/TestDataCloudletsPolicy/rules/match_rules_out.json")), resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "match_rule_format", "1.0"), resource.TestCheckResourceAttr("data.akamai_cloudlets_policy.test", "warnings", "null"), }, @@ -250,7 +251,7 @@ func TestDataCloudletsPolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( test.checkFuncs..., ), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_request_control_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_request_control_match_rule_test.go index c57304de0..6aa8b188a 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_request_control_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_request_control_match_rule_test.go @@ -4,7 +4,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsRequestControlMatchRule(t *testing.T) { @@ -40,11 +41,11 @@ func TestDataCloudletsRequestControlMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_request_control_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_request_control_match_rule.test", "match_rules.0.type", "igMatchRule"), ), @@ -103,7 +104,7 @@ func TestIncorrectDataCloudletsRequestControlMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_request_control_match_rule.test", "match_rules.0.type", "igMatchRule"), diff --git a/pkg/providers/cloudlets/data_akamai_cloudlets_visitor_prioritization_match_rule_test.go b/pkg/providers/cloudlets/data_akamai_cloudlets_visitor_prioritization_match_rule_test.go index 418d937ce..b4d03dc6f 100644 --- a/pkg/providers/cloudlets/data_akamai_cloudlets_visitor_prioritization_match_rule_test.go +++ b/pkg/providers/cloudlets/data_akamai_cloudlets_visitor_prioritization_match_rule_test.go @@ -6,7 +6,8 @@ import ( "strconv" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataCloudletsVisitorPrioritizationMatchRule(t *testing.T) { @@ -44,11 +45,11 @@ func TestDataCloudletsVisitorPrioritizationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_visitor_prioritization_match_rule.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_cloudlets_visitor_prioritization_match_rule.test", "match_rules.0.type", "vpMatchRule"), resource.TestCheckResourceAttr( @@ -106,7 +107,7 @@ func TestIncorrectDataCloudletsVisitorPrioritizationMatchRule(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_cloudlets_visitor_prioritization_match_rule.test", "match_rules.0.type", "vpMatchRule"), diff --git a/pkg/providers/cloudlets/provider_test.go b/pkg/providers/cloudlets/provider_test.go index 0466a7939..b96be1de6 100644 --- a/pkg/providers/cloudlets/provider_test.go +++ b/pkg/providers/cloudlets/provider_test.go @@ -1,8 +1,6 @@ package cloudlets import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -52,17 +50,3 @@ func useClient(client cloudlets.Cloudlets, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_activation_test.go b/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_activation_test.go index 4e08c4e0a..e0cb29a11 100644 --- a/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_activation_test.go +++ b/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_activation_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -34,14 +35,14 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -66,14 +67,14 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -126,14 +127,14 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -149,7 +150,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), ExpectError: regexp.MustCompile("application load balancer activation create: application load balancer activation failed. No changes were written to server:\nan error"), }, }, @@ -164,7 +165,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), ExpectError: regexp.MustCompile("application load balancer activation create: error while waiting until load balancer activation status == 'active':\nan error"), }, }, @@ -179,7 +180,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -199,7 +200,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), ExpectError: regexp.MustCompile("application load balancer activation read: an error"), }, }, @@ -222,7 +223,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -230,7 +231,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -260,7 +261,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -268,7 +269,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -303,7 +304,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -311,7 +312,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "2"), @@ -347,7 +348,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "id", "org_1:STAGING"), @@ -356,7 +357,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update_prod.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update_prod.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "id", "org_1:PRODUCTION"), @@ -389,7 +390,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -397,7 +398,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), ExpectError: regexp.MustCompile("application load balancer activation update: error while waiting until load balancer activation status == 'active':\nan error"), }, }, @@ -423,7 +424,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_application_load_balancer_activation.test", "version", "1"), @@ -431,7 +432,7 @@ func TestResourceCloudletsApplicationLoadBalancerActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceCloudletsApplicationLoadBalancerActivation/alb_activation_update.tf"), ExpectError: regexp.MustCompile("application load balancer activation update: application load balancer activation failed. No changes were written to server:\nan error"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.LoadBalancerActivationStatusActive)), diff --git a/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_test.go b/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_test.go index 5205f8be2..95aec538d 100644 --- a/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_test.go +++ b/pkg/providers/cloudlets/resource_akamai_cloudlets_application_load_balancer_test.go @@ -6,9 +6,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/jinzhu/copier" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -213,7 +214,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -222,7 +223,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "2", @@ -253,7 +254,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -262,7 +263,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -293,7 +294,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -302,7 +303,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -333,7 +334,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -342,7 +343,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -380,7 +381,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -389,7 +390,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -425,7 +426,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), ExpectError: regexp.MustCompile("creating origin"), }, }, @@ -491,7 +492,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), ExpectError: regexp.MustCompile("creating version"), }, }, @@ -517,7 +518,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "1", @@ -526,7 +527,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), Check: checkAttributes(loadBalancerAttributes{ originID: "test_origin", version: "2", @@ -557,7 +558,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), ExpectError: regexp.MustCompile("fetching version"), }, }, @@ -581,7 +582,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), }, { ImportState: true, @@ -610,7 +611,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), }, { ImportState: true, @@ -637,7 +638,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), }, { ImportState: true, @@ -668,7 +669,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), }, { ImportState: true, @@ -702,7 +703,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), ExpectError: regexp.MustCompile("'liveness_hosts' field should be omitted for GTM hostname: \"test-hostname\". " + "Liveness tests for this host can be configured in DNS traffic management"), }, @@ -736,10 +737,10 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), }, { - Config: loadFixtureString(fmt.Sprintf("%s/alb_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_update.tf", testDir)), ExpectError: regexp.MustCompile("'liveness_hosts' field should be omitted for GTM hostname: \"test-hostname\". " + "Liveness tests for this host can be configured in DNS traffic management"), }, @@ -758,7 +759,7 @@ func TestResourceApplicationLoadBalancer(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/alb_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/alb_create.tf", testDir)), ExpectError: regexp.MustCompile("the total data center percentage must be 100%: total=10.012%"), }, }, diff --git a/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_activation_test.go b/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_activation_test.go index 3c6a4b934..299fe45e4 100644 --- a/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_activation_test.go +++ b/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_activation_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -22,7 +23,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile(`policy activation: cannot find the given policy version \(1\): an error`), }, }, @@ -35,7 +36,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -69,7 +70,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -104,7 +105,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -141,7 +142,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -178,7 +179,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: policy activation: policyID 1234"), }, }, @@ -200,7 +201,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: policy activation: policyID 1234"), }, }, @@ -229,7 +230,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -265,7 +266,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile(`policy activation read: cannot find any activation for the given policy \(1234\) and network \('staging'\)`), }, }, @@ -278,7 +279,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_production.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_production.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -295,7 +296,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_prod.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_prod.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -315,7 +316,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: an error"), }, }, @@ -334,7 +335,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: an error"), }, }, @@ -358,7 +359,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -382,7 +383,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation read: an error"), }, }, @@ -409,7 +410,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -417,7 +418,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -436,7 +437,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: activation failed"), }, }, @@ -451,7 +452,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), ExpectError: regexp.MustCompile("policy activation create: activation failed"), }, }, @@ -471,7 +472,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -479,7 +480,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile(`policy activation: cannot find the given policy version \(2\): an error`), }, }, @@ -499,7 +500,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -507,7 +508,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -542,7 +543,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -550,7 +551,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "2"), @@ -581,7 +582,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -589,7 +590,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_prod.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1_prod.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -614,7 +615,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -622,7 +623,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile("policy activation update: an error"), }, }, @@ -645,7 +646,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -653,7 +654,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile("policy activation update: an error"), }, }, @@ -678,7 +679,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -686,7 +687,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile("policy activation: cannot remove policy 1234 property 20 and network 'staging'. Please, try once again later.\nan error"), }, }, @@ -709,7 +710,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -717,7 +718,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile("policy activation: cannot find policy 1234 properties: an error"), }, }, @@ -742,7 +743,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -750,7 +751,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile("policy activation update: an error"), }, }, @@ -779,7 +780,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_version1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckOutput("status", string(cloudlets.PolicyActivationStatusActive)), resource.TestCheckResourceAttr("akamai_cloudlets_policy_activation.test", "version", "1"), @@ -787,7 +788,7 @@ func TestResourceCloudletsPolicyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResCloudletsPolicyActivation/policy_activation_update_version2.tf"), ExpectError: regexp.MustCompile(`policy activation read: cannot find any activation for the given policy \(1234\) and network \('staging'\)`), }, }, diff --git a/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_test.go b/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_test.go index 32ffa5c12..524e83efa 100644 --- a/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_test.go +++ b/pkg/providers/cloudlets/resource_akamai_cloudlets_policy_test.go @@ -7,9 +7,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudlets" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/jinzhu/copier" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -186,7 +187,7 @@ func TestResourcePolicy(t *testing.T) { checkPolicyAttributes = func(attrs policyAttributes) resource.TestCheckFunc { var matchRulesPath string if attrs.matchRulesPath != "" { - matchRulesPath = loadFixtureString(attrs.matchRulesPath) + matchRulesPath = testutils.LoadFixtureString(t, attrs.matchRulesPath) } return resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cloudlets_policy.policy", "id", "2"), @@ -245,7 +246,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -253,7 +254,7 @@ func TestResourcePolicy(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy_updated", version: "2", @@ -306,7 +307,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -362,7 +363,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -370,7 +371,7 @@ func TestResourcePolicy(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy_updated", version: "1", @@ -425,7 +426,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -433,7 +434,7 @@ func TestResourcePolicy(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy_updated", version: "1", @@ -488,7 +489,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -496,7 +497,7 @@ func TestResourcePolicy(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -559,15 +560,15 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkWarnings, }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkWarnings, }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkWarnings, }, }, @@ -618,7 +619,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -626,7 +627,7 @@ func TestResourcePolicy(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -651,7 +652,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ name: "test_policy", version: "1", @@ -679,7 +680,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("oops"), }, }, @@ -774,7 +775,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: testCases[i].ExpectedError, }, }, @@ -796,7 +797,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("oops"), }, }, @@ -821,7 +822,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("oops"), }, }, @@ -877,10 +878,10 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), ExpectError: regexp.MustCompile("oops"), }, }, @@ -968,10 +969,10 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), ExpectError: testCases[i].ExpectedError, }, }, @@ -990,7 +991,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("invalid group_id provided"), }, }, @@ -1041,7 +1042,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -1071,7 +1072,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -1099,7 +1100,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -1126,7 +1127,7 @@ func TestResourcePolicy(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -1178,8 +1179,8 @@ func TestDiffSuppressMatchRules(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - oldJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.oldPath)) - newJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.newPath)) + oldJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.oldPath)) + newJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.newPath)) res := diffSuppressMatchRules("", oldJSON, newJSON, nil) assert.Equal(t, test.expected, res) }) diff --git a/pkg/providers/cloudwrapper/cloudwrapper.go b/pkg/providers/cloudwrapper/cloudwrapper.go new file mode 100644 index 000000000..b12e1a328 --- /dev/null +++ b/pkg/providers/cloudwrapper/cloudwrapper.go @@ -0,0 +1,7 @@ +package cloudwrapper + +import "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/registry" + +func init() { + registry.RegisterFrameworkSubprovider(NewSubprovider()) +} diff --git a/pkg/providers/cloudwrapper/cloudwrapper_errors.go b/pkg/providers/cloudwrapper/cloudwrapper_errors.go new file mode 100644 index 000000000..ea4b9cdc6 --- /dev/null +++ b/pkg/providers/cloudwrapper/cloudwrapper_errors.go @@ -0,0 +1,8 @@ +package cloudwrapper + +import "errors" + +var ( + // ErrCloudWrapperLocation is returned when operation on cloudwrapper location fails + ErrCloudWrapperLocation = errors.New("cloudwrapper location") +) diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities.go new file mode 100644 index 000000000..bd0de50aa --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities.go @@ -0,0 +1,214 @@ +package cloudwrapper + +import ( + "context" + "fmt" + "strings" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/collections" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +type capacitiesDataSourceModel struct { + ID types.String `tfsdk:"id"` + ContractIDs types.List `tfsdk:"contract_ids"` + Capacities []locationCapacityModel `tfsdk:"capacities"` +} + +func (m capacitiesDataSourceModel) getContractIDs(ctx context.Context) ([]string, diag.Diagnostics) { + var contracts []string + diags := m.ContractIDs.ElementsAs(ctx, &contracts, false) + if diags.HasError() { + return nil, diags + } + + collections.ForEachInSlice(contracts, func(s string) string { + return strings.TrimPrefix(s, "ctr_") + }) + + return contracts, nil +} + +type locationCapacityModel struct { + LocationID types.Int64 `tfsdk:"location_id"` + LocationName types.String `tfsdk:"location_name"` + ContractID types.String `tfsdk:"contract_id"` + Type types.String `tfsdk:"type"` + ApprovedCapacity capacityModel `tfsdk:"approved"` + AssignedCapacity capacityModel `tfsdk:"assigned"` + UnassignedCapacity capacityModel `tfsdk:"unassigned"` +} + +type capacityModel struct { + Value types.Int64 `tfsdk:"value"` + Unit types.String `tfsdk:"unit"` +} + +func newLocationCapacityModel(capacity cloudwrapper.LocationCapacity) locationCapacityModel { + return locationCapacityModel{ + LocationID: types.Int64Value(int64(capacity.LocationID)), + LocationName: types.StringValue(capacity.LocationName), + ContractID: types.StringValue(capacity.ContractID), + Type: types.StringValue(string(capacity.Type)), + ApprovedCapacity: newCapacityModel(capacity.ApprovedCapacity), + AssignedCapacity: newCapacityModel(capacity.AssignedCapacity), + UnassignedCapacity: newCapacityModel(capacity.UnassignedCapacity), + } +} + +func newCapacityModel(capacity cloudwrapper.Capacity) capacityModel { + return capacityModel{ + Value: types.Int64Value(int64(capacity.Value)), + Unit: types.StringValue(string(capacity.Unit)), + } +} + +var ( + _ datasource.DataSource = &capacitiesDataSource{} + _ datasource.DataSourceWithConfigure = &capacitiesDataSource{} +) + +type capacitiesDataSource struct { + client cloudwrapper.CloudWrapper +} + +// NewCapacitiesDataSource returns a new capacity data source +func NewCapacitiesDataSource() datasource.DataSource { + return &capacitiesDataSource{} +} + +func (d *capacitiesDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source's meta information +func (d *capacitiesDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = d.name() +} + +func (d *capacitiesDataSource) name() string { + return "akamai_cloudwrapper_capacities" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *capacitiesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source's terraform schema +func (d *capacitiesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + capacityAttributes := map[string]attr.Type{ + "value": types.Int64Type, + "unit": types.StringType, + } + + resp.Schema = schema.Schema{ + Description: "CloudWrapper capacities", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_capacities`.", + Description: "ID of the data source.", + }, + "contract_ids": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "List of contract IDs with Cloud Wrapper entitlement.", + }, + }, + Blocks: map[string]schema.Block{ + "capacities": schema.ListNestedBlock{ + Description: "List of all location capacities.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "location_id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier of the configured location.", + }, + "location_name": schema.StringAttribute{ + Computed: true, + Description: "Name of the location.", + }, + "contract_id": schema.StringAttribute{ + Computed: true, + Description: "Contract ID having Cloud Wrapper entitlement.", + }, + "type": schema.StringAttribute{ + Computed: true, + Description: "The type of property this capacity is related to.", + }, + "approved": schema.ObjectAttribute{ + Computed: true, + Description: "Capacity allocated for the location.", + AttributeTypes: capacityAttributes, + }, + "assigned": schema.ObjectAttribute{ + Computed: true, + Description: "Capacity already assigned to Cloud Wrapper configurations.", + AttributeTypes: capacityAttributes, + }, + "unassigned": schema.ObjectAttribute{ + Computed: true, + Description: "Capacity value that can be assigned to Cloud Wrapper configurations.", + AttributeTypes: capacityAttributes, + }, + }, + }, + }, + }, + } +} + +// Read is called when the provider must read data source values in order to update state +func (d *capacitiesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Capacities DataSource Read") + + var data capacitiesDataSourceModel + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + contractIDs, diags := data.getContractIDs(ctx) + if diags.HasError() { + resp.Diagnostics.Append(diags...) + return + } + + listCapacitiesResponse, err := d.client.ListCapacities(ctx, cloudwrapper.ListCapacitiesRequest{ + ContractIDs: contractIDs, + }) + if err != nil { + resp.Diagnostics.AddError("Reading CloudWrapper Capacities Failed", err.Error()) + return + } + + for _, capacity := range listCapacitiesResponse.Capacities { + data.Capacities = append(data.Capacities, newLocationCapacityModel(capacity)) + } + + data.ID = types.StringValue(d.name()) + resp.Diagnostics.Append(resp.State.Set(ctx, data)...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities_test.go new file mode 100644 index 000000000..7d133af66 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_capacities_test.go @@ -0,0 +1,241 @@ +package cloudwrapper + +import ( + "context" + "fmt" + "regexp" + "strconv" + "strings" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +func TestCapacitiesDataSource(t *testing.T) { + t.Parallel() + + contractIDs := []string{"ctr_123", "345"} + contractIDsTrimmed := []string{"123", "345"} + request := cloudwrapper.ListCapacitiesRequest{ + ContractIDs: contractIDsTrimmed, + } + + testCases := map[string]struct { + respData []cloudwrapper.LocationCapacity + init func(*testing.T, *cloudwrapper.Mock, []cloudwrapper.LocationCapacity) + expectedError *regexp.Regexp + }{ + "listing capacities successful": { + respData: []cloudwrapper.LocationCapacity{ + { + LocationID: 1, + LocationName: "US West", + Type: cloudwrapper.CapacityTypeMedia, + ContractID: "ctr_123", + ApprovedCapacity: cloudwrapper.Capacity{ + Value: 2000, + Unit: cloudwrapper.UnitGB, + }, + UnassignedCapacity: cloudwrapper.Capacity{ + Value: 2000, + Unit: cloudwrapper.UnitGB, + }, + AssignedCapacity: cloudwrapper.Capacity{ + Value: 0, + Unit: cloudwrapper.UnitGB, + }, + }, + { + LocationID: 2, + LocationName: "US East", + Type: cloudwrapper.CapacityTypeMedia, + ContractID: "ctr_345", + ApprovedCapacity: cloudwrapper.Capacity{ + Value: 4000, + Unit: cloudwrapper.UnitGB, + }, + UnassignedCapacity: cloudwrapper.Capacity{ + Value: 2000, + Unit: cloudwrapper.UnitGB, + }, + AssignedCapacity: cloudwrapper.Capacity{ + Value: 2000, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + init: func(t *testing.T, m *cloudwrapper.Mock, capacities []cloudwrapper.LocationCapacity) { + resp := cloudwrapper.ListCapacitiesResponse{ + Capacities: capacities, + } + m.On("ListCapacities", mock.Anything, request).Return(&resp, nil).Times(5) + }, + }, + "no capacities found": { + respData: []cloudwrapper.LocationCapacity{}, + init: func(t *testing.T, m *cloudwrapper.Mock, capacities []cloudwrapper.LocationCapacity) { + resp := cloudwrapper.ListCapacitiesResponse{ + Capacities: capacities, + } + m.On("ListCapacities", mock.Anything, request).Return(&resp, nil).Times(5) + }, + }, + "listing capacities failed": { + init: func(t *testing.T, m *cloudwrapper.Mock, _ []cloudwrapper.LocationCapacity) { + err := fmt.Errorf("listing capacities failed") + m.On("ListCapacities", mock.Anything, request).Return(nil, err).Once() + }, + expectedError: regexp.MustCompile("listing capacities failed"), + }, + } + + for name, tc := range testCases { + name, tc := name, tc + t.Run(name, func(t *testing.T) { + t.Parallel() + + client := &cloudwrapper.Mock{} + if tc.init != nil { + tc.init(t, client, tc.respData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: dataCloudWrapperCapacityConfig(contractIDs), + Check: checkDataCloudWrapperCapacityAttrs(contractIDs, tc.respData), + ExpectError: tc.expectedError, + }, + }, + }) + client.AssertExpectations(t) + }) + } +} + +func checkDataCloudWrapperCapacityAttrs(contractIDs []string, capacities []cloudwrapper.LocationCapacity) resource.TestCheckFunc { + name := "data.akamai_cloudwrapper_capacities.test" + var checkFuncs []resource.TestCheckFunc + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(name, "contract_ids.#", strconv.Itoa(len(contractIDs)))) + for i, ctr := range contractIDs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(name, fmt.Sprintf("contract_ids.%d", i), ctr)) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(name, "capacities.#", strconv.Itoa(len(capacities)))) + for i, cap := range capacities { + checkFuncs = append(checkFuncs, + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.location_id", i), strconv.Itoa(cap.LocationID)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.location_name", i), cap.LocationName), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.contract_id", i), cap.ContractID), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.type", i), string(cap.Type)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.approved.value", i), strconv.FormatInt(cap.ApprovedCapacity.Value, 10)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.approved.unit", i), string(cap.ApprovedCapacity.Unit)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.assigned.value", i), strconv.FormatInt(cap.AssignedCapacity.Value, 10)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.assigned.unit", i), string(cap.AssignedCapacity.Unit)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.unassigned.value", i), strconv.FormatInt(cap.UnassignedCapacity.Value, 10)), + resource.TestCheckResourceAttr(name, fmt.Sprintf("capacities.%d.unassigned.unit", i), string(cap.UnassignedCapacity.Unit)), + ) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttrSet(name, "id")) + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} + +func dataCloudWrapperCapacityConfig(contracts []string) string { + var contractIDs string + if len(contracts) > 0 { + contractIDs = fmt.Sprintf(`"%s"`, strings.Join(contracts, `", "`)) + } + + return fmt.Sprintf(` +data "akamai_cloudwrapper_capacities" "test" { + contract_ids = [%s] +}`, contractIDs) +} + +func TestCapacitiesDataSourceModel_getContractIDs(t *testing.T) { + t.Parallel() + + newCapacitiesDataSourceModelWithContractIDs := func(t *testing.T, ctrIDs []string) capacitiesDataSourceModel { + t.Helper() + + ctrList, diags := types.ListValueFrom(context.Background(), types.StringType, ctrIDs) + require.False(t, diags.HasError(), "converting []string to types.List failed with: %s", diags) + + return capacitiesDataSourceModel{ + ContractIDs: ctrList, + } + } + + testCases := map[string]struct { + createModel func(*testing.T) capacitiesDataSourceModel + want []string + withError bool + }{ + "returns all contract IDs": { + createModel: func(t *testing.T) capacitiesDataSourceModel { + contractIDs := []string{"123", "345", "567"} + return newCapacitiesDataSourceModelWithContractIDs(t, contractIDs) + }, + want: []string{"123", "345", "567"}, + }, + "trims 'ctr_' prefix": { + createModel: func(t *testing.T) capacitiesDataSourceModel { + contractIDs := []string{"ctr_123", "345", "ctr_567"} + return newCapacitiesDataSourceModelWithContractIDs(t, contractIDs) + }, + want: []string{"123", "345", "567"}, + }, + "returns empty slice when contract IDs empty": { + createModel: func(t *testing.T) capacitiesDataSourceModel { + return newCapacitiesDataSourceModelWithContractIDs(t, []string{}) + }, + want: []string{}, + }, + "returns nil when contract IDs are nil": { + createModel: func(t *testing.T) capacitiesDataSourceModel { + return newCapacitiesDataSourceModelWithContractIDs(t, nil) + }, + want: nil, + }, + "fails when contractIDs are of wrong type": { + createModel: func(t *testing.T) capacitiesDataSourceModel { + contractIDs := []int{123, 345, 567} + ctrList, diags := types.ListValueFrom(context.Background(), types.Int64Type, contractIDs) + require.False(t, diags.HasError(), "converting []int to types.List failed with: %s", diags) + + return capacitiesDataSourceModel{ + ContractIDs: ctrList, + } + }, + withError: true, + }, + } + + for name, tc := range testCases { + name, tc := name, tc + + t.Run(name, func(t *testing.T) { + t.Parallel() + + model := tc.createModel(t) + + got, diags := model.getContractIDs(context.Background()) + if tc.withError { + assert.True(t, diags.HasError(), "diag.Diagnostics does not contain error") + return + } + + require.False(t, diags.HasError(), "returned diag.Diagnostics contain error") + assert.Equal(t, tc.want, got) + }) + } +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration.go new file mode 100644 index 000000000..4a4a34a74 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration.go @@ -0,0 +1,521 @@ +package cloudwrapper + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ datasource.DataSource = &configurationDataSource{} + _ datasource.DataSourceWithConfigure = &configurationDataSource{} + + configBlock = map[string]schema.Block{ + "multi_cdn_settings": schema.SingleNestedBlock{ + Description: "Specify details about the Multi CDN settings.", + Attributes: map[string]schema.Attribute{ + "enable_soft_alerts": schema.BoolAttribute{ + Computed: true, + Description: "Option to opt out of alerts based on soft limits of bandwidth usage.", + }, + }, + Blocks: map[string]schema.Block{ + "bocc": schema.SingleNestedBlock{ + Description: "Specify diagnostic data beacons details.", + Attributes: map[string]schema.Attribute{ + "conditional_sampling_frequency": schema.StringAttribute{ + Computed: true, + Description: "The sampling frequency of requests and forwards for EDGE, MIDGRESS, and ORIGIN beacons.", + }, + "enabled": schema.BoolAttribute{ + Computed: true, + Description: "Enable diagnostic data beacons for consumption by the Broadcast Operations Control Center.", + }, + "forward_type": schema.StringAttribute{ + Computed: true, + Description: "Select whether to beacon diagnostics data for internal ORIGIN_ONLY, MIDGRESS_ONLY, or both ORIGIN_AND_MIDGRESS forwards.", + }, + "request_type": schema.StringAttribute{ + Computed: true, + Description: "Select whether to beacon diagnostics data for EDGE_ONLY or EDGE_AND_MIDGRESS requests.", + }, + "sampling_frequency": schema.StringAttribute{ + Computed: true, + Description: "The sampling frequency of requests and forwards for EDGE, MIDGRESS, and ORIGIN beacons.", + }, + }, + }, + "cdns": schema.SetNestedBlock{ + Description: "List of CDN added for the configuration.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "cdn_code": schema.StringAttribute{ + Computed: true, + Description: "Unique identifier for the CDN.", + }, + "enabled": schema.BoolAttribute{ + Computed: true, + Description: "Enable CDN.", + }, + "https_only": schema.BoolAttribute{ + Computed: true, + Description: "Specify whether CDN communication is HTTPS only.", + }, + "ip_acl_cidrs": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "Configure an access control list using IP addresses in CIDR notation.", + }, + }, + Blocks: map[string]schema.Block{ + "cdn_auth_keys": schema.SetNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "auth_key_name": schema.StringAttribute{ + Computed: true, + Description: "The name of the auth key.", + }, + "expiry_date": schema.StringAttribute{ + Computed: true, + Description: "The expirty date of an auth key.", + }, + "header_name": schema.StringAttribute{ + Computed: true, + Description: "The header name of an auth key.", + }, + "secret": schema.StringAttribute{ + Computed: true, + Description: "The secret of an auth key.", + }, + }, + }, + Description: "List of auth keys configured for the CDN.", + }, + }, + }, + }, + "data_streams": schema.SingleNestedBlock{ + Description: "Specifies data streams details.", + Attributes: map[string]schema.Attribute{ + "data_stream_ids": schema.SetAttribute{ + ElementType: types.Int64Type, + Computed: true, + Description: "Unique identifiers of the Data Streams.", + }, + "enabled": schema.BoolAttribute{ + Computed: true, + Description: "Enables DataStream reporting.", + }, + "sampling_rate": schema.Int64Attribute{ + Computed: true, + Description: "Specifies the percentage of log data you want to collect for this configuration.", + }, + }, + }, + "origins": schema.SetNestedBlock{ + Description: "List of origins corresponding to the properties selected in the configuration.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "hostname": schema.StringAttribute{ + Computed: true, + Description: "Origins hostname corresponding to the Akamai Delivery Property.", + }, + "origin_id": schema.StringAttribute{ + Computed: true, + Description: "Origin identifier and will be used to generated Multi CDN host names.", + }, + "property_id": schema.Int64Attribute{ + Computed: true, + Description: "Property ID of the property that origin belongs to.", + }, + }, + }, + }, + }, + }, + "locations": schema.SetNestedBlock{ + Description: "List of all unused properties.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "comments": schema.StringAttribute{ + Computed: true, + Description: "Additional comments provided by user.", + }, + "traffic_type_id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier for the location and traffic type combination.", + }, + "map_name": schema.StringAttribute{ + Computed: true, + Description: "The name of the map.", + }, + "capacity": schema.ObjectAttribute{ + AttributeTypes: map[string]attr.Type{ + "unit": types.StringType, + "value": types.Int64Type, + }, + Computed: true, + Description: "The capacity assigned to this configuration's location.", + }, + }, + }, + }, + } +) + +type ( + configurationDataSource struct { + client cloudwrapper.CloudWrapper + } + + configurationDataSourceModel struct { + ID types.Int64 `tfsdk:"id"` + CapacityAlertsThreshold types.Int64 `tfsdk:"capacity_alerts_threshold"` + Comments types.String `tfsdk:"comments"` + ConfigName types.String `tfsdk:"config_name"` + ContractID types.String `tfsdk:"contract_id"` + LastActivatedBy types.String `tfsdk:"last_activated_by"` + LastActivatedDate types.String `tfsdk:"last_activated_date"` + LastUpdatedBy types.String `tfsdk:"last_updated_by"` + LastUpdatedDate types.String `tfsdk:"last_updated_date"` + Locations []configurationLocationModel `tfsdk:"locations"` + MultiCDNSettings *multiCDNSettingsModel `tfsdk:"multi_cdn_settings"` + NotificationEmails types.Set `tfsdk:"notification_emails"` + PropertyIDs types.Set `tfsdk:"property_ids"` + RetainIdleObjects types.Bool `tfsdk:"retain_idle_objects"` + Status types.String `tfsdk:"status"` + } + + configurationLocationModel struct { + Capacity capacityModel `tfsdk:"capacity"` + Comments types.String `tfsdk:"comments"` + TrafficTypeID types.Int64 `tfsdk:"traffic_type_id"` + MapName types.String `tfsdk:"map_name"` + } + + boccModel struct { + ConditionalSamplingFrequency types.String `tfsdk:"conditional_sampling_frequency"` + Enabled types.Bool `tfsdk:"enabled"` + ForwardType types.String `tfsdk:"forward_type"` + RequestType types.String `tfsdk:"request_type"` + SamplingFrequency types.String `tfsdk:"sampling_frequency"` + } + + cdnsModel struct { + CDNAuthKeys []cdnAuthKeyModel `tfsdk:"cdn_auth_keys"` + CDNCode types.String `tfsdk:"cdn_code"` + Enabled types.Bool `tfsdk:"enabled"` + HTTPSOnly types.Bool `tfsdk:"https_only"` + IPACLCIDRs types.Set `tfsdk:"ip_acl_cidrs"` + } + + cdnAuthKeyModel struct { + AuthKeyName types.String `tfsdk:"auth_key_name"` + ExpiryDate types.String `tfsdk:"expiry_date"` + HeaderName types.String `tfsdk:"header_name"` + Secret types.String `tfsdk:"secret"` + } + + dataStreamsModel struct { + DataStreamsIDs types.Set `tfsdk:"data_stream_ids"` + Enabled types.Bool `tfsdk:"enabled"` + SamplingRate types.Int64 `tfsdk:"sampling_rate"` + } + + originModel struct { + Hostname types.String `tfsdk:"hostname"` + OriginID types.String `tfsdk:"origin_id"` + PropertyID types.Int64 `tfsdk:"property_id"` + } + + multiCDNSettingsModel struct { + EnableSoftAlerts types.Bool `tfsdk:"enable_soft_alerts"` + BOCC boccModel `tfsdk:"bocc"` + CDNs []cdnsModel `tfsdk:"cdns"` + DataStreams dataStreamsModel `tfsdk:"data_streams"` + Origins []originModel `tfsdk:"origins"` + } +) + +// NewConfigurationDataSource returns a new configuration data source +func NewConfigurationDataSource() datasource.DataSource { + return &configurationDataSource{} +} + +func (d *configurationDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source's meta information +func (d *configurationDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_configuration" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *configurationDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + // ProviderData is nil when Configure is run first time as part of ValidateDataSourceConfig in framework provider + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source's terraform schema +func (d *configurationDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "CloudWrapper configuration", + Attributes: map[string]schema.Attribute{ + "id": schema.Int64Attribute{ + Required: true, + Description: "Unique identifier of a Cloud Wrapper configuration.", + }, + "capacity_alerts_threshold": schema.Int64Attribute{ + Computed: true, + Description: "Represents the threshold for sending alerts.", + }, + "comments": schema.StringAttribute{ + Computed: true, + Description: "Additional information provided by user which can help to differentiate or track changes of the configuration.", + }, + "config_name": schema.StringAttribute{ + Computed: true, + Description: "Name of the configuration.", + }, + "contract_id": schema.StringAttribute{ + Computed: true, + Description: "Contract ID with Cloud Wrapper entitlement.", + }, + "last_activated_by": schema.StringAttribute{ + Computed: true, + Description: "User to last activate the configuration.", + }, + "last_activated_date": schema.StringAttribute{ + Computed: true, + Description: "ISO format date that represents when the configuration was last activated successfully.", + }, + "last_updated_by": schema.StringAttribute{ + Computed: true, + Description: "User to last modify the configuration.", + }, + "last_updated_date": schema.StringAttribute{ + Computed: true, + Description: "ISO format date that represents when the configuration was last edited.", + }, + "notification_emails": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "Email addresses to receive notifications.", + }, + "property_ids": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "List of properties belonging to media delivery products. Properties need to be unique across configurations.", + }, + "retain_idle_objects": schema.BoolAttribute{ + Computed: true, + Description: "Retain idle objects beyond their max idle lifetime.", + }, + "status": schema.StringAttribute{ + Computed: true, + Description: "Current state of the provisioning of the configuration, either SAVED, IN_PROGRESS, ACTIVE, DELETE_IN_PROGRESS, or FAILED.", + }, + }, + Blocks: configBlock, + } +} + +// Read is called when the provider must read data source values in order to update state +func (d *configurationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Configuration DataSource Read") + + var data configurationDataSourceModel + if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() { + return + } + + cfg, err := d.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ + ConfigID: data.ID.ValueInt64(), + }) + if err != nil { + resp.Diagnostics.AddError("Reading CloudWrapper Configuration", err.Error()) + return + } + + if resp.Diagnostics.Append(data.populate(ctx, cfg)...); resp.Diagnostics.HasError() { + return + } + + if resp.Diagnostics.Append(resp.State.Set(ctx, &data)...); resp.Diagnostics.HasError() { + return + } +} + +func (m *configurationDataSourceModel) populate(ctx context.Context, cfg *cloudwrapper.Configuration) diag.Diagnostics { + var diags diag.Diagnostics + + m.ContractID = types.StringValue(cfg.ContractID) + m.ConfigName = types.StringValue(cfg.ConfigName) + m.Comments = types.StringValue(cfg.Comments) + m.RetainIdleObjects = types.BoolValue(cfg.RetainIdleObjects) + m.LastUpdatedBy = types.StringValue(cfg.LastUpdatedBy) + m.LastUpdatedDate = types.StringValue(cfg.LastUpdatedDate) + m.Status = types.StringValue(string(cfg.Status)) + m.setLocations(cfg.Locations) + + if cfg.CapacityAlertsThreshold == nil { + m.CapacityAlertsThreshold = types.Int64Null() + } else { + m.CapacityAlertsThreshold = types.Int64Value(int64(*cfg.CapacityAlertsThreshold)) + } + if cfg.LastActivatedBy == nil { + m.LastActivatedBy = types.StringNull() + } else { + m.LastActivatedBy = types.StringValue(*cfg.LastActivatedBy) + } + if cfg.LastActivatedDate == nil { + m.LastActivatedDate = types.StringNull() + } else { + m.LastActivatedDate = types.StringValue(*cfg.LastActivatedDate) + } + + if diags.Append(m.setPropertyIDs(ctx, cfg.PropertyIDs)...); diags.HasError() { + return diags + } + if diags.Append(m.setNotificationEmails(ctx, cfg.NotificationEmails)...); diags.HasError() { + return diags + } + + if cfg.MultiCDNSettings != nil { + diags.Append(m.setMultiCDNSettings(ctx, cfg.MultiCDNSettings)...) + } + + return diags +} + +func (m *configurationDataSourceModel) setLocations(locations []cloudwrapper.ConfigLocationResp) { + for _, loc := range locations { + m.Locations = append(m.Locations, configurationLocationModel{ + Capacity: capacityModel{ + Unit: types.StringValue(string(loc.Capacity.Unit)), + Value: types.Int64Value(loc.Capacity.Value), + }, + Comments: types.StringValue(loc.Comments), + TrafficTypeID: types.Int64Value(int64(loc.TrafficTypeID)), + MapName: types.StringValue(loc.MapName), + }) + } +} + +func (m *configurationDataSourceModel) setPropertyIDs(ctx context.Context, propertyIDs []string) diag.Diagnostics { + var diags diag.Diagnostics + m.PropertyIDs, diags = types.SetValueFrom(ctx, types.StringType, propertyIDs) + + return diags +} + +func (m *configurationDataSourceModel) setNotificationEmails(ctx context.Context, notificationEmails []string) diag.Diagnostics { + var diags diag.Diagnostics + m.NotificationEmails, diags = types.SetValueFrom(ctx, types.StringType, notificationEmails) + + return diags +} + +func (m *configurationDataSourceModel) setMultiCDNSettings(ctx context.Context, multiCDNSettings *cloudwrapper.MultiCDNSettings) diag.Diagnostics { + m.MultiCDNSettings = &multiCDNSettingsModel{ + EnableSoftAlerts: types.BoolValue(multiCDNSettings.EnableSoftAlerts), + } + m.setBOCC(multiCDNSettings.BOCC) + m.setOrigins(multiCDNSettings.Origins) + m.setCDNs(ctx, multiCDNSettings.CDNs) + + return m.setDataStreams(ctx, multiCDNSettings.DataStreams) +} + +func (m *configurationDataSourceModel) setBOCC(bocc *cloudwrapper.BOCC) { + m.MultiCDNSettings.BOCC = boccModel{ + ConditionalSamplingFrequency: types.StringValue(string(bocc.ConditionalSamplingFrequency)), + Enabled: types.BoolValue(bocc.Enabled), + ForwardType: types.StringValue(string(bocc.ForwardType)), + RequestType: types.StringValue(string(bocc.RequestType)), + SamplingFrequency: types.StringValue(string(bocc.SamplingFrequency)), + } +} + +func (m *configurationDataSourceModel) setOrigins(origins []cloudwrapper.Origin) { + for _, origin := range origins { + m.MultiCDNSettings.Origins = append(m.MultiCDNSettings.Origins, originModel{ + Hostname: types.StringValue(origin.Hostname), + OriginID: types.StringValue(origin.OriginID), + PropertyID: types.Int64Value(int64(origin.PropertyID)), + }) + } +} + +func (m *configurationDataSourceModel) setCDNs(ctx context.Context, cdns []cloudwrapper.CDN) diag.Diagnostics { + var diags diag.Diagnostics + for _, cdn := range cdns { + var ips types.Set + ips, diags = types.SetValueFrom(ctx, types.StringType, cdn.IPACLCIDRs) + if diags.HasError() { + return diags + } + + authKeys := make([]cdnAuthKeyModel, 0, len(cdn.CDNAuthKeys)) + for _, authKey := range cdn.CDNAuthKeys { + authKeys = append(authKeys, cdnAuthKeyModel{ + AuthKeyName: types.StringValue(authKey.AuthKeyName), + ExpiryDate: types.StringValue(authKey.ExpiryDate), + HeaderName: types.StringValue(authKey.HeaderName), + Secret: types.StringValue(authKey.Secret), + }) + } + + m.MultiCDNSettings.CDNs = append(m.MultiCDNSettings.CDNs, cdnsModel{ + CDNAuthKeys: authKeys, + CDNCode: types.StringValue(cdn.CDNCode), + Enabled: types.BoolValue(cdn.Enabled), + HTTPSOnly: types.BoolValue(cdn.HTTPSOnly), + IPACLCIDRs: ips, + }) + } + + return diags +} + +func (m *configurationDataSourceModel) setDataStreams(ctx context.Context, datastreams *cloudwrapper.DataStreams) diag.Diagnostics { + dataStreamsIDs, diags := types.SetValueFrom(ctx, types.Int64Type, datastreams.DataStreamIDs) + if diags.HasError() { + return diags + } + m.MultiCDNSettings.DataStreams = dataStreamsModel{ + DataStreamsIDs: dataStreamsIDs, + Enabled: types.BoolValue(datastreams.Enabled), + } + if datastreams.SamplingRate != nil { + m.MultiCDNSettings.DataStreams.SamplingRate = types.Int64Value(int64(*datastreams.SamplingRate)) + } else { + m.MultiCDNSettings.DataStreams.SamplingRate = types.Int64Null() + } + + return diags +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration_test.go new file mode 100644 index 000000000..191f2d40f --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configuration_test.go @@ -0,0 +1,358 @@ +package cloudwrapper + +import ( + "fmt" + "regexp" + "strconv" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +var ( + minimalConfiguration = testDataForCWConfiguration{ + ID: 1, + Comments: "Test comments", + ContractID: "Test contract", + Status: "Test status", + ConfigName: "Test config name", + LastUpdatedBy: "Test user", + LastUpdatedDate: "Test date", + RetainIdleObjects: false, + } + + configuration = testDataForCWConfiguration{ + ID: 1, + CapacityAlertsThreshold: tools.IntPtr(1), + Comments: "Test comments", + ContractID: "Test contract", + Locations: []cloudwrapper.ConfigLocationResp{ + { + Comments: "Test comments 1", + TrafficTypeID: 11, + Capacity: cloudwrapper.Capacity{ + Value: 111, + Unit: "GB", + }, + MapName: "Test MapName 1", + }, + { + Comments: "Test comments 2", + TrafficTypeID: 22, + Capacity: cloudwrapper.Capacity{ + Value: 222, + Unit: "TB", + }, + MapName: "Test MapName 2", + }, + }, + MultiCDNSettings: &cloudwrapper.MultiCDNSettings{ + BOCC: &cloudwrapper.BOCC{ + ConditionalSamplingFrequency: "ZERO", + Enabled: true, + ForwardType: "ORIGIN_ONLY", + RequestType: "EDGE_ONLY", + SamplingFrequency: "ZERO", + }, + CDNs: []cloudwrapper.CDN{ + { + CDNAuthKeys: []cloudwrapper.CDNAuthKey{ + { + AuthKeyName: "Test name 1", + ExpiryDate: "Test date 1", + HeaderName: "Test header name 1", + Secret: "Test secret 1", + }, + { + AuthKeyName: "Test name 2", + ExpiryDate: "Test date 2", + HeaderName: "Test header name 2", + Secret: "Test secret 2", + }, + }, + CDNCode: "Test code", + Enabled: true, + HTTPSOnly: true, + IPACLCIDRs: []string{"1.1.1.1", "2.2.2.2"}, + }, + { + CDNAuthKeys: []cloudwrapper.CDNAuthKey{ + { + AuthKeyName: "Test name 1", + ExpiryDate: "Test date 1", + HeaderName: "Test header name 1", + Secret: "Test secret 1", + }, + }, + CDNCode: "Test code", + IPACLCIDRs: []string{"1.1.1.1", "2.2.2.2"}, + }, + }, + DataStreams: &cloudwrapper.DataStreams{ + DataStreamIDs: []int64{1, 2}, + Enabled: true, + SamplingRate: tools.IntPtr(10), + }, + EnableSoftAlerts: true, + Origins: []cloudwrapper.Origin{ + { + Hostname: "Test hostname 1", + OriginID: "Test originID 1", + PropertyID: 11, + }, + { + Hostname: "Test hostname 2", + OriginID: "Test originID 2", + PropertyID: 22, + }, + }, + }, + Status: "Test status", + ConfigName: "Test config name", + LastUpdatedBy: "Test user", + LastUpdatedDate: "Test date", + LastActivatedBy: tools.StringPtr("Test user 2"), + LastActivatedDate: tools.StringPtr("Test date 2"), + NotificationEmails: []string{"1@a.com", "2@a.com"}, + PropertyIDs: []string{"11", "22"}, + RetainIdleObjects: true, + } +) + +func TestConfigurationDataSource(t *testing.T) { + t.Parallel() + + tests := map[string]struct { + configPath string + init func(*testing.T, *cloudwrapper.Mock, testDataForCWConfiguration) + mockData testDataForCWConfiguration + error *regexp.Regexp + }{ + "happy path - minimal data returned": { + configPath: "testdata/TestDataConfiguration/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWConfiguration) { + expectGetConfiguration(m, testData, 5) + }, + mockData: minimalConfiguration, + }, + "happy path - all fields": { + configPath: "testdata/TestDataConfiguration/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWConfiguration) { + expectGetConfiguration(m, testData, 5) + }, + mockData: configuration, + }, + "error getting configuration": { + configPath: "testdata/TestDataConfiguration/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWConfiguration) { + expectGetConfigurationWithError(m, testData, 1) + }, + mockData: testDataForCWConfiguration{ + ID: 1, + }, + error: regexp.MustCompile("get configuration failed"), + }, + "no required argument - configID": { + configPath: "testdata/TestDataConfiguration/no_config_id.tf", + error: regexp.MustCompile(`The argument "id" is required, but no definition was found.`), + }, + } + for name, test := range tests { + name, test := name, test + t.Run(name, func(t *testing.T) { + t.Parallel() + + client := &cloudwrapper.Mock{} + if test.init != nil { + test.init(t, client, test.mockData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, test.configPath), + Check: checkCloudWrapperConfigurationAttrs(test.mockData), + ExpectError: test.error, + }, + }, + }) + + client.AssertExpectations(t) + }) + } +} + +type testDataForCWConfiguration struct { + ID int64 + CapacityAlertsThreshold *int + Comments string + ContractID string + Locations []cloudwrapper.ConfigLocationResp + MultiCDNSettings *cloudwrapper.MultiCDNSettings + Status string + ConfigName string + LastUpdatedBy string + LastUpdatedDate string + LastActivatedBy *string + LastActivatedDate *string + NotificationEmails []string + PropertyIDs []string + RetainIdleObjects bool +} + +func checkCloudWrapperConfigurationAttrs(data testDataForCWConfiguration) resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + checkFuncs = append(checkFuncs, checkConfiguration(data, "data.akamai_cloudwrapper_configuration.test", "")) + + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} + +func checkConfiguration(data testDataForCWConfiguration, dsName, keyPrefix string) resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + if data.CapacityAlertsThreshold != nil { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"capacity_alerts_threshold", strconv.Itoa(*data.CapacityAlertsThreshold))) + } else { + checkFuncs = append(checkFuncs, resource.TestCheckNoResourceAttr(dsName, keyPrefix+"capacity_alerts_threshold")) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"comments", data.Comments), + resource.TestCheckResourceAttr(dsName, keyPrefix+"id", strconv.Itoa(int(data.ID))), + resource.TestCheckResourceAttr(dsName, keyPrefix+"contract_id", data.ContractID), + resource.TestCheckResourceAttr(dsName, keyPrefix+"config_name", data.ConfigName), + resource.TestCheckResourceAttr(dsName, keyPrefix+"last_updated_by", data.LastUpdatedBy), + resource.TestCheckResourceAttr(dsName, keyPrefix+"last_updated_date", data.LastUpdatedDate), + resource.TestCheckResourceAttr(dsName, keyPrefix+"retain_idle_objects", strconv.FormatBool(data.RetainIdleObjects)), + resource.TestCheckResourceAttr(dsName, keyPrefix+"status", data.Status), + ) + if data.LastActivatedBy != nil { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"last_activated_by", *data.LastActivatedBy)) + } else { + checkFuncs = append(checkFuncs, resource.TestCheckNoResourceAttr(dsName, keyPrefix+"last_activated_by")) + } + if data.LastActivatedDate != nil { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"last_activated_date", *data.LastActivatedDate)) + } else { + checkFuncs = append(checkFuncs, resource.TestCheckNoResourceAttr(dsName, keyPrefix+"last_activated_date")) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"notification_emails.#", strconv.Itoa(len(data.NotificationEmails)))) + for i, email := range data.NotificationEmails { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"notification_emails.%d", i), email)) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"property_ids.#", strconv.Itoa(len(data.PropertyIDs)))) + for i, prpID := range data.PropertyIDs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"property_ids.%d", i), prpID)) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"retain_idle_objects", strconv.FormatBool(data.RetainIdleObjects))) + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"locations.#", strconv.Itoa(len(data.Locations)))) + for i, loc := range data.Locations { + checkFuncs = append(checkFuncs, + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"locations.%d.capacity.value", i), strconv.FormatInt(loc.Capacity.Value, 10)), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"locations.%d.capacity.unit", i), string(loc.Capacity.Unit)), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"locations.%d.comments", i), loc.Comments), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"locations.%d.map_name", i), loc.MapName), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"locations.%d.traffic_type_id", i), strconv.Itoa(loc.TrafficTypeID)), + ) + } + + if data.MultiCDNSettings != nil { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.enable_soft_alerts", strconv.FormatBool(data.MultiCDNSettings.EnableSoftAlerts))) + if data.MultiCDNSettings.DataStreams != nil { + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.data_streams.enabled", strconv.FormatBool(data.MultiCDNSettings.DataStreams.Enabled))) + if data.MultiCDNSettings.DataStreams.SamplingRate != nil { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.data_streams.sampling_rate", strconv.Itoa(*data.MultiCDNSettings.DataStreams.SamplingRate))) + } else { + checkFuncs = append(checkFuncs, resource.TestCheckNoResourceAttr(dsName, keyPrefix+"multi_cdn_settings.data_streams.sampling_rate")) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.data_streams.data_stream_ids.#", strconv.Itoa(len(data.MultiCDNSettings.DataStreams.DataStreamIDs)))) + for i, id := range data.MultiCDNSettings.DataStreams.DataStreamIDs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.data_streams.data_stream_ids.%d", i), strconv.Itoa(int(id)))) + } + } + + if data.MultiCDNSettings.BOCC != nil { + checkFuncs = append(checkFuncs, + resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.bocc.enabled", strconv.FormatBool(data.MultiCDNSettings.BOCC.Enabled)), + resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.bocc.request_type", string(data.MultiCDNSettings.BOCC.RequestType)), + resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.bocc.forward_type", string(data.MultiCDNSettings.BOCC.ForwardType)), + resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.bocc.conditional_sampling_frequency", string(data.MultiCDNSettings.BOCC.ConditionalSamplingFrequency)), + resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.bocc.sampling_frequency", string(data.MultiCDNSettings.BOCC.SamplingFrequency)), + ) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.origins.#", strconv.Itoa(len(data.MultiCDNSettings.Origins)))) + for i, origin := range data.MultiCDNSettings.Origins { + checkFuncs = append(checkFuncs, + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.origins.%d.origin_id", i), origin.OriginID), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.origins.%d.hostname", i), origin.Hostname), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.origins.%d.property_id", i), strconv.Itoa(origin.PropertyID)), + ) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, keyPrefix+"multi_cdn_settings.cdns.#", strconv.Itoa(len(data.MultiCDNSettings.CDNs)))) + for i, cdn := range data.MultiCDNSettings.CDNs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_code", i), cdn.CDNCode)) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.enabled", i), strconv.FormatBool(cdn.Enabled))) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.https_only", i), strconv.FormatBool(cdn.HTTPSOnly))) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.ip_acl_cidrs.#", i), strconv.Itoa(len(cdn.IPACLCIDRs)))) + for j, ip := range cdn.IPACLCIDRs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.ip_acl_cidrs.%d", i, j), ip)) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_auth_keys.#", i), strconv.Itoa(len(cdn.CDNAuthKeys)))) + for j, authKey := range cdn.CDNAuthKeys { + checkFuncs = append(checkFuncs, + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_auth_keys.%d.auth_key_name", i, j), authKey.AuthKeyName), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_auth_keys.%d.header_name", i, j), authKey.HeaderName), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_auth_keys.%d.secret", i, j), authKey.Secret), + resource.TestCheckResourceAttr(dsName, fmt.Sprintf(keyPrefix+"multi_cdn_settings.cdns.%d.cdn_auth_keys.%d.expiry_date", i, j), authKey.ExpiryDate), + ) + } + + } + } + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} + +func expectGetConfiguration(client *cloudwrapper.Mock, data testDataForCWConfiguration, timesToRun int) { + getConfigurationReq := cloudwrapper.GetConfigurationRequest{ + ConfigID: data.ID, + } + getConfigurationRes := getConfiguration(data) + client.On("GetConfiguration", mock.Anything, getConfigurationReq).Return(&getConfigurationRes, nil).Times(timesToRun) +} + +func getConfiguration(data testDataForCWConfiguration) cloudwrapper.Configuration { + return cloudwrapper.Configuration{ + CapacityAlertsThreshold: data.CapacityAlertsThreshold, + Comments: data.Comments, + ContractID: data.ContractID, + ConfigID: data.ID, + Locations: data.Locations, + MultiCDNSettings: data.MultiCDNSettings, + Status: cloudwrapper.StatusType(data.Status), + ConfigName: data.ConfigName, + LastUpdatedBy: data.LastUpdatedBy, + LastUpdatedDate: data.LastUpdatedDate, + LastActivatedBy: data.LastActivatedBy, + LastActivatedDate: data.LastActivatedDate, + NotificationEmails: data.NotificationEmails, + PropertyIDs: data.PropertyIDs, + RetainIdleObjects: data.RetainIdleObjects, + } +} + +func expectGetConfigurationWithError(client *cloudwrapper.Mock, data testDataForCWConfiguration, timesToRun int) { + getConfigurationReq := cloudwrapper.GetConfigurationRequest{ + ConfigID: data.ID, + } + client.On("GetConfiguration", mock.Anything, getConfigurationReq).Return(nil, fmt.Errorf("get configuration failed")).Times(timesToRun) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations.go new file mode 100644 index 000000000..51fc31802 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations.go @@ -0,0 +1,171 @@ +package cloudwrapper + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ datasource.DataSource = &configurationsDataSource{} + _ datasource.DataSourceWithConfigure = &configurationsDataSource{} +) + +type ( + configurationsDataSource struct { + client cloudwrapper.CloudWrapper + } + + configurationsDataSourceModel struct { + ID types.String `tfsdk:"id"` + Configurations []configurationDataSourceModel `tfsdk:"configurations"` + } +) + +// NewConfigurationsDataSource returns configurations data source +func NewConfigurationsDataSource() datasource.DataSource { + return &configurationsDataSource{} +} + +// setClient assigns given client to properties data source +func (d *configurationsDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source meta information +func (d *configurationsDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_configurations" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *configurationsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + // ProviderData is nil when Configure is run first time as part of ValidateDataSourceConfig in framework provider + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source terraform schema +func (d *configurationsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "CloudWrapper configurations", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_configurations`.", + Description: "ID of the data source.", + }, + }, + Blocks: map[string]schema.Block{ + "configurations": schema.ListNestedBlock{ + Description: "List of the configurations on the contract.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier of a Cloud Wrapper configuration.", + }, + "capacity_alerts_threshold": schema.Int64Attribute{ + Computed: true, + Description: "Represents the threshold for sending alerts.", + }, + "comments": schema.StringAttribute{ + Computed: true, + Description: "Additional information provided by user which can help to differentiate or track changes of the configuration.", + }, + "config_name": schema.StringAttribute{ + Computed: true, + Description: "Name of the configuration.", + }, + "contract_id": schema.StringAttribute{ + Computed: true, + Description: "Contract ID with Cloud Wrapper entitlement.", + }, + "last_activated_by": schema.StringAttribute{ + Computed: true, + Description: "User to last activate the configuration.", + }, + "last_activated_date": schema.StringAttribute{ + Computed: true, + Description: "ISO format date that represents when the configuration was last activated successfully.", + }, + "last_updated_by": schema.StringAttribute{ + Computed: true, + Description: "User to last modify the configuration.", + }, + "last_updated_date": schema.StringAttribute{ + Computed: true, + Description: "ISO format date that represents when the configuration was last edited.", + }, + "notification_emails": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "Email addresses to receive notifications.", + }, + "property_ids": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + Description: "List of properties belonging to media delivery products. Properties need to be unique across configurations.", + }, + "retain_idle_objects": schema.BoolAttribute{ + Computed: true, + Description: "Retain idle objects beyond their max idle lifetime.", + }, + "status": schema.StringAttribute{ + Computed: true, + Description: "Current state of the provisioning of the configuration, either SAVED, IN_PROGRESS, ACTIVE, DELETE_IN_PROGRESS, or FAILED.", + }, + }, + Blocks: configBlock, + }, + }, + }, + } +} + +func (d *configurationsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Configurations DataSource Read") + + var data configurationsDataSourceModel + if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() { + return + } + + configs, err := d.client.ListConfigurations(ctx) + if err != nil { + resp.Diagnostics.AddError("Reading CloudWrapper Configurations", err.Error()) + return + } + + for _, cfg := range configs.Configurations { + var cfgModel configurationDataSourceModel + if resp.Diagnostics.Append(cfgModel.populate(ctx, &cfg)...); resp.Diagnostics.HasError() { + return + } + cfgModel.ID = types.Int64Value(cfg.ConfigID) + data.Configurations = append(data.Configurations, cfgModel) + } + + data.ID = types.StringValue("akamai_cloudwrapper_configurations") + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations_test.go new file mode 100644 index 000000000..b9d692ab5 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_configurations_test.go @@ -0,0 +1,121 @@ +package cloudwrapper + +import ( + "fmt" + "regexp" + "strconv" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestDataConfigurations(t *testing.T) { + t.Parallel() + tests := map[string]struct { + configPath string + init func(*testing.T, *cloudwrapper.Mock, []testDataForCWConfiguration) + mockData []testDataForCWConfiguration + error *regexp.Regexp + }{ + "happy path- minimal data returned": { + configPath: "testdata/TestDataConfigurations/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData []testDataForCWConfiguration) { + expectGetConfigurations(m, testData, 5) + }, + mockData: []testDataForCWConfiguration{ + minimalConfiguration, + }, + }, + "happy path - all fields": { + configPath: "testdata/TestDataConfigurations/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData []testDataForCWConfiguration) { + expectGetConfigurations(m, testData, 5) + }, + mockData: []testDataForCWConfiguration{ + configuration, + }, + }, + "happy path - a few configurations": { + configPath: "testdata/TestDataConfigurations/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData []testDataForCWConfiguration) { + expectGetConfigurations(m, testData, 5) + }, + mockData: []testDataForCWConfiguration{ + minimalConfiguration, + configuration, + }, + }, + "error getting configuration": { + configPath: "testdata/TestDataConfigurations/default.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData []testDataForCWConfiguration) { + m.On("ListConfigurations", mock.Anything, mock.Anything).Return(nil, fmt.Errorf("get configuration failed")).Times(1) + }, + mockData: []testDataForCWConfiguration{ + { + ID: 1, + }, + }, + error: regexp.MustCompile("get configuration failed"), + }, + } + for name, test := range tests { + name, test := name, test + t.Run(name, func(t *testing.T) { + t.Parallel() + + client := &cloudwrapper.Mock{} + if test.init != nil { + test.init(t, client, test.mockData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, test.configPath), + Check: checkCloudWrapperConfigurationsAttrs(test.mockData), + ExpectError: test.error, + }, + }, + }) + + client.AssertExpectations(t) + }) + } +} + +func checkCloudWrapperConfigurationsAttrs(data []testDataForCWConfiguration) resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_configurations.test", "configurations.#", strconv.Itoa(len(data)))) + for i, c := range data { + checkFuncs = append(checkFuncs, checkCloudWrapperConfiguration(c, i)) + } + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} + +func expectGetConfigurations(client *cloudwrapper.Mock, data []testDataForCWConfiguration, timesToRun int) { + var configurations []cloudwrapper.Configuration + + for _, c := range data { + configurations = append(configurations, getConfiguration(c)) + } + + res := cloudwrapper.ListConfigurationsResponse{ + Configurations: configurations, + } + client.On("ListConfigurations", mock.Anything, mock.Anything).Return(&res, nil).Times(timesToRun) +} + +func checkCloudWrapperConfiguration(data testDataForCWConfiguration, idx int) resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + dsName := "data.akamai_cloudwrapper_configurations.test" + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(dsName, "id", "akamai_cloudwrapper_configurations")) + checkFuncs = append(checkFuncs, checkConfiguration(data, dsName, "configurations."+strconv.Itoa(idx)+".")) + + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location.go new file mode 100644 index 000000000..d8c7ca21f --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location.go @@ -0,0 +1,140 @@ +package cloudwrapper + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ datasource.DataSource = &locationDataSource{} + _ datasource.DataSourceWithConfigure = &locationDataSource{} +) + +type ( + locationDataSource struct { + client cloudwrapper.CloudWrapper + } + + locationDataSourceModel struct { + ID types.String `tfsdk:"id"` + LocationName types.String `tfsdk:"location_name"` + TrafficType types.String `tfsdk:"traffic_type"` + TrafficTypeID types.Int64 `tfsdk:"traffic_type_id"` + LocationID types.String `tfsdk:"location_id"` + } +) + +// NewLocationDataSource returns a new location's data source +func NewLocationDataSource() datasource.DataSource { + return &locationDataSource{} +} + +func (d *locationDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source's meta information +func (d *locationDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_location" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *locationDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + // ProviderData is nil when Configure is run first time as part of ValidateDataSourceConfig in framework provider + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source's terraform schema +func (d *locationDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "CloudWrapper location", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_location`", + Description: "ID of the data source.", + }, + "location_name": schema.StringAttribute{ + Required: true, + Description: "Name of the location.", + }, + "traffic_type": schema.StringAttribute{ + Required: true, + Validators: []validator.String{stringvalidator.OneOf("LIVE", "LIVE_VOD", "WEB_STANDARD_TLS", "WEB_ENHANCED_TLS")}, + Description: "Represents the traffic type. LIVE applies to low-latency media traffic, such as live streaming. " + + "LIVE_VOD applies to redundant media traffic, like video on demand content. " + + "WEB_STANDARD_TLS or WEB_ENHANCED_TLS applies to web content using Standard TLS security or Enhanced TLS security, respectively.", + }, + "traffic_type_id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier for the location and traffic type combination.", + }, + "location_id": schema.StringAttribute{ + Computed: true, + Description: "Unique identifier of the location.", + }, + }, + } +} + +// Read is called when the provider must read data source values in order to update state +func (d *locationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Location DataSource Read") + + var data locationDataSourceModel + if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() { + return + } + + locations, err := d.client.ListLocations(ctx) + if err != nil { + resp.Diagnostics.AddError(fmt.Sprintf("reading %s", ErrCloudWrapperLocation), err.Error()) + return + } + + for _, loc := range locations.Locations { + if loc.LocationName == data.LocationName.ValueString() { + if trafficType, ok := getMatchingTrafficType(loc.TrafficTypes, data.TrafficType.ValueString()); ok { + data.LocationID = types.StringValue(trafficType.MapName) + data.TrafficTypeID = types.Int64Value(int64(trafficType.TrafficTypeID)) + data.ID = types.StringValue("akamai_cloudwrapper_location") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) + return + } + } + } + resp.Diagnostics.AddError("No matching location", "no location with given location name and traffic type") +} + +func getMatchingTrafficType(items []cloudwrapper.TrafficTypeItem, trafficType string) (*cloudwrapper.TrafficTypeItem, bool) { + for _, item := range items { + if item.TrafficType == trafficType { + return &item, true + } + } + return nil, false +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location_test.go new file mode 100644 index 000000000..3e78f86bd --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_location_test.go @@ -0,0 +1,133 @@ +package cloudwrapper + +import ( + "fmt" + "regexp" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestDataLocation(t *testing.T) { + expectListLocations := func(client *cloudwrapper.Mock, data testDataForCWLocation, timesToRun int) { + listLocationsRes := cloudwrapper.ListLocationResponse{ + Locations: data.locations, + } + client.On("ListLocations", mock.Anything).Return(&listLocationsRes, nil).Times(timesToRun) + } + + expectListLocationsWithError := func(client *cloudwrapper.Mock, timesToRun int) { + client.On("ListLocations", mock.Anything).Return(nil, fmt.Errorf("list locations failed")).Times(timesToRun) + } + + location := testDataForCWLocation{ + locations: []cloudwrapper.Location{ + { + LocationID: 1, + LocationName: "US East", + TrafficTypes: []cloudwrapper.TrafficTypeItem{ + { + TrafficTypeID: 1, + TrafficType: "LIVE", + MapName: "cw-s-use-live", + }, + { + TrafficTypeID: 2, + TrafficType: "LIVE_VOD", + MapName: "cw-s-use", + }, + }, + MultiCDNLocationID: "018", + }, + { + LocationID: 2, + LocationName: "US West", + TrafficTypes: []cloudwrapper.TrafficTypeItem{ + { + TrafficTypeID: 3, + TrafficType: "LIVE_VOD", + MapName: "cw-s-usw", + }, + { + TrafficTypeID: 4, + TrafficType: "LIVE", + MapName: "cw-s-usw-live", + }, + }, + MultiCDNLocationID: "020", + }, + }, + } + tests := map[string]struct { + configPath string + init func(*testing.T, *cloudwrapper.Mock, testDataForCWLocation) + mockData testDataForCWLocation + error *regexp.Regexp + }{ + "happy path": { + configPath: "testdata/TestDataLocation/location.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWLocation) { + expectListLocations(m, testData, 5) + }, + mockData: location, + }, + "no location": { + configPath: "testdata/TestDataLocation/no_location.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWLocation) { + expectListLocations(m, testData, 1) + }, + mockData: location, + error: regexp.MustCompile("no location with given location name and traffic type"), + }, + "invalid type": { + configPath: "testdata/TestDataLocation/invalid_type.tf", + error: regexp.MustCompile(`Attribute traffic_type value must be one of: \["LIVE" "LIVE_VOD"\n"WEB_STANDARD_TLS" "WEB_ENHANCED_TLS"], got: "TEST"`), + }, + "error listing locations": { + configPath: "testdata/TestDataLocation/location.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWLocation) { + expectListLocationsWithError(m, 1) + }, + error: regexp.MustCompile("list locations failed"), + }, + } + for name, test := range tests { + t.Run(name, func(t *testing.T) { + client := &cloudwrapper.Mock{} + if test.init != nil { + test.init(t, client, test.mockData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, test.configPath), + Check: checkCloudWrapperLocationAttrs(), + ExpectError: test.error, + }, + }, + }) + + client.AssertExpectations(t) + }) + } +} + +type testDataForCWLocation struct { + locations []cloudwrapper.Location +} + +func checkCloudWrapperLocationAttrs() resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_location.test", "traffic_type_id", "3")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_location.test", "location_id", "cw-s-usw")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttrSet("data.akamai_cloudwrapper_location.test", "id")) + + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations.go new file mode 100644 index 000000000..377b97f84 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations.go @@ -0,0 +1,172 @@ +package cloudwrapper + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ datasource.DataSource = &locationsDataSource{} + _ datasource.DataSourceWithConfigure = &locationsDataSource{} +) + +type ( + locationsDataSource struct { + client cloudwrapper.CloudWrapper + } + + locationsDataSourceModel struct { + ID types.String `tfsdk:"id"` + Locations []locationModel `tfsdk:"locations"` + } + + locationModel struct { + LocationID types.Int64 `tfsdk:"location_id"` + LocationName types.String `tfsdk:"location_name"` + MultiCDNLocationID types.String `tfsdk:"multi_cdn_location_id"` + TrafficTypes []trafficTypeModel `tfsdk:"traffic_types"` + } + + trafficTypeModel struct { + TrafficType types.String `tfsdk:"traffic_type"` + TrafficTypeID types.Int64 `tfsdk:"traffic_type_id"` + LocationID types.String `tfsdk:"location_id"` + } +) + +// NewLocationsDataSource returns a new location's data source +func NewLocationsDataSource() datasource.DataSource { + return &locationsDataSource{} +} + +func (d *locationsDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source's meta information +func (d *locationsDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_locations" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *locationsDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + // ProviderData is nil when Configure is run first time as part of ValidateDataSourceConfig in framework provider + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source's terraform schema +func (d *locationsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "CloudWrapper locations", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_locations`", + Description: "ID of the data source.", + }, + }, + Blocks: map[string]schema.Block{ + "locations": schema.ListNestedBlock{ + Description: "List of the locations.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "location_id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier of the location.", + }, + "location_name": schema.StringAttribute{ + Computed: true, + Description: "Name of the location.", + }, + "multi_cdn_location_id": schema.StringAttribute{ + Computed: true, + Description: "Unique identifier of the multi CDN location.", + }, + }, + Blocks: map[string]schema.Block{ + "traffic_types": schema.ListNestedBlock{ + Description: "List of traffic types for the location.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "traffic_type_id": schema.Int64Attribute{ + Computed: true, + Description: "Unique identifier for the location and traffic type combination.", + }, + "traffic_type": schema.StringAttribute{ + Computed: true, + Description: "Represents the traffic type. LIVE applies to low-latency media traffic, such as live streaming. " + + "LIVE_VOD applies to redundant media traffic, like video on demand content. " + + "WEB_STANDARD_TLS or WEB_ENHANCED_TLS applies to web content using Standard TLS security or Enhanced TLS security, respectively.", + }, + "location_id": schema.StringAttribute{ + Computed: true, + Description: "Represents the failover map.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +// Read is called when the provider must read data source values in order to update state +func (d *locationsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Locations DataSource Read") + + var data locationsDataSourceModel + if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() { + return + } + + locations, err := d.client.ListLocations(ctx) + if err != nil { + resp.Diagnostics.AddError("reading CloudWrapper Locations", err.Error()) + return + } + + for _, loc := range locations.Locations { + trafficTypes := make([]trafficTypeModel, 0) + for _, trafficType := range loc.TrafficTypes { + tt := trafficTypeModel{ + TrafficType: types.StringValue(trafficType.TrafficType), + TrafficTypeID: types.Int64Value(int64(trafficType.TrafficTypeID)), + LocationID: types.StringValue(trafficType.MapName), + } + trafficTypes = append(trafficTypes, tt) + } + location := locationModel{ + LocationID: types.Int64Value(int64(loc.LocationID)), + LocationName: types.StringValue(loc.LocationName), + MultiCDNLocationID: types.StringValue(loc.MultiCDNLocationID), + TrafficTypes: trafficTypes, + } + data.Locations = append(data.Locations, location) + } + data.ID = types.StringValue("akamai_cloudwrapper_locations") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations_test.go new file mode 100644 index 000000000..43e3c5b22 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_locations_test.go @@ -0,0 +1,124 @@ +package cloudwrapper + +import ( + "fmt" + "regexp" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestDataLocations(t *testing.T) { + expectListLocations := func(client *cloudwrapper.Mock, data testDataForCWLocations, timesToRun int) { + listLocationsRes := cloudwrapper.ListLocationResponse{ + Locations: data.locations, + } + client.On("ListLocations", mock.Anything).Return(&listLocationsRes, nil).Times(timesToRun) + } + + expectListLocationsWithError := func(client *cloudwrapper.Mock, timesToRun int) { + client.On("ListLocations", mock.Anything).Return(nil, fmt.Errorf("list locations failed")).Times(timesToRun) + } + + location := testDataForCWLocations{ + locations: []cloudwrapper.Location{ + { + LocationID: 1, + LocationName: "US East", + TrafficTypes: []cloudwrapper.TrafficTypeItem{ + { + TrafficTypeID: 1, + TrafficType: "LIVE", + MapName: "cw-s-use-live", + }, + { + TrafficTypeID: 2, + TrafficType: "LIVE_VOD", + MapName: "cw-s-use", + }, + }, + MultiCDNLocationID: "018", + }, + { + LocationID: 2, + LocationName: "US West", + TrafficTypes: []cloudwrapper.TrafficTypeItem{ + { + TrafficTypeID: 3, + TrafficType: "LIVE_VOD", + MapName: "cw-s-usw", + }, + { + TrafficTypeID: 4, + TrafficType: "LIVE", + MapName: "cw-s-usw-live", + }, + }, + MultiCDNLocationID: "020", + }, + }, + } + tests := map[string]struct { + configPath string + init func(*testing.T, *cloudwrapper.Mock, testDataForCWLocations) + mockData testDataForCWLocations + error *regexp.Regexp + }{ + "happy path": { + configPath: "testdata/TestDataLocations/location.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWLocations) { + expectListLocations(m, testData, 5) + }, + mockData: location, + }, + "error listing locations": { + configPath: "testdata/TestDataLocations/location.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWLocations) { + expectListLocationsWithError(m, 1) + }, + error: regexp.MustCompile("list locations failed"), + }, + } + for name, test := range tests { + t.Run(name, func(t *testing.T) { + client := &cloudwrapper.Mock{} + if test.init != nil { + test.init(t, client, test.mockData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, test.configPath), + Check: checkCloudWrapperLocationsAttrs(), + ExpectError: test.error, + }, + }, + }) + + client.AssertExpectations(t) + }) + } +} + +type testDataForCWLocations struct { + locations []cloudwrapper.Location +} + +func checkCloudWrapperLocationsAttrs() resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_locations.test", "locations.#", "2")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_locations.test", "locations.1.location_id", "2")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_locations.test", "locations.1.traffic_types.#", "2")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_locations.test", "locations.1.traffic_types.0.traffic_type_id", "3")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_locations.test", "locations.1.traffic_types.0.location_id", "cw-s-usw")) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttrSet("data.akamai_cloudwrapper_locations.test", "id")) + + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties.go new file mode 100644 index 000000000..7f615b4b7 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties.go @@ -0,0 +1,166 @@ +package cloudwrapper + +import ( + "context" + "fmt" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ datasource.DataSource = &propertiesDataSource{} + _ datasource.DataSourceWithConfigure = &propertiesDataSource{} +) + +type ( + propertiesDataSource struct { + client cloudwrapper.CloudWrapper + } + + propertiesDataSourceModel struct { + ID types.String `tfsdk:"id"` + ContractIDs types.List `tfsdk:"contract_ids"` + Unused types.Bool `tfsdk:"unused"` + Properties []propertyModel `tfsdk:"properties"` + } + + propertyModel struct { + PropertyID types.Int64 `tfsdk:"property_id"` + Type types.String `tfsdk:"type"` + PropertyName types.String `tfsdk:"property_name"` + ContractID types.String `tfsdk:"contract_id"` + GroupID types.Int64 `tfsdk:"group_id"` + } +) + +// NewPropertiesDataSource returns a new properties' data source +func NewPropertiesDataSource() datasource.DataSource { + return &propertiesDataSource{} +} + +func (d *propertiesDataSource) setClient(client cloudwrapper.CloudWrapper) { + d.client = client +} + +// Metadata configures data source's meta information +func (d *propertiesDataSource) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_properties" +} + +// Configure configures data source at the beginning of the lifecycle +func (d *propertiesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + // ProviderData is nil when Configure is run first time as part of ValidateDataSourceConfig in framework provider + return + } + + if d.client != nil { + return + } + + m, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected meta.Meta, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + } + d.client = cloudwrapper.Client(m.Session()) +} + +// Schema is used to define data source's terraform schema +func (d *propertiesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: "CloudWrapper properties", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_properties`", + Description: "ID of the data source.", + }, + "contract_ids": schema.ListAttribute{ + ElementType: types.StringType, + Optional: true, + Description: "List of contract IDs with Cloud Wrapper entitlement.", + }, + "unused": schema.BoolAttribute{ + Optional: true, + Description: "Specify whether the response should contain only unused properties.", + }, + }, + Blocks: map[string]schema.Block{ + "properties": schema.ListNestedBlock{ + Description: "List of all unused properties.", + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "property_id": schema.Int64Attribute{ + Computed: true, + Description: "Property ID of the property.", + }, + "type": schema.StringAttribute{ + Computed: true, + Description: "The type of property. MEDIA applies to live or video on demand content. WEB applies to website or app content.", + }, + "property_name": schema.StringAttribute{ + Computed: true, + Description: "Name of the property belonging to the origin.", + }, + "contract_id": schema.StringAttribute{ + Computed: true, + Description: "Contract ID having Cloud Wrapper entitlement.", + }, + "group_id": schema.Int64Attribute{ + Computed: true, + Description: "ID of the group which the property belongs to.", + }, + }, + }, + }, + }, + } +} + +// Read is called when the provider must read data source values in order to update state +func (d *propertiesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + tflog.Debug(ctx, "CloudWrapper Properties DataSource Read") + + var data propertiesDataSourceModel + if resp.Diagnostics.Append(req.Config.Get(ctx, &data)...); resp.Diagnostics.HasError() { + return + } + + var contracts []string + if resp.Diagnostics.Append(data.ContractIDs.ElementsAs(ctx, &contracts, false)...); resp.Diagnostics.HasError() { + return + } + + properties, err := d.client.ListProperties(ctx, cloudwrapper.ListPropertiesRequest{ + Unused: data.Unused.ValueBool(), + ContractIDs: contracts, + }) + if err != nil { + resp.Diagnostics.AddError("Reading CloudWrapper Properties", err.Error()) + return + } + + for _, prp := range properties.Properties { + data.Properties = append(data.Properties, propertyModel{ + PropertyID: types.Int64Value(prp.PropertyID), + Type: types.StringValue(string(prp.Type)), + PropertyName: types.StringValue(prp.PropertyName), + ContractID: types.StringValue(prp.ContractID), + GroupID: types.Int64Value(prp.GroupID), + }) + } + + data.ID = types.StringValue("akamai_cloudwrapper_properties") + + if resp.Diagnostics.Append(resp.State.Set(ctx, &data)...); resp.Diagnostics.HasError() { + return + } +} diff --git a/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties_test.go b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties_test.go new file mode 100644 index 000000000..c19657927 --- /dev/null +++ b/pkg/providers/cloudwrapper/data_akamai_cloudwrapper_properties_test.go @@ -0,0 +1,171 @@ +package cloudwrapper + +import ( + "fmt" + "regexp" + "strconv" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestDataProperty(t *testing.T) { + tests := map[string]struct { + configPath string + init func(*testing.T, *cloudwrapper.Mock, testDataForCWProperties) + mockData testDataForCWProperties + error *regexp.Regexp + }{ + "happy path - one property, unused-true": { + configPath: "testdata/TestDataProperties/default_unused_true.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWProperties) { + expectListProperties(m, testData, 5) + }, + mockData: testDataForCWProperties{ + unused: true, + properties: []cloudwrapper.Property{ + { + GroupID: 1, + ContractID: "ctr_1", + PropertyID: 11, + PropertyName: "Name1", + Type: "Type1", + }, + }, + }, + }, + "happy path - two properties, unused-false, contract_ids supplied": { + configPath: "testdata/TestDataProperties/default_unused_false.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWProperties) { + expectListProperties(m, testData, 5) + }, + mockData: testDataForCWProperties{ + contractIDs: []string{"ctr_1", "ctr_2"}, + properties: []cloudwrapper.Property{ + { + GroupID: 1, + ContractID: "ctr_1", + PropertyID: 11, + PropertyName: "Name1", + Type: "Type1", + }, + { + GroupID: 2, + ContractID: "ctr_2", + PropertyID: 22, + PropertyName: "Name2", + Type: "Type2", + }, + }, + }, + }, + "happy path - no optional attributes": { + configPath: "testdata/TestDataProperties/no_attributes.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWProperties) { + expectListProperties(m, testData, 5) + }, + mockData: testDataForCWProperties{ + properties: []cloudwrapper.Property{ + { + GroupID: 1, + ContractID: "ctr_1", + PropertyID: 11, + PropertyName: "Name1", + Type: "Type1", + }, + }, + }, + }, + "happy path - empty properties list": { + configPath: "testdata/TestDataProperties/default_unused_false.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWProperties) { + expectListProperties(m, testData, 5) + }, + mockData: testDataForCWProperties{ + contractIDs: []string{"ctr_1", "ctr_2"}, + properties: []cloudwrapper.Property{}, + }, + }, + "error listing properties": { + configPath: "testdata/TestDataProperties/default_unused_false.tf", + init: func(t *testing.T, m *cloudwrapper.Mock, testData testDataForCWProperties) { + expectListPropertiesWithError(m, testData, 1) + }, + mockData: testDataForCWProperties{ + contractIDs: []string{"ctr_1", "ctr_2"}, + }, + error: regexp.MustCompile("list properties failed"), + }, + } + for name, test := range tests { + t.Run(name, func(t *testing.T) { + client := &cloudwrapper.Mock{} + if test.init != nil { + test.init(t, client, test.mockData) + } + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + IsUnitTest: true, + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, test.configPath), + Check: checkCloudWrapperPropertiesAttrs(test.mockData), + ExpectError: test.error, + }, + }, + }) + + client.AssertExpectations(t) + }) + } +} + +type testDataForCWProperties struct { + unused bool + contractIDs []string + properties []cloudwrapper.Property +} + +func checkCloudWrapperPropertiesAttrs(data testDataForCWProperties) resource.TestCheckFunc { + var checkFuncs []resource.TestCheckFunc + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", "contract_ids.#", strconv.Itoa(len(data.contractIDs)))) + for i, ctr := range data.contractIDs { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("contract_ids.%d", i), ctr)) + } + + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", "properties.#", strconv.Itoa(len(data.properties)))) + for i, prp := range data.properties { + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("properties.%d.property_id", i), strconv.FormatInt(prp.PropertyID, 10))) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("properties.%d.type", i), string(prp.Type))) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("properties.%d.property_name", i), prp.PropertyName)) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("properties.%d.contract_id", i), prp.ContractID)) + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr("data.akamai_cloudwrapper_properties.test", fmt.Sprintf("properties.%d.group_id", i), strconv.FormatInt(prp.GroupID, 10))) + } + checkFuncs = append(checkFuncs, resource.TestCheckResourceAttrSet("data.akamai_cloudwrapper_properties.test", "id")) + + return resource.ComposeAggregateTestCheckFunc(checkFuncs...) +} + +func expectListProperties(client *cloudwrapper.Mock, data testDataForCWProperties, timesToRun int) { + listPropertiesReq := cloudwrapper.ListPropertiesRequest{ + Unused: data.unused, + ContractIDs: data.contractIDs, + } + listPropertiesRes := cloudwrapper.ListPropertiesResponse{ + Properties: data.properties, + } + client.On("ListProperties", mock.Anything, listPropertiesReq).Return(&listPropertiesRes, nil).Times(timesToRun) +} + +func expectListPropertiesWithError(client *cloudwrapper.Mock, data testDataForCWProperties, timesToRun int) { + listPropertiesReq := cloudwrapper.ListPropertiesRequest{ + Unused: data.unused, + ContractIDs: data.contractIDs, + } + client.On("ListProperties", mock.Anything, listPropertiesReq).Return(nil, fmt.Errorf("list properties failed")).Times(timesToRun) +} diff --git a/pkg/providers/cloudwrapper/provider.go b/pkg/providers/cloudwrapper/provider.go new file mode 100644 index 000000000..b915b8223 --- /dev/null +++ b/pkg/providers/cloudwrapper/provider.go @@ -0,0 +1,42 @@ +// Package cloudwrapper contains implementation for Akamai Terraform sub-provider responsible for cloud wrapper +package cloudwrapper + +import ( + "github.com/akamai/terraform-provider-akamai/v5/pkg/subprovider" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +type ( + // Subprovider gathers cloud wrapper resources and data sources written using terraform-plugin-framework + Subprovider struct{} +) + +var ( + _ subprovider.Framework = &Subprovider{} +) + +// NewSubprovider returns a core Framework based sub provider +func NewSubprovider() *Subprovider { + return &Subprovider{} +} + +// Resources returns terraform resources for cloudwrapper +func (p *Subprovider) Resources() []func() resource.Resource { + return []func() resource.Resource{ + NewActivationResource, + NewConfigurationResource, + } +} + +// DataSources returns terraform data sources for cloudwrapper +func (p *Subprovider) DataSources() []func() datasource.DataSource { + return []func() datasource.DataSource{ + NewCapacitiesDataSource, + NewConfigurationDataSource, + NewConfigurationsDataSource, + NewLocationDataSource, + NewLocationsDataSource, + NewPropertiesDataSource, + } +} diff --git a/pkg/providers/cloudwrapper/provider_test.go b/pkg/providers/cloudwrapper/provider_test.go new file mode 100644 index 000000000..5ee6270ed --- /dev/null +++ b/pkg/providers/cloudwrapper/provider_test.go @@ -0,0 +1,133 @@ +package cloudwrapper + +import ( + "context" + "log" + "os" + "testing" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/akamai" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" +) + +type ( + TestSubprovider struct { + resources []func() resource.Resource + datasources []func() datasource.DataSource + client cloudwrapper.CloudWrapper + interval time.Duration + } + + clientSetter interface { + setClient(cloudwrapper.CloudWrapper) + } + + pollIntervalSetter interface { + setPollInterval(time.Duration) + } + + testSubproviderOption func(*TestSubprovider) +) + +func withMockClient(mock cloudwrapper.CloudWrapper) testSubproviderOption { + return func(ts *TestSubprovider) { + ts.client = mock + ts.interval = time.Microsecond + } +} + +func withInterval(interval time.Duration) testSubproviderOption { + return func(ts *TestSubprovider) { + ts.interval = interval + } +} + +func newTestSubprovider(opts ...testSubproviderOption) *TestSubprovider { + s := NewSubprovider() + + ts := &TestSubprovider{ + resources: s.Resources(), + datasources: s.DataSources(), + } + + for _, opt := range opts { + opt(ts) + } + + return ts +} + +// Resources returns terraform resources for cloudwrapper +func (ts *TestSubprovider) Resources() []func() resource.Resource { + for i, fn := range ts.resources { + // decorate + fn := fn + ts.resources[i] = func() resource.Resource { + res := fn() + if v, ok := res.(clientSetter); ok { + v.setClient(ts.client) + } + if v, ok := res.(pollIntervalSetter); ok { + v.setPollInterval(ts.interval) + } + return res + } + } + return ts.resources +} + +// DataSources returns terraform data sources for cloudwrapper +func (ts *TestSubprovider) DataSources() []func() datasource.DataSource { + for i, fn := range ts.datasources { + fn := fn + // decorate + ts.datasources[i] = func() datasource.DataSource { + ds := fn() + if v, ok := ds.(clientSetter); ok { + v.setClient(ts.client) + } + return ds + } + } + return ts.datasources +} + +func TestMain(m *testing.M) { + if err := testutils.TFTestSetup(); err != nil { + log.Fatal(err) + } + exitCode := m.Run() + if err := testutils.TFTestTeardown(); err != nil { + log.Fatal(err) + } + os.Exit(exitCode) +} + +func newProviderFactory(opts ...testSubproviderOption) map[string]func() (tfprotov5.ProviderServer, error) { + testAccProvider := akamai.NewFrameworkProvider(newTestSubprovider(opts...))() + + return map[string]func() (tfprotov5.ProviderServer, error){ + "akamai": func() (tfprotov5.ProviderServer, error) { + ctx := context.Background() + providers := []func() tfprotov5.ProviderServer{ + providerserver.NewProtocol5( + testAccProvider, + ), + } + + muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...) + if err != nil { + return nil, err + } + + return muxServer.ProviderServer(), nil + }, + } +} diff --git a/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation.go b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation.go new file mode 100644 index 000000000..55259beb0 --- /dev/null +++ b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation.go @@ -0,0 +1,353 @@ +package cloudwrapper + +import ( + "context" + "fmt" + "strconv" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ resource.Resource = &activationResource{} + _ resource.ResourceWithConfigure = &activationResource{} + _ resource.ResourceWithModifyPlan = &activationResource{} + _ resource.ResourceWithImportState = &activationResource{} +) + +var ( + activationTimeout = 4 * time.Hour + onlyTimeoutChangeWarn = diag.NewWarningDiagnostic("Update in Place", "requested only timeout change; API won't be called") +) + +const readError = "could not read Config from API" + +type activationResource struct { + client cloudwrapper.CloudWrapper + activationPollInterval time.Duration +} + +// ModifyPlan implements resource.ResourceWithModifyPlan +func (a *activationResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + if req.Plan.Raw.IsNull() { + resp.Diagnostics.AddWarning("Deactivation is not Available", "currently it's not possible to deactivate configuration; removing only local state") + return + } + + var state, plan *activationResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + if resp.Diagnostics.HasError() { + return + } + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + if onlyChangeInTimeout(state, plan) { + resp.Diagnostics.Append(onlyTimeoutChangeWarn) + } +} + +// NewActivationResource returns new cloud wrapper activation resource +func NewActivationResource() resource.Resource { + return &activationResource{} +} + +// Metadata implements resource.Resource +func (a *activationResource) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_activation" +} + +func (a *activationResource) setClient(client cloudwrapper.CloudWrapper) { + a.client = client +} + +func (a *activationResource) setPollInterval(interval time.Duration) { + a.activationPollInterval = interval +} + +// Schema implements resource.Resource +func (a *activationResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "config_id": schema.Int64Attribute{ + Required: true, + Description: "The configuration you want to activate.", + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.RequiresReplace(), + }, + }, + "revision": schema.StringAttribute{ + Required: true, + Description: "Unique hash value of the configuration.", + }, + "id": schema.StringAttribute{ + Computed: true, + Description: "ID of the resource.", + DeprecationMessage: "Required by the terraform plugin testing framework, always set to `akamai_cloudwrapper_activation`.", + }, + }, + Blocks: map[string]schema.Block{ + "timeouts": timeouts.Block(ctx, + timeouts.Opts{ + Create: true, + CreateDescription: "Optional configurable activation timeout to be used on resource create. By default it's 4h with 1s pooling interval.", + Update: true, + UpdateDescription: "Optional configurable activation timeout to be used on resource update. By default it's 4h with 1s pooling interval.", + }, + ), + }, + } +} + +// Configure implements implements resource.ResourceWithConfigure +func (a *activationResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + a.configureResource(req, resp) + if a.activationPollInterval == 0 { + a.activationPollInterval = time.Minute + } +} + +func (a *activationResource) configureResource(req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + if a.client != nil { + return + } + + meta, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + a.client = cloudwrapper.Client(meta.Session()) +} + +type activationResourceModel struct { + ID types.String `tfsdk:"id"` + ConfigID types.Int64 `tfsdk:"config_id"` + Revision types.String `tfsdk:"revision"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +// Create implements resource.Resource +func (a *activationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Creating Activation Resource") + + var data activationResourceModel + + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + createTimeout, diags := data.Timeouts.Create(ctx, activationTimeout) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + newState, diags := a.upsert(ctx, data, createTimeout) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + newState.Timeouts = data.Timeouts + newState.ID = types.StringValue("akamai_cloudwrapper_activation") + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) +} + +func (a *activationResource) upsert(ctx context.Context, data activationResourceModel, activationTimeout time.Duration) (*activationResourceModel, diag.Diagnostics) { + var diags diag.Diagnostics + + configID := int(data.ConfigID.ValueInt64()) + err := a.client.ActivateConfiguration(ctx, cloudwrapper.ActivateConfigurationRequest{ConfigurationIDs: []int{configID}}) + if err != nil { + diags.AddError("Activating Configuration Failed", err.Error()) + return nil, diags + } + + diags.Append(a.waitUntilActivationCompleted(ctx, configID, activationTimeout)...) + if diags.HasError() { + return nil, diags + } + + newState, err := a.readStateFromAPI(ctx, data, int64(configID)) + if err != nil { + diags.AddError(readError, err.Error()) + return nil, diags + } + return newState, diags +} + +func (a *activationResource) readStateFromAPI(ctx context.Context, model activationResourceModel, configID int64) (*activationResourceModel, error) { + configuration, err := a.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ConfigID: configID}) + if err != nil { + return nil, err + } + if configuration.Status == cloudwrapper.StatusActive { + model.ConfigID = types.Int64Value(configuration.ConfigID) + model.Revision = types.StringValue(calculateRevision(configuration)) + } else { + model.ConfigID = types.Int64Null() + model.Revision = types.StringNull() + } + return &model, nil +} + +func (a *activationResource) waitUntilActivationCompleted(ctx context.Context, configID int, timeout time.Duration) diag.Diagnostics { + var diags diag.Diagnostics + + timeoutCtx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() + + for { + configuration, err := a.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ConfigID: int64(configID)}) + if err != nil { + diags.AddError(readError, err.Error()) + return diags + } + if configuration.Status == cloudwrapper.StatusActive { + return diags + } + + select { + case <-time.After(a.activationPollInterval): + continue + case <-timeoutCtx.Done(): + diags.AddError("Reached Activation Timeout", timeoutCtx.Err().Error()) + return diags + } + } +} + +// Read implements resource.Resource +func (a *activationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Reading Activation Resource") + + var data activationResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + newState, err := a.readStateFromAPI(ctx, data, data.ConfigID.ValueInt64()) + if err != nil { + resp.Diagnostics.AddError(readError, err.Error()) + return + } + + if newState.ConfigID.IsNull() { + resp.State.RemoveResource(ctx) + } else { + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) + } +} + +// Update implements resource.Resource +func (a *activationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Updating Activation Resource") + + var plan, oldState *activationResourceModel + + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(req.State.Get(ctx, &oldState)...) + if resp.Diagnostics.HasError() { + return + } + + if onlyChangeInTimeout(oldState, plan) { + oldState.Timeouts = plan.Timeouts + resp.Diagnostics.Append(resp.State.Set(ctx, oldState)...) + return + } + + updateTimeout, diags := plan.Timeouts.Update(ctx, activationTimeout) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + newState, diags := a.upsert(ctx, *plan, updateTimeout) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + newState.Timeouts = plan.Timeouts + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) +} + +func onlyChangeInTimeout(state, plan *activationResourceModel) bool { + return state != nil && plan != nil && + plan.ConfigID == state.ConfigID && + plan.Revision == state.Revision && + !plan.Timeouts.Equal(state.Timeouts) +} + +// Delete implements resource.Resource +func (a *activationResource) Delete(ctx context.Context, _ resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Deleting Activation Resource") + resp.State.RemoveResource(ctx) +} + +// ImportState implements resource.ResourceWithImportState +func (a *activationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Importing Activation Resource") + + configID, err := strconv.Atoi(req.ID) + if err != nil { + resp.Diagnostics.AddError("Activation Resource ID has incorrect Value", err.Error()) + return + } + config := activationResourceModel{ + Timeouts: getDefaultTimeoutValue(), + } + newState, err := a.readStateFromAPI(ctx, config, int64(configID)) + if err != nil { + resp.Diagnostics.AddError(readError, err.Error()) + return + } + + if newState.ConfigID.IsNull() { + resp.Diagnostics.AddError("Import Failed", "configuration must be active prior to import; activate configuration instead") + return + } + + newState.ID = types.StringValue("akamai_cloudwrapper_activation") + resp.Diagnostics.Append(resp.State.Set(ctx, newState)...) +} + +func getDefaultTimeoutValue() timeouts.Value { + return timeouts.Value{ + Object: types.ObjectNull(map[string]attr.Type{ + "create": types.StringType, + "update": types.StringType, + }), + } +} diff --git a/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation_test.go b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation_test.go new file mode 100644 index 000000000..66eea0df3 --- /dev/null +++ b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_activation_test.go @@ -0,0 +1,235 @@ +package cloudwrapper + +import ( + "regexp" + "testing" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/stretchr/testify/mock" +) + +func TestActivation(t *testing.T) { + t.Parallel() + tests := map[string]struct { + init func() *cloudwrapper.Mock + steps []resource.TestStep + }{ + "activation lifecycle": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + //not yet activated + mockGetConfiguration(client, 123, cloudwrapper.StatusInProgress, "location comment").Once() + //activated + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "location comment").Times(3) + //refresh after modifying configuration + mockGetConfiguration(client, 123, cloudwrapper.StatusSaved, "other comment").Once() + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusInProgress, "other comment").Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "other comment").Times(3) + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/update.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "8b92934d68d69621153c"), + ), + }, + }, + }, + "import": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "location comment").Times(5) + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + { + ImportState: true, + ImportStateId: "123", + ResourceName: "akamai_cloudwrapper_activation.act", + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + }, + }, + "import of inactive config": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "location comment").Times(3) + mockGetConfiguration(client, 123, cloudwrapper.StatusFailed, "location comment").Once() + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + { + ImportState: true, + ImportStateId: "123", + ResourceName: "akamai_cloudwrapper_activation.act", + ExpectError: regexp.MustCompile("configuration must be active prior to import; activate configuration instead"), + }, + }, + }, + "force new on config_id": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "location comment").Times(4) + mockActivateConfig(client, []int{321}, nil).Once() + mockGetConfiguration(client, 321, cloudwrapper.StatusActive, "location comment").Times(3) + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/update_forcenew.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "321"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + }, + }, + "missing required fields": { + init: func() *cloudwrapper.Mock { + return &cloudwrapper.Mock{} + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create_missing_required.tf"), + ExpectError: regexp.MustCompile(`The argument "revision" is required, but no definition was found.`), + }, + }, + }, + "timeout on create": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusInProgress, "location comment") //timeout sometimes triggers after 2 calls, sometimes after 3 - no Times(x) + + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create_timeout.tf"), + ExpectError: regexp.MustCompile(`Reached Activation Timeout`), + }, + }, + }, + "timeout on update": { + init: func() *cloudwrapper.Mock { + client := &cloudwrapper.Mock{} + + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusActive, "location comment").Times(3) + mockGetConfiguration(client, 123, cloudwrapper.StatusSaved, "other comment").Once() + mockActivateConfig(client, []int{123}, nil).Once() + mockGetConfiguration(client, 123, cloudwrapper.StatusInProgress, "other comment") + + return client + }, + steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/create_timeout.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "id", "akamai_cloudwrapper_activation"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "config_id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_activation.act", "revision", "5fe7963eb7270e69c5e8"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResActivation/update_timeout.tf"), + ExpectError: regexp.MustCompile(`Reached Activation Timeout`), + }, + }, + }, + } + + for name, test := range tests { + name, test := name, test + t.Run(name, func(t *testing.T) { + t.Parallel() + client := test.init() + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client), withInterval(time.Second)), + Steps: test.steps, + }) + client.AssertExpectations(t) + }) + } +} + +func mockActivateConfig(client *cloudwrapper.Mock, configIDs []int, err error) *mock.Call { + return client.On("ActivateConfiguration", mock.Anything, cloudwrapper.ActivateConfigurationRequest{ConfigurationIDs: configIDs}).Return(err) +} + +func mockGetConfiguration(client *cloudwrapper.Mock, configID int, returnStatus cloudwrapper.StatusType, locationComment string) *mock.Call { + return client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ConfigID: int64(configID)}). + Return(&cloudwrapper.Configuration{ + Comments: "some comment", + ConfigName: "testconfig", + ContractID: "1-CTRACT", + ConfigID: int64(configID), + Locations: []cloudwrapper.ConfigLocationResp{ + { + Comments: locationComment, + TrafficTypeID: 2, + Capacity: cloudwrapper.Capacity{ + Unit: "GB", + Value: 1, + }, + }, + }, + Status: returnStatus, + NotificationEmails: []string{"test@test.com"}, + PropertyIDs: []string{"1234567"}, + }, nil) +} diff --git a/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration.go b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration.go new file mode 100644 index 000000000..5913c23d6 --- /dev/null +++ b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration.go @@ -0,0 +1,506 @@ +package cloudwrapper + +import ( + "context" + "errors" + "fmt" + "strconv" + "time" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/modifiers" + "github.com/akamai/terraform-provider-akamai/v5/pkg/meta" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/objectvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "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/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ resource.Resource = &ConfigurationResource{} + _ resource.ResourceWithConfigure = &ConfigurationResource{} + _ resource.ResourceWithModifyPlan = &ConfigurationResource{} + _ resource.ResourceWithImportState = &ConfigurationResource{} +) + +// ConfigurationResource represents akamai_cloudwrapper_configuration resource +type ConfigurationResource struct { + client cloudwrapper.CloudWrapper + deleteTimeout time.Duration + pollInterval time.Duration +} + +func (r *ConfigurationResource) setClient(client cloudwrapper.CloudWrapper) { + r.client = client +} + +func (r *ConfigurationResource) setPollInterval(duration time.Duration) { + r.pollInterval = duration +} + +// NewConfigurationResource returns new cloud wrapper configuration resource +func NewConfigurationResource() resource.Resource { + return &ConfigurationResource{ + deleteTimeout: 2 * time.Hour, + pollInterval: 30 * time.Second, + } +} + +// Metadata implements resource.Resource. +func (r *ConfigurationResource) Metadata(_ context.Context, _ resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = "akamai_cloudwrapper_configuration" +} + +// Schema implements resource.Resource. +func (r *ConfigurationResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "contract_id": schema.StringAttribute{ + Required: true, + Description: "Contract ID having Cloud Wrapper entitlement.", + PlanModifiers: []planmodifier.String{ + modifiers.StringUseStateIf(modifiers.EqualUpToPrefixFunc("ctr_")), + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "config_name": schema.StringAttribute{ + Required: true, + Description: "Name of the configuration.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "property_ids": schema.SetAttribute{ + Required: true, + ElementType: types.StringType, + Description: "List of properties belonging to eligible products.", + PlanModifiers: []planmodifier.Set{ + modifiers.SetUseStateIf(modifiers.EqualUpToPrefixFunc("prp_")), + }, + }, + "comments": schema.StringAttribute{ + Required: true, + Description: "Additional information you provide to differentiate or track changes of the configuration.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + PlanModifiers: []planmodifier.String{ + modifiers.PreventStringUpdate(), + }, + }, + "retain_idle_objects": schema.BoolAttribute{ + Optional: true, + Computed: true, + Description: "Retain idle objects beyond their max idle lifetime.", + Default: booldefault.StaticBool(false), + }, + "capacity_alerts_threshold": schema.Int64Attribute{ + Optional: true, + Description: "Capacity Alerts enablement information for the configuration. " + + "The Alert Threshold should be between 50 and 100.", + Validators: []validator.Int64{ + int64validator.Between(50, 100), + }, + }, + "notification_emails": schema.SetAttribute{ + ElementType: types.StringType, + Optional: true, + Computed: true, + Description: "Email addresses to use for notifications.", + PlanModifiers: []planmodifier.Set{ + setplanmodifier.UseStateForUnknown(), + }, + }, + "revision": schema.StringAttribute{ + Computed: true, + Description: "Unique hash value of the configuration.", + }, + "id": schema.Int64Attribute{ + Computed: true, + Description: "Resource's unique identifier.", + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + }, + Blocks: map[string]schema.Block{ + "location": schema.SetNestedBlock{ + Description: "List of locations to use with the configuration.", + Validators: []validator.Set{ + setvalidator.IsRequired(), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "comments": schema.StringAttribute{ + Required: true, + Description: "Additional comments provided by the user.", + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "traffic_type_id": schema.Int64Attribute{ + Required: true, + Description: "Unique identifier for the location and traffic type combination", + }, + }, + Blocks: map[string]schema.Block{ + "capacity": schema.SingleNestedBlock{ + Description: "The capacity assigned to this configuration's location", + Validators: []validator.Object{ + objectvalidator.IsRequired(), + }, + Attributes: map[string]schema.Attribute{ + "value": schema.Int64Attribute{ + Required: true, + Description: "Value of capacity.", + }, + "unit": schema.StringAttribute{ + Required: true, + Description: "Unit of capacity. Can be either 'GB' or 'TB'.", + Validators: []validator.String{ + stringvalidator.OneOf( + string(cloudwrapper.UnitGB), + string(cloudwrapper.UnitTB), + ), + }, + }, + }, + }, + }, + }, + }, + "timeouts": timeouts.Block(ctx, timeouts.Opts{ + Delete: true, + CreateDescription: "Optional configurable resource delete timeout. By default it's 2h with 30s pooling interval.", + }), + }, + } +} + +// Configure implements resource.ResourceWithConfigure. +func (r *ConfigurationResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + if r.client != nil { + return + } + + meta, ok := req.ProviderData.(meta.Meta) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *http.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + r.client = cloudwrapper.Client(meta.Session()) +} + +// ModifyPlan implements resource.ResourceWithModifyPlan. +func (*ConfigurationResource) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { + // config will be deleted + if req.Plan.Raw.IsNull() { + resp.Diagnostics.AddWarning("Deletion May Not Succeed", + "Only Akamai internal users can delete configurations. I you are not internal user, "+ + "the configuration will only be removed from state") + return + } + + var plan *ConfigurationResourceModel + resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) + if resp.Diagnostics.HasError() { + return + } + + if plan.hasUnknown() { + return + } + + plan.Revision = types.StringValue(plan.revision(ctx)) + resp.Diagnostics.Append(resp.Plan.Set(ctx, plan)...) + + var state *ConfigurationResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &state)...) + + if onlyTimeoutChanged(state, plan) { + resp.Diagnostics.Append(onlyTimeoutChangeWarn) + } +} + +func onlyTimeoutChanged(state, plan *ConfigurationResourceModel) bool { + return state != nil && plan != nil && + state.Revision == plan.Revision && + !state.Timeouts.Equal(plan.Timeouts) +} + +// Create implements resource.Resource. +func (r *ConfigurationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + tflog.Debug(ctx, "Creating Configuration Resource") + + var data *ConfigurationResourceModel + + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(r.create(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConfigurationResource) create(ctx context.Context, data *ConfigurationResourceModel) diag.Diagnostics { + var diags diag.Diagnostics + + resp, err := r.client.CreateConfiguration(ctx, data.buildCreateRequest(ctx)) + if err != nil { + diags.AddError("Create Failed", err.Error()) + return diags + } + + return data.populateFrom(ctx, resp) +} + +var diagErrConfigurationNotFound = diag.NewErrorDiagnostic("Cannot Find Configuration", "") + +// Read implements resource.Resource. +func (r *ConfigurationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + tflog.Debug(ctx, "Reading Configuration Resource") + + var data *ConfigurationResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + diags := r.read(ctx, data) + if diags.Contains(diagErrConfigurationNotFound) { + resp.State.RemoveResource(ctx) + return + } + if diags.HasError() { + resp.Diagnostics.Append(diags...) + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConfigurationResource) read(ctx context.Context, data *ConfigurationResourceModel) diag.Diagnostics { + var diags diag.Diagnostics + + result, err := r.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ + ConfigID: data.ID.ValueInt64(), + }) + if errors.Is(err, cloudwrapper.ErrConfigurationNotFound) { + diags.Append(diagErrConfigurationNotFound) + return diags + } + if err != nil { + diags.AddError("Reading Configuration Failed", err.Error()) + return diags + } + + if result.MultiCDNSettings != nil { + diags.AddError("Configuration Contains Multi CDN Settings", + "Cloud Wrapper Configuration resource does not currently support Mutli CDN settings. "+ + "This error is caused by a configuration drift. "+ + "Make sure to remove Mutli CDN settings before continuing.") + return diags + } + + return data.populateFrom(ctx, result) +} + +// Update implements resource.Resource. +func (r *ConfigurationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + tflog.Debug(ctx, "Updating Configuration Resource") + + var data *ConfigurationResourceModel + + resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + var oldState *ConfigurationResourceModel + resp.Diagnostics.Append(req.State.Get(ctx, &oldState)...) + if resp.Diagnostics.HasError() { + return + } + + if onlyTimeoutChanged(oldState, data) { + oldState.Timeouts = data.Timeouts + resp.Diagnostics.Append(resp.State.Set(ctx, &oldState)...) + return + } + + resp.Diagnostics.Append(r.update(ctx, data)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} + +func (r *ConfigurationResource) update(ctx context.Context, data *ConfigurationResourceModel) diag.Diagnostics { + var diags diag.Diagnostics + + resp, err := r.client.UpdateConfiguration(ctx, data.buildUpdateRequest(ctx)) + if err != nil { + diags.AddError("Update Failed", err.Error()) + return diags + } + + return data.populateFrom(ctx, resp) +} + +// Delete implements resource.Resource. +func (r *ConfigurationResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Debug(ctx, "Deleting Configuration Resource") + + var data *ConfigurationResourceModel + + resp.Diagnostics.Append(req.State.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + + deleteTimeout, diags := data.Timeouts.Delete(ctx, r.deleteTimeout) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + ctx, cancel := context.WithTimeout(ctx, deleteTimeout) + defer cancel() + + isPending, diags := r.isPendingDelete(ctx, data.ID.ValueInt64()) + if diags.HasError() { + resp.Diagnostics.Append(diags...) + return + } + if isPending { + resp.Diagnostics.Append(r.waitForDelete(ctx, data.ID.ValueInt64())...) + return + } + + err := r.client.DeleteConfiguration(ctx, cloudwrapper.DeleteConfigurationRequest{ + ConfigID: data.ID.ValueInt64(), + }) + if errors.Is(err, cloudwrapper.ErrDeletionNotAllowed) { + resp.Diagnostics.AddWarning("Deletion Unsuccessful", + "Configuration only removed from state. "+ + fmt.Sprintf("To completely remove this configuration [id=%d], contact your akamai representative.", data.ID.ValueInt64())) + return + } + if err != nil { + resp.Diagnostics.AddError("Deletion Failed", err.Error()) + return + } + + resp.Diagnostics.Append(r.waitForDelete(ctx, data.ID.ValueInt64())...) +} + +func (r *ConfigurationResource) isPendingDelete(ctx context.Context, id int64) (bool, diag.Diagnostics) { + var diags diag.Diagnostics + resp, err := r.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ + ConfigID: id, + }) + if err != nil { + diags.AddError("Error Retreiving Configutation", err.Error()) + return false, diags + } + + return resp.Status == cloudwrapper.StatusDeleteInProgress, diags +} + +func (r *ConfigurationResource) waitForDelete(ctx context.Context, id int64) diag.Diagnostics { + var diags diag.Diagnostics + for { + _, err := r.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ + ConfigID: id, + }) + if errors.Is(err, cloudwrapper.ErrConfigurationNotFound) { + return diags + } + + select { + case <-time.Tick(r.pollInterval): + continue + case <-ctx.Done(): + diags.AddError("Deletion Terminated", + "context terminated the wait for deletion to finish") + return diags + } + } +} + +// ImportState implements resource.ResourceWithImportState. +func (r *ConfigurationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + tflog.Debug(ctx, "Importing Configuration Resource") + + var data = &ConfigurationResourceModel{} + + configID, err := strconv.ParseInt(req.ID, 10, 64) + if err != nil { + resp.Diagnostics.AddError("Incorrect ID", err.Error()) + return + } + + result, err := r.client.GetConfiguration(ctx, cloudwrapper.GetConfigurationRequest{ + ConfigID: configID, + }) + if err != nil { + resp.Diagnostics.AddError("Cannot Find Configuration", err.Error()) + return + } + + if result.MultiCDNSettings != nil { + resp.Diagnostics.AddError("Cannot Import", + "Importing configuration with Multi CDN is not supported") + return + } + + data.Timeouts = timeouts.Value{ + Object: types.ObjectNull(map[string]attr.Type{ + "delete": types.StringType, + }), + } + + resp.Diagnostics.Append(data.populateFrom(ctx, result)...) + if resp.Diagnostics.HasError() { + return + } + + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_model.go b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_model.go new file mode 100644 index 000000000..3b8ef1714 --- /dev/null +++ b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_model.go @@ -0,0 +1,287 @@ +package cloudwrapper + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/hex" + "sort" + "strconv" + "strings" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/modifiers" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/framework/replacer" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +// ConfigurationResourceModel is a model for akamai_cloudwrapper_configuration resource +type ConfigurationResourceModel struct { + ID types.Int64 `tfsdk:"id"` + ConfigName types.String `tfsdk:"config_name"` + ContractID types.String `tfsdk:"contract_id"` + PropertyIDs types.Set `tfsdk:"property_ids"` + Revision types.String `tfsdk:"revision"` + Comments types.String `tfsdk:"comments"` + RetainIdleObjects types.Bool `tfsdk:"retain_idle_objects"` + NotificationEmails types.Set `tfsdk:"notification_emails"` + CapacityAlertsThreshold types.Int64 `tfsdk:"capacity_alerts_threshold"` + Locations []ConfigLocation `tfsdk:"location"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +// ConfigLocation represents location item +type ConfigLocation struct { + Comments types.String `tfsdk:"comments"` + TrafficTypeID types.Int64 `tfsdk:"traffic_type_id"` + Capacity LocationCapacity `tfsdk:"capacity"` +} + +// LocationCapacity holds capacity details for some location +type LocationCapacity struct { + Value types.Int64 `tfsdk:"value"` + Unit types.String `tfsdk:"unit"` +} + +func (m *ConfigurationResourceModel) hasUnknown() bool { + for _, loc := range m.Locations { + if loc.TrafficTypeID.IsUnknown() || + loc.Comments.IsUnknown() || + loc.Capacity.Unit.IsUnknown() || + loc.Capacity.Value.IsUnknown() { + return true + } + } + + return m.ID.IsUnknown() || + m.ConfigName.IsUnknown() || + m.ContractID.IsUnknown() || + m.PropertyIDs.IsUnknown() || + m.Comments.IsUnknown() || + m.RetainIdleObjects.IsUnknown() || + m.NotificationEmails.IsUnknown() || + m.CapacityAlertsThreshold.IsUnknown() +} + +func (m *ConfigurationResourceModel) buildCreateRequest(ctx context.Context) cloudwrapper.CreateConfigurationRequest { + return cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + CapacityAlertsThreshold: m.getCapacityAlertsThreshold(), + Comments: m.Comments.ValueString(), + ContractID: m.ContractID.ValueString(), + Locations: m.getLocationsReq(), + MultiCDNSettings: nil, + ConfigName: m.ConfigName.ValueString(), + PropertyIDs: m.getPropertyIDs(ctx), + RetainIdleObjects: m.RetainIdleObjects.ValueBool(), + NotificationEmails: m.getNotificationEmails(ctx), + }, + } +} + +func (m *ConfigurationResourceModel) buildUpdateRequest(ctx context.Context) cloudwrapper.UpdateConfigurationRequest { + return cloudwrapper.UpdateConfigurationRequest{ + ConfigID: m.ID.ValueInt64(), + Body: cloudwrapper.UpdateConfigurationBody{ + CapacityAlertsThreshold: m.getCapacityAlertsThreshold(), + Comments: m.Comments.ValueString(), + Locations: m.getLocationsReq(), + MultiCDNSettings: nil, + NotificationEmails: m.getNotificationEmails(ctx), + PropertyIDs: m.getPropertyIDs(ctx), + RetainIdleObjects: m.RetainIdleObjects.ValueBool(), + }, + } +} + +func (m *ConfigurationResourceModel) populateFrom(ctx context.Context, config *cloudwrapper.Configuration) diag.Diagnostics { + var diags diag.Diagnostics + + m.ID = types.Int64Value(config.ConfigID) + m.ConfigName = types.StringValue(config.ConfigName) + m.Comments = types.StringValue(config.Comments) + m.RetainIdleObjects = types.BoolValue(config.RetainIdleObjects) + + m.setContractID(config.ContractID) + m.setLocations(config.Locations) + + if config.CapacityAlertsThreshold == nil { + m.CapacityAlertsThreshold = types.Int64Null() + } else { + m.CapacityAlertsThreshold = types.Int64Value(int64(*config.CapacityAlertsThreshold)) + } + + diags.Append(m.setPropertyIDs(ctx, config.PropertyIDs)...) + if diags.HasError() { + return diags + } + + diags.Append(m.setNotificationEmails(ctx, config.NotificationEmails)...) + if diags.HasError() { + return diags + } + + m.Revision = types.StringValue(calculateRevision(config)) + + return diags +} + +func (m *ConfigurationResourceModel) getCapacityAlertsThreshold() *int { + var capacityAlertsThreshold *int + if !m.CapacityAlertsThreshold.IsNull() { + cat := int(m.CapacityAlertsThreshold.ValueInt64()) + capacityAlertsThreshold = &cat + } + return capacityAlertsThreshold +} + +func (m *ConfigurationResourceModel) getPropertyIDs(ctx context.Context) []string { + var propertyIDs []string + m.PropertyIDs.ElementsAs(ctx, &propertyIDs, false) + + for i := range propertyIDs { + propertyIDs[i] = strings.TrimPrefix(propertyIDs[i], "prp_") + } + + return propertyIDs +} + +func (m *ConfigurationResourceModel) setPropertyIDs(ctx context.Context, propIDs []string) diag.Diagnostics { + var mProps []string + if !m.PropertyIDs.IsNull() { + diags := m.PropertyIDs.ElementsAs(ctx, &mProps, false) + if diags.HasError() { + return diags + } + } + + replaced := replacer.Replacer{ + Source: propIDs, + Replacements: mProps, + EqFunc: modifiers.EqualUpToPrefixFunc("prp_"), + }.Replace() + + newPropIDs, diags := types.SetValueFrom(ctx, types.StringType, replaced) + if diags.HasError() { + return diags + } + + m.PropertyIDs = newPropIDs + + return diags +} + +func (m *ConfigurationResourceModel) setContractID(contract string) { + if strings.TrimPrefix(contract, "ctr_") == strings.TrimPrefix(m.ContractID.ValueString(), "ctr_") { + return + } + m.ContractID = types.StringValue(contract) +} + +func (m *ConfigurationResourceModel) setNotificationEmails(ctx context.Context, emails []string) diag.Diagnostics { + notificationEmails, diags := types.SetValueFrom(ctx, types.StringType, emails) + if diags.HasError() { + return diags + } + m.NotificationEmails = notificationEmails + return diags +} + +func (m *ConfigurationResourceModel) getNotificationEmails(ctx context.Context) []string { + var emails []string + m.NotificationEmails.ElementsAs(ctx, &emails, false) + return emails +} + +func (m *ConfigurationResourceModel) setLocations(locs []cloudwrapper.ConfigLocationResp) { + m.Locations = make([]ConfigLocation, 0, len(locs)) + for _, loc := range locs { + m.Locations = append(m.Locations, ConfigLocation{ + Comments: types.StringValue(loc.Comments), + TrafficTypeID: types.Int64Value(int64(loc.TrafficTypeID)), + Capacity: LocationCapacity{ + Value: types.Int64Value(int64(loc.Capacity.Value)), + Unit: types.StringValue(string(loc.Capacity.Unit)), + }, + }) + } +} + +func (m *ConfigurationResourceModel) getLocationsReq() []cloudwrapper.ConfigLocationReq { + locations := make([]cloudwrapper.ConfigLocationReq, 0, len(m.Locations)) + for _, loc := range m.Locations { + locations = append(locations, cloudwrapper.ConfigLocationReq{ + Comments: loc.Comments.ValueString(), + TrafficTypeID: int(loc.TrafficTypeID.ValueInt64()), + Capacity: cloudwrapper.Capacity{ + Value: loc.Capacity.Value.ValueInt64(), + Unit: cloudwrapper.Unit(loc.Capacity.Unit.ValueString()), + }, + }) + } + return locations +} + +func (m *ConfigurationResourceModel) getLocationsResp() []cloudwrapper.ConfigLocationResp { + locations := make([]cloudwrapper.ConfigLocationResp, 0, len(m.Locations)) + for _, loc := range m.Locations { + locations = append(locations, cloudwrapper.ConfigLocationResp{ + Comments: loc.Comments.ValueString(), + TrafficTypeID: int(loc.TrafficTypeID.ValueInt64()), + Capacity: cloudwrapper.Capacity{ + Value: loc.Capacity.Value.ValueInt64(), + Unit: cloudwrapper.Unit(loc.Capacity.Unit.ValueString()), + }, + }) + } + return locations +} + +func (m *ConfigurationResourceModel) revision(ctx context.Context) string { + return calculateRevision(&cloudwrapper.Configuration{ + CapacityAlertsThreshold: m.getCapacityAlertsThreshold(), + Comments: m.Comments.ValueString(), + ContractID: m.ContractID.ValueString(), + ConfigID: m.ID.ValueInt64(), + Locations: m.getLocationsResp(), + ConfigName: m.ConfigName.ValueString(), + NotificationEmails: m.getNotificationEmails(ctx), + PropertyIDs: m.getPropertyIDs(ctx), + RetainIdleObjects: m.RetainIdleObjects.ValueBool(), + }) +} + +func calculateRevision(config *cloudwrapper.Configuration) string { + sha := sha256.New() + + buffer := bytes.Buffer{} + + buffer.WriteString(config.Comments) + + sort.Strings(config.PropertyIDs) + buffer.WriteString(strings.Join(config.PropertyIDs, ":")) + + buffer.WriteString(strconv.FormatBool(config.RetainIdleObjects)) + if config.CapacityAlertsThreshold != nil { + buffer.WriteString(strconv.Itoa(*config.CapacityAlertsThreshold)) + } + buffer.WriteString(strings.Join(config.NotificationEmails, ":")) + + sort.Slice(config.Locations, func(i, j int) bool { + return config.Locations[i].TrafficTypeID < config.Locations[j].TrafficTypeID + }) + for _, loc := range config.Locations { + buffer.WriteString(loc.Comments) + buffer.WriteString(strconv.FormatInt(loc.Capacity.Value, 10)) + buffer.WriteString(string(loc.Capacity.Unit)) + } + + _, err := buffer.WriteTo(sha) + if err != nil { + panic("calculate revision: writing to buffer failed") + } + + return hex.EncodeToString(sha.Sum([]byte{}))[:20] +} diff --git a/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_test.go b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_test.go new file mode 100644 index 000000000..152c6f14e --- /dev/null +++ b/pkg/providers/cloudwrapper/resource_akamai_cloudwrapper_configuration_test.go @@ -0,0 +1,1262 @@ +package cloudwrapper + +import ( + "regexp" + "testing" + + "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cloudwrapper" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/jinzhu/copier" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestConfigurationResource(t *testing.T) { + t.Parallel() + t.Run("create basic", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + ConfigName: "testname", + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "property_ids.0", "200200200"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "notification_emails.0", "test@akamai.com"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "comments", "test"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "retain_idle_objects", "false"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "location.#", "1"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "location.0.comments", "test"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "location.0.traffic_type_id", "1"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "location.0.capacity.value", "1"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "location.0.capacity.unit", "GB"), + resource.TestCheckNoResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("email will be computed when not provided", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/computed_email.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "notification_emails.#", "1"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "notification_emails.0", "generated@akamai.com"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("retain_idle_objects has default when not provided", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/computed_email.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "notification_emails.#", "1"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "notification_emails.0", "generated@akamai.com"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("force new on config name change", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + expecter.ExpectRefresh() + expecter.ExpectRefresh() + expecter.ExpectDelete() + + configUpdate := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "newname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter = newExpecter(t, client) + + expecter.ExpectCreate(configUpdate) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/update_config_name.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "newname"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("force new on contract_id change", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + configUpdate := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_234", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter = newExpecter(t, client) + + expecter.ExpectCreate(configUpdate) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/update_contract_id.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_234"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("force new on contract_id change", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + configUpdate := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_234", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter = newExpecter(t, client) + + expecter.ExpectCreate(configUpdate) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/update_contract_id.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_234"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("import", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + ImportState: true, + ImportStateId: "123", + ResourceName: "akamai_cloudwrapper_configuration.test", + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("basic update", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + capacityAlertsThreshold := 50 + + configUpdate := cloudwrapper.UpdateConfigurationRequest{ + ConfigID: expecter.config.ConfigID, + Body: cloudwrapper.UpdateConfigurationBody{ + CapacityAlertsThreshold: &capacityAlertsThreshold, + Comments: "test", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: true, + }, + } + + expecter.ExpectRefresh() + expecter.ExpectUpdate(configUpdate) + + expecter.ExpectRefresh() + + configUpdate2 := cloudwrapper.UpdateConfigurationRequest{ + ConfigID: expecter.config.ConfigID, + Body: cloudwrapper.UpdateConfigurationBody{ + Comments: "test", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter.ExpectRefresh() + expecter.ExpectUpdate(configUpdate2) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckNoResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/update_alerts_threshold.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold", "50"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckNoResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold"), + ), + }, + }, + }) + }) + t.Run("update comments - expect an error", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + configUpdate := cloudwrapper.UpdateConfigurationRequest{ + ConfigID: expecter.config.ConfigID, + Body: cloudwrapper.UpdateConfigurationBody{ + Comments: "test-updated", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter.ExpectRefresh() + expecter.ExpectUpdate(configUpdate) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/update_comments_error.tf"), + ExpectError: regexp.MustCompile("updating field `comments` is not possible"), + }, + }, + }) + }) + t.Run("drift - config got removed", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + expecter.ExpectDriftRefresh(nil, cloudwrapper.ErrConfigurationNotFound) + expecter = newExpecter(t, client) + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckNoResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + resource.TestCheckNoResourceAttr("akamai_cloudwrapper_configuration.test", "capacity_alerts_threshold"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("contract_id remove prefix expect no diff", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + expecter.ExpectCreate(configuration) + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/contract_id_no_prefix.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("property_ids with prefix", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + expecter.ExpectCreate(configuration) + expecter.ExpectRefresh() + + expecter.ExpectDriftRefresh(&cloudwrapper.Configuration{ + Comments: "test", + ContractID: "ctr_123", + ConfigID: 123, + Locations: []cloudwrapper.ConfigLocationResp{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + Status: "SAVED", + ConfigName: "testname", + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"300300300"}, + RetainIdleObjects: false, + }, nil) + + expecter.ExpectUpdate(cloudwrapper.UpdateConfigurationRequest{ + ConfigID: 123, + Activate: false, + Body: cloudwrapper.UpdateConfigurationBody{ + Comments: "test", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + }) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/property_ids_with_prefix.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/property_ids_with_prefix.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("multicdn drift error", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + expecter.ExpectCreate(configuration) + expecter.ExpectRefresh() + + expecter.ExpectDriftRefresh(&cloudwrapper.Configuration{ + Comments: "test", + ContractID: "ctr_123", + ConfigID: 123, + Locations: []cloudwrapper.ConfigLocationResp{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + MultiCDNSettings: &cloudwrapper.MultiCDNSettings{}, // ADDED MULTICDN + Status: "SAVED", + ConfigName: "testname", + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"300300300"}, + RetainIdleObjects: false, + }, nil) + + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/property_ids_with_prefix.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/property_ids_with_prefix.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + ExpectError: regexp.MustCompile("Configuration Contains Multi CDN Settings"), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("contract_id prefix drift", func(t *testing.T) { + t.Parallel() + client := &cloudwrapper.Mock{} + + configuration := cloudwrapper.CreateConfigurationRequest{ + Body: cloudwrapper.CreateConfigurationBody{ + Comments: "test", + ContractID: "ctr_123", + Locations: []cloudwrapper.ConfigLocationReq{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + NotificationEmails: []string{"test@akamai.com"}, + ConfigName: "testname", + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, + } + + expecter := newExpecter(t, client) + expecter.ExpectCreate(configuration) + expecter.ExpectRefresh() + + expecter.ExpectDriftRefresh(&cloudwrapper.Configuration{ + Comments: "test", + ContractID: "123", + ConfigID: 123, + Locations: []cloudwrapper.ConfigLocationResp{ + { + Comments: "test", + TrafficTypeID: 1, + Capacity: cloudwrapper.Capacity{ + Value: 1, + Unit: cloudwrapper.UnitGB, + }, + }, + }, + Status: "SAVED", + ConfigName: "testname", + NotificationEmails: []string{"test@akamai.com"}, + PropertyIDs: []string{"200200200"}, + RetainIdleObjects: false, + }, nil) + + expecter.ExpectRefresh() + expecter.ExpectDelete() + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: newProviderFactory(withMockClient(client)), + Steps: []resource.TestStep{ + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + { + Config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/create.tf"), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "id", "123"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "config_name", "testname"), + resource.TestCheckResourceAttr("akamai_cloudwrapper_configuration.test", "contract_id", "ctr_123"), + ), + }, + }, + }) + + client.AssertExpectations(t) + }) + t.Run("expect missing required errors", func(t *testing.T) { + t.Parallel() + tests := map[string]struct { + config string + expectErr *regexp.Regexp + }{ + "missing comments": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`The argument "comments" is required, but no definition was found`), + }, + "missing config_name": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`The argument "config_name" is required, but no definition was found`), + }, + "missing property_ids": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`The argument "property_ids" is required, but no definition was found`), + }, + "missing contract_id": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`The argument "contract_id" is required, but no definition was found`), + }, + "missing location": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_location.tf"), + expectErr: regexp.MustCompile("Block location must have a configuration value as the provider has marked it\nas required"), + }, + "missing location comments": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_location_comments.tf"), + expectErr: regexp.MustCompile(`location {\n\nThe argument "comments" is required, but no definition was found.`), + }, + "missing location traffic_type_id": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`location {\n\nThe argument "traffic_type_id" is required, but no definition was found.`), + }, + "missing location capacity block": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_capacity.tf"), + expectErr: regexp.MustCompile(`Block\nlocation\[.+\]\.capacity\nmust have a configuration value as the provider has marked it as required`), + }, + "missing location capacity value": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`capacity {\n\nThe argument "value" is required, but no definition was found.`), + }, + "missing location capacity unit": { + config: testutils.LoadFixtureString(t, "testdata/TestResConfiguration/missing_required.tf"), + expectErr: regexp.MustCompile(`capacity {\n\nThe argument "unit" is required, but no definition was found.`), + }, + } + fact := newProviderFactory() + + for name, tc := range tests { + name, tc := name, tc + t.Run(name, func(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV5ProviderFactories: fact, + Steps: []resource.TestStep{ + { + Config: tc.config, + ExpectError: tc.expectErr, + }, + }, + }) + + }) + } + }) +} + +type expecter struct { + t *testing.T + client *cloudwrapper.Mock + config *cloudwrapper.Configuration +} + +func newExpecter(t *testing.T, client *cloudwrapper.Mock) expecter { + return expecter{ + t: t, + client: client, + } +} + +func (e *expecter) CloneConfig() *cloudwrapper.Configuration { + var config cloudwrapper.Configuration + err := copier.CopyWithOption(&config, e.config, copier.Option{DeepCopy: true}) + assert.NoError(e.t, err) + return &config +} + +func (e *expecter) applyCreate(req cloudwrapper.CreateConfigurationRequest) { + notificationEmails := []string{"generated@akamai.com"} // email is genereated when not provided + if len(req.Body.NotificationEmails) > 0 { + notificationEmails = req.Body.NotificationEmails + } + + locations := make([]cloudwrapper.ConfigLocationResp, 0, len(req.Body.Locations)) + for _, loc := range req.Body.Locations { + locations = append(locations, cloudwrapper.ConfigLocationResp{ + Comments: loc.Comments, + TrafficTypeID: loc.TrafficTypeID, + Capacity: loc.Capacity, + MapName: "cw-s-use-live", + }) + } + + e.config = &cloudwrapper.Configuration{ + CapacityAlertsThreshold: req.Body.CapacityAlertsThreshold, + Comments: req.Body.Comments, + ContractID: req.Body.ContractID, + ConfigID: 123, + Locations: locations, + MultiCDNSettings: req.Body.MultiCDNSettings, + Status: "SAVED", + ConfigName: req.Body.ConfigName, + LastUpdatedBy: "jondoe", + LastUpdatedDate: "2022-02-02T02:22:22Z", + NotificationEmails: notificationEmails, + PropertyIDs: req.Body.PropertyIDs, + RetainIdleObjects: req.Body.RetainIdleObjects, + } + +} + +func (e *expecter) ExpectCreate(req cloudwrapper.CreateConfigurationRequest) { + e.applyCreate(req) + e.client.On("CreateConfiguration", mock.Anything, req).Return(e.CloneConfig(), nil).Once() +} + +func (e *expecter) ExpectRefresh() { + e.client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ + ConfigID: 123, + }).Return(e.CloneConfig(), nil).Once() +} + +func (e *expecter) ExpectDriftRefresh(config *cloudwrapper.Configuration, err error) { + e.client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ + ConfigID: e.config.ConfigID, + }).Return(config, err).Once() +} + +func (e *expecter) applyUpdate(req cloudwrapper.UpdateConfigurationRequest) { + + notificationEmails := []string{"generated@akamai.com"} + if len(req.Body.NotificationEmails) > 0 { + notificationEmails = req.Body.NotificationEmails + } + + locations := make([]cloudwrapper.ConfigLocationResp, 0, len(req.Body.Locations)) + for _, loc := range req.Body.Locations { + locations = append(locations, cloudwrapper.ConfigLocationResp{ + Comments: loc.Comments, + TrafficTypeID: loc.TrafficTypeID, + Capacity: loc.Capacity, + MapName: "cw-s-use-live", + }) + } + + e.config = &cloudwrapper.Configuration{ + CapacityAlertsThreshold: req.Body.CapacityAlertsThreshold, + Comments: req.Body.Comments, + ContractID: e.config.ContractID, // no update + ConfigID: 123, + Locations: locations, + MultiCDNSettings: req.Body.MultiCDNSettings, + Status: "SAVED", + ConfigName: e.config.ConfigName, // no update + LastUpdatedBy: "jondoe", + LastUpdatedDate: "2022-02-02T02:22:22Z", + NotificationEmails: notificationEmails, + PropertyIDs: req.Body.PropertyIDs, + RetainIdleObjects: req.Body.RetainIdleObjects, + } +} + +func (e *expecter) ExpectUpdate(req cloudwrapper.UpdateConfigurationRequest) { + e.applyUpdate(req) + e.client.On("UpdateConfiguration", mock.Anything, req).Return(e.CloneConfig(), nil).Once() +} + +func (e *expecter) ExpectDelete() { + e.client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ + ConfigID: 123, + }).Return(e.CloneConfig(), nil).Once() + + e.client.On("DeleteConfiguration", mock.Anything, cloudwrapper.DeleteConfigurationRequest{ + ConfigID: e.config.ConfigID, + }).Return(nil).Once() + + conf := e.CloneConfig() + conf.Status = "DELETE_IN_PROGRESS" + + e.client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ + ConfigID: 123, + }).Return(conf, nil).Once() + + e.client.On("GetConfiguration", mock.Anything, cloudwrapper.GetConfigurationRequest{ + ConfigID: 123, + }).Return(nil, cloudwrapper.ErrConfigurationNotFound).Once() +} diff --git a/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/default.tf b/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/default.tf new file mode 100644 index 000000000..5c74f6886 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/default.tf @@ -0,0 +1,3 @@ +data "akamai_cloudwrapper_configuration" "test" { + id = 1 +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/no_config_id.tf b/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/no_config_id.tf new file mode 100644 index 000000000..afb78fab1 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataConfiguration/no_config_id.tf @@ -0,0 +1 @@ +data "akamai_cloudwrapper_configuration" "test" {} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataConfigurations/default.tf b/pkg/providers/cloudwrapper/testdata/TestDataConfigurations/default.tf new file mode 100644 index 000000000..87232418b --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataConfigurations/default.tf @@ -0,0 +1 @@ +data "akamai_cloudwrapper_configurations" "test" {} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataLocation/invalid_type.tf b/pkg/providers/cloudwrapper/testdata/TestDataLocation/invalid_type.tf new file mode 100644 index 000000000..928595db1 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataLocation/invalid_type.tf @@ -0,0 +1,4 @@ +data "akamai_cloudwrapper_location" "test" { + location_name = "US West" + traffic_type = "TEST" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataLocation/location.tf b/pkg/providers/cloudwrapper/testdata/TestDataLocation/location.tf new file mode 100644 index 000000000..bc4688ac5 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataLocation/location.tf @@ -0,0 +1,4 @@ +data "akamai_cloudwrapper_location" "test" { + location_name = "US West" + traffic_type = "LIVE_VOD" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataLocation/no_location.tf b/pkg/providers/cloudwrapper/testdata/TestDataLocation/no_location.tf new file mode 100644 index 000000000..acc2acafd --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataLocation/no_location.tf @@ -0,0 +1,4 @@ +data "akamai_cloudwrapper_location" "test" { + location_name = "US West" + traffic_type = "WEB_ENHANCED_TLS" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataLocations/location.tf b/pkg/providers/cloudwrapper/testdata/TestDataLocations/location.tf new file mode 100644 index 000000000..8b6b0151f --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataLocations/location.tf @@ -0,0 +1,2 @@ +data "akamai_cloudwrapper_locations" "test" { +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_false.tf b/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_false.tf new file mode 100644 index 000000000..8ff85f3f7 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_false.tf @@ -0,0 +1,4 @@ +data "akamai_cloudwrapper_properties" "test" { + unused = false + contract_ids = ["ctr_1", "ctr_2"] +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_true.tf b/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_true.tf new file mode 100644 index 000000000..7ffe42f9b --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataProperties/default_unused_true.tf @@ -0,0 +1,3 @@ +data "akamai_cloudwrapper_properties" "test" { + unused = true +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataProperties/missing_contract_ids.tf b/pkg/providers/cloudwrapper/testdata/TestDataProperties/missing_contract_ids.tf new file mode 100644 index 000000000..ab6d35996 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataProperties/missing_contract_ids.tf @@ -0,0 +1,2 @@ +data "akamai_cloudwrapper_properties" "test" { +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestDataProperties/no_attributes.tf b/pkg/providers/cloudwrapper/testdata/TestDataProperties/no_attributes.tf new file mode 100644 index 000000000..1f4802833 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestDataProperties/no_attributes.tf @@ -0,0 +1 @@ +data "akamai_cloudwrapper_properties" "test" {} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/create.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/create.tf new file mode 100644 index 000000000..f684bcd6b --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/create.tf @@ -0,0 +1,4 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 123 + revision = "5fe7963eb7270e69c5e8" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/create_missing_required.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/create_missing_required.tf new file mode 100644 index 000000000..2dd7538e1 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/create_missing_required.tf @@ -0,0 +1,3 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 123 +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/create_timeout.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/create_timeout.tf new file mode 100644 index 000000000..78688c8fd --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/create_timeout.tf @@ -0,0 +1,8 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 123 + revision = "5fe7963eb7270e69c5e8" + timeouts { + create = "2s" + update = "1s" + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/update.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/update.tf new file mode 100644 index 000000000..7ddd0ccb7 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/update.tf @@ -0,0 +1,4 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 123 + revision = "8b92934d68d69621153c" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/update_forcenew.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/update_forcenew.tf new file mode 100644 index 000000000..ea080e6ac --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/update_forcenew.tf @@ -0,0 +1,4 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 321 + revision = "5fe7963eb7270e69c5e8" +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResActivation/update_timeout.tf b/pkg/providers/cloudwrapper/testdata/TestResActivation/update_timeout.tf new file mode 100644 index 000000000..4a684dc0f --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResActivation/update_timeout.tf @@ -0,0 +1,8 @@ +resource "akamai_cloudwrapper_activation" "act" { + config_id = 123 + revision = "8b92934d68d69621153c" + timeouts { + create = "2s" + update = "1s" + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_email.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_email.tf new file mode 100644 index 000000000..e6a80b27a --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_email.tf @@ -0,0 +1,15 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_retain_idle_obj.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_retain_idle_obj.tf new file mode 100644 index 000000000..dac94c6cf --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/computed_retain_idle_obj.tf @@ -0,0 +1,14 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + comments = "test" + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/contract_id_no_prefix.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/contract_id_no_prefix.tf new file mode 100644 index 000000000..f505cf9ca --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/contract_id_no_prefix.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/create.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/create.tf new file mode 100644 index 000000000..4508ad93f --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/create.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_capacity.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_capacity.tf new file mode 100644 index 000000000..9055c43bf --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_capacity.tf @@ -0,0 +1,12 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location.tf new file mode 100644 index 000000000..b04093d1b --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location.tf @@ -0,0 +1,8 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location_comments.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location_comments.tf new file mode 100644 index 000000000..431cc2df4 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_location_comments.tf @@ -0,0 +1,15 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_required.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_required.tf new file mode 100644 index 000000000..65e21901b --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/missing_required.tf @@ -0,0 +1,7 @@ +resource "akamai_cloudwrapper_configuration" "test" { + location { + capacity { + + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/property_ids_with_prefix.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/property_ids_with_prefix.tf new file mode 100644 index 000000000..9a8ca48dc --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/property_ids_with_prefix.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["prp_200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_alerts_threshold.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_alerts_threshold.tf new file mode 100644 index 000000000..2c73799dd --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_alerts_threshold.tf @@ -0,0 +1,17 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = true + capacity_alerts_threshold = 50 + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_comments_error.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_comments_error.tf new file mode 100644 index 000000000..3d33236e0 --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_comments_error.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test-updated" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_config_name.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_config_name.tf new file mode 100644 index 000000000..ab97180da --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_config_name.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "newname" + contract_id = "ctr_123" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_contract_id.tf b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_contract_id.tf new file mode 100644 index 000000000..a545b731e --- /dev/null +++ b/pkg/providers/cloudwrapper/testdata/TestResConfiguration/update_contract_id.tf @@ -0,0 +1,16 @@ +resource "akamai_cloudwrapper_configuration" "test" { + config_name = "testname" + contract_id = "ctr_234" + property_ids = ["200200200"] + notification_emails = ["test@akamai.com"] + comments = "test" + retain_idle_objects = false + location { + traffic_type_id = 1 + comments = "test" + capacity { + value = 1 + unit = "GB" + } + } +} \ No newline at end of file diff --git a/pkg/providers/cps/data_akamai_cps_csr_test.go b/pkg/providers/cps/data_akamai_cps_csr_test.go index 6ef201022..7b3a25e0e 100644 --- a/pkg/providers/cps/data_akamai_cps_csr_test.go +++ b/pkg/providers/cps/data_akamai_cps_csr_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/cps/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -442,7 +443,7 @@ func TestDataCPSCSR(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkAttrsForCPSCSR(test.mockData), ExpectError: test.error, }, diff --git a/pkg/providers/cps/data_akamai_cps_deployments_test.go b/pkg/providers/cps/data_akamai_cps_deployments_test.go index ff9055105..c1b74681e 100644 --- a/pkg/providers/cps/data_akamai_cps_deployments_test.go +++ b/pkg/providers/cps/data_akamai_cps_deployments_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -242,7 +243,7 @@ func TestDataCPSDeployments(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc(test.checkFunctions...), ExpectError: test.withError, }, diff --git a/pkg/providers/cps/data_akamai_cps_enrollment_test.go b/pkg/providers/cps/data_akamai_cps_enrollment_test.go index d1ee24716..5ff96c831 100644 --- a/pkg/providers/cps/data_akamai_cps_enrollment_test.go +++ b/pkg/providers/cps/data_akamai_cps_enrollment_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -335,7 +336,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_without_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_without_challenges.tf"), Check: checkAttributesForEnrollment(enrollmentDV1, enrollment1ID, mockEmptyChanges(), mockEmptyDVArray()), }, }, @@ -363,7 +364,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_with_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_with_challenges.tf"), Check: checkAttributesForEnrollment(enrollmentDV2, enrollment2ID, mockLetsEncryptChallenges(), mockDVArray()), }, }, @@ -378,7 +379,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_without_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_without_challenges.tf"), ExpectError: regexp.MustCompile("could not get an enrollment"), }, }, @@ -398,7 +399,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_with_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_with_challenges.tf"), ExpectError: regexp.MustCompile("could not get a change status"), }, }, @@ -425,7 +426,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_with_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_with_challenges.tf"), ExpectError: regexp.MustCompile("could not get LetsEncrypt challenges"), }, }, @@ -448,7 +449,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_with_third_party_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_with_third_party_challenges.tf"), Check: checkAttributesForEnrollment(enrollmentThirdParty, enrollment3ID, mockThirdPartyCSRChallenges(), mockThirdPartyCSRDVArray()), }, }, @@ -471,7 +472,7 @@ func TestDataEnrollment(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollment/enrollment_with_ev_challenges.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollment/enrollment_with_ev_challenges.tf"), Check: checkAttributesForEnrollment(enrollmentEV, enrollment4ID, mockEVChallenges(), mockEVDVArray()), }, }, diff --git a/pkg/providers/cps/data_akamai_cps_enrollments_test.go b/pkg/providers/cps/data_akamai_cps_enrollments_test.go index 78075ad1d..d1aab7fcd 100644 --- a/pkg/providers/cps/data_akamai_cps_enrollments_test.go +++ b/pkg/providers/cps/data_akamai_cps_enrollments_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/cps/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -40,7 +41,7 @@ func TestDataEnrollments(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollments/enrollments.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollments/enrollments.tf"), Check: checkAttrsForListEnrollments(enrollmentsList), }, }, @@ -54,7 +55,7 @@ func TestDataEnrollments(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollments/enrollments.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollments/enrollments.tf"), ExpectError: regexp.MustCompile("could not get list of enrollments"), }, }, @@ -69,7 +70,7 @@ func TestDataEnrollments(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollments/enrollments.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollments/enrollments.tf"), Check: checkAttrsForListEnrollments(enrollmentsThirdPartyList), }, }, @@ -83,11 +84,11 @@ func TestDataEnrollments(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataEnrollments/enrollments.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollments/enrollments.tf"), Check: resource.TestCheckResourceAttr("data.akamai_cps_enrollments.test", "contract_id", contractID), }, { - Config: loadFixtureString("testdata/TestDataEnrollments/enrollments.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataEnrollments/enrollments.tf"), Check: resource.TestCheckResourceAttr("data.akamai_cps_enrollments.test", "enrollments.#", "0"), }, }, diff --git a/pkg/providers/cps/data_akamai_cps_warnings_test.go b/pkg/providers/cps/data_akamai_cps_warnings_test.go index d4c8dc144..315768298 100644 --- a/pkg/providers/cps/data_akamai_cps_warnings_test.go +++ b/pkg/providers/cps/data_akamai_cps_warnings_test.go @@ -3,7 +3,8 @@ package cps import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataWarnings(t *testing.T) { @@ -13,7 +14,7 @@ func TestDataWarnings(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataWarnings/warnings.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataWarnings/warnings.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_cps_warnings.test", "warnings.%", "112"), resource.TestCheckResourceAttr("data.akamai_cps_warnings.test", "warnings.CERTIFICATE_NULL_OR_EMPTY", "Null or empty [] Certificate."), diff --git a/pkg/providers/cps/provider_test.go b/pkg/providers/cps/provider_test.go index a2aa662f8..2ac3e3e39 100644 --- a/pkg/providers/cps/provider_test.go +++ b/pkg/providers/cps/provider_test.go @@ -1,8 +1,6 @@ package cps import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -52,17 +50,3 @@ func useClient(client cps.CPS, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/cps/resource_akamai_cps_dv_enrollment_test.go b/pkg/providers/cps/resource_akamai_cps_dv_enrollment_test.go index 494017a7c..93915f1d4 100644 --- a/pkg/providers/cps/resource_akamai_cps_dv_enrollment_test.go +++ b/pkg/providers/cps/resource_akamai_cps_dv_enrollment_test.go @@ -8,8 +8,9 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/jinzhu/copier" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -278,7 +279,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/lifecycle/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/lifecycle/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -290,7 +291,7 @@ func TestResourceDVEnrollment(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResDVEnrollment/lifecycle/update_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/lifecycle/update_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -477,7 +478,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/empty_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/empty_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -687,7 +688,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/client_mutual_auth/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/client_mutual_auth/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "network_configuration.0.client_mutual_authentication.0.set_id", "12345"), @@ -878,7 +879,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -890,7 +891,7 @@ func TestResourceDVEnrollment(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResDVEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1036,7 +1037,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/lifecycle/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/lifecycle/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1249,7 +1250,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1258,7 +1259,7 @@ func TestResourceDVEnrollment(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResDVEnrollment/acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1438,7 +1439,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1624,7 +1625,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/allow_duplicate_cn/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/allow_duplicate_cn/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_dv_enrollment.dv", "certificate_type", "san"), @@ -1760,7 +1761,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`enrollment pre-verification returned warnings and the enrollment cannot be validated. Please fix the issues or set acknowledge_pre_validation_warnings flag to true then run 'terraform apply' again: some warning`), }, }, @@ -1843,7 +1844,7 @@ func TestResourceDVEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/no_acknowledge_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`error creating enrollment`), }, }, @@ -1996,7 +1997,7 @@ func TestResourceDVEnrollmentImport(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/import/import_enrollment.tf"), ImportStateCheck: func(s []*terraform.InstanceState) error { assert.Len(t, s, 1) rs := s[0] @@ -2006,7 +2007,7 @@ func TestResourceDVEnrollmentImport(t *testing.T) { }, }, { - Config: loadFixtureString("testdata/TestResDVEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/import/import_enrollment.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cps_dv_enrollment.dv", @@ -2033,7 +2034,7 @@ func TestResourceDVEnrollmentImport(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVEnrollment/import/import_enrollment.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cps_dv_enrollment.dv", diff --git a/pkg/providers/cps/resource_akamai_cps_dv_validation_test.go b/pkg/providers/cps/resource_akamai_cps_dv_validation_test.go index 2a495636a..5f972ebc3 100644 --- a/pkg/providers/cps/resource_akamai_cps_dv_validation_test.go +++ b/pkg/providers/cps/resource_akamai_cps_dv_validation_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -98,7 +99,7 @@ func TestDVValidation(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVValidation/create_validation.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVValidation/create_validation.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "id", "1"), resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "status", "coodinate-domain-validation"), @@ -106,7 +107,7 @@ func TestDVValidation(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResDVValidation/update_validation.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVValidation/update_validation.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "id", "1"), resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "status", "coodinate-domain-validation"), @@ -166,7 +167,7 @@ func TestDVValidation(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVValidation/create_validation.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVValidation/create_validation.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "id", "1"), resource.TestCheckResourceAttr("akamai_cps_dv_validation.dv_validation", "status", "coodinate-domain-validation"), @@ -207,7 +208,7 @@ func TestDVValidation(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDVValidation/create_validation.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDVValidation/create_validation.tf"), ExpectError: regexp.MustCompile("retry timeout reached - error sending acknowledgement request: oops"), }, }, diff --git a/pkg/providers/cps/resource_akamai_cps_third_party_enrollment_test.go b/pkg/providers/cps/resource_akamai_cps_third_party_enrollment_test.go index b974dd692..217f8034e 100644 --- a/pkg/providers/cps/resource_akamai_cps_third_party_enrollment_test.go +++ b/pkg/providers/cps/resource_akamai_cps_third_party_enrollment_test.go @@ -7,9 +7,10 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/jinzhu/copier" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -139,13 +140,13 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle/update_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle/update_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -268,13 +269,13 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_no_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_no_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_no_sans/update_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_no_sans/update_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -362,7 +363,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/empty_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/empty_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -476,7 +477,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/client_mutual_auth/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/client_mutual_auth/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -566,13 +567,13 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -665,13 +666,13 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_no_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_no_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle_no_cn_in_sans/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle_no_cn_in_sans/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -731,7 +732,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -822,13 +823,13 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -932,7 +933,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/acknowledge_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -1019,7 +1020,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/allow_duplicate_cn/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/allow_duplicate_cn/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "allow_duplicate_common_name", "true"), @@ -1094,7 +1095,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`enrollment pre-verification returned warnings and the enrollment cannot be validated. Please fix the issues or set acknowledge_pre_validation_warnings flag to true then run 'terraform apply' again: some warning`), }, }, @@ -1134,7 +1135,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/no_acknowledge_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`error creating enrollment`), }, }, @@ -1236,7 +1237,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), @@ -1310,7 +1311,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`warnings cannot be approved: "FIXED_TRUST_CHAIN_PARSING_ERROR"`), }, }, @@ -1388,7 +1389,7 @@ func TestResourceThirdPartyEnrollment(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/auto_approve_warnings/create_enrollment.tf"), ExpectError: regexp.MustCompile(`received warning\(s\) does not match any known warning: 'This is unknown warning.'`), }, }, @@ -1471,7 +1472,7 @@ func TestResourceThirdPartyEnrollmentImport(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), ImportStateCheck: func(s []*terraform.InstanceState) error { assert.Len(t, s, 1) rs := s[0] @@ -1481,7 +1482,7 @@ func TestResourceThirdPartyEnrollmentImport(t *testing.T) { }, }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cps_third_party_enrollment.third_party", @@ -1508,7 +1509,7 @@ func TestResourceThirdPartyEnrollmentImport(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/import/import_enrollment.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cps_third_party_enrollment.third_party", @@ -1612,13 +1613,13 @@ func TestSuppressingSignatureAlgorithm(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle/create_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), }, { - Config: loadFixtureString("testdata/TestResThirdPartyEnrollment/lifecycle/update_enrollment.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResThirdPartyEnrollment/lifecycle/update_enrollment.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_cps_third_party_enrollment.third_party", "contract_id", "ctr_1"), ), diff --git a/pkg/providers/cps/resource_akamai_cps_upload_certificate_test.go b/pkg/providers/cps/resource_akamai_cps_upload_certificate_test.go index 9b0a390b1..d3a683085 100644 --- a/pkg/providers/cps/resource_akamai_cps_upload_certificate_test.go +++ b/pkg/providers/cps/resource_akamai_cps_upload_certificate_test.go @@ -7,9 +7,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/cps" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -75,12 +76,12 @@ func TestResourceCPSUploadCertificate(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPathForCreate), + Config: testutils.LoadFixtureString(t, test.configPathForCreate), Check: test.checkFuncForCreate, ExpectError: test.error, }, { - Config: loadFixtureString(test.configPathForUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForUpdate), Check: test.checkFuncForUpdate, ExpectError: test.error, }, @@ -176,7 +177,7 @@ func TestResourceCPSUploadCertificateWithThirdPartyEnrollmentDependency(t *testi IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), ExpectError: test.error, Check: test.checkFunc, }, @@ -283,17 +284,17 @@ func TestResourceCPSUploadCertificateLifecycle(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPathForCreate), + Config: testutils.LoadFixtureString(t, test.configPathForCreate), Check: test.checkFuncForCreate, ExpectError: test.errorForCreate, }, { - Config: loadFixtureString(test.configPathForUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForUpdate), Check: test.checkFuncForUpdate, ExpectError: test.errorForUpdate, }, { - Config: loadFixtureString(test.configPathForSecondUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForSecondUpdate), Check: test.checkFuncForUpdate, ExpectError: test.errorForSecondUpdate, }, @@ -663,7 +664,7 @@ func TestCreateCPSUploadCertificate(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: test.checkFunc, ExpectError: test.error, }, @@ -778,7 +779,7 @@ func TestReadCPSUploadCertificate(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: test.checkFunc, ExpectError: test.error, }, @@ -1091,12 +1092,12 @@ func TestUpdateCPSUploadCertificate(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPathForCreate), + Config: testutils.LoadFixtureString(t, test.configPathForCreate), Check: test.checkFuncForCreate, ExpectError: test.errorForCreate, }, { - Config: loadFixtureString(test.configPathForUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForUpdate), Check: test.checkFuncForUpdate, ExpectError: test.errorForUpdate, }, @@ -1169,7 +1170,7 @@ func TestResourceUploadCertificateImport(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPSUploadCertificate/import/import_upload.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPSUploadCertificate/import/import_upload.tf"), ImportState: true, ImportStateId: fmt.Sprintf("%d", id), ResourceName: "akamai_cps_upload_certificate.import", diff --git a/pkg/providers/datastream/data_akamai_datastream_activation_history_test.go b/pkg/providers/datastream/data_akamai_datastream_activation_history_test.go index 7683d227b..2bf306ec2 100644 --- a/pkg/providers/datastream/data_akamai_datastream_activation_history_test.go +++ b/pkg/providers/datastream/data_akamai_datastream_activation_history_test.go @@ -7,9 +7,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/datastream" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/stretchr/testify/mock" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataAkamaiDatastreamActivationHistoryRead(t *testing.T) { @@ -79,7 +80,7 @@ func TestDataAkamaiDatastreamActivationHistoryRead(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( test.checkFuncs..., ), diff --git a/pkg/providers/datastream/data_akamai_datastream_dataset_fields_test.go b/pkg/providers/datastream/data_akamai_datastream_dataset_fields_test.go index 7d8e443dd..ad5415486 100644 --- a/pkg/providers/datastream/data_akamai_datastream_dataset_fields_test.go +++ b/pkg/providers/datastream/data_akamai_datastream_dataset_fields_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/datastream" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -95,7 +96,7 @@ func TestDataSourceDatasetFieldsRead(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( test.checkFuncs..., ), @@ -107,7 +108,7 @@ func TestDataSourceDatasetFieldsRead(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), ExpectError: test.withError, }, }, diff --git a/pkg/providers/datastream/data_akamai_datastreams_test.go b/pkg/providers/datastream/data_akamai_datastreams_test.go index a1ac06168..8f1b34516 100644 --- a/pkg/providers/datastream/data_akamai_datastreams_test.go +++ b/pkg/providers/datastream/data_akamai_datastreams_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/datastream" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -71,7 +72,7 @@ func TestDataDatastreams(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_without_groupid.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_without_groupid.tf"), Check: streamsChecks(streamList), }, }, @@ -84,7 +85,7 @@ func TestDataDatastreams(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_with_groupid.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_with_groupid.tf"), Check: streamsChecks(streamListForSpecificGroup), }, }, @@ -97,7 +98,7 @@ func TestDataDatastreams(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_with_groupid_with_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_with_groupid_with_prefix.tf"), Check: streamsChecks(streamListForSpecificGroup), }, }, @@ -106,7 +107,7 @@ func TestDataDatastreams(t *testing.T) { init: func(t *testing.T, m *datastream.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_with_groupid_with_invalid_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_with_groupid_with_invalid_prefix.tf"), ExpectError: regexp.MustCompile("Invalid reference"), }, }, @@ -118,7 +119,7 @@ func TestDataDatastreams(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_without_groupid.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_without_groupid.tf"), Check: streamsChecks([]datastream.StreamDetails{}), }, }, @@ -130,7 +131,7 @@ func TestDataDatastreams(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDatastreams/list_streams_without_groupid.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDatastreams/list_streams_without_groupid.tf"), ExpectError: regexp.MustCompile("failed to get stream list"), }, }, diff --git a/pkg/providers/datastream/provider_test.go b/pkg/providers/datastream/provider_test.go index 1dbbaa297..cd6d5ffdc 100644 --- a/pkg/providers/datastream/provider_test.go +++ b/pkg/providers/datastream/provider_test.go @@ -1,8 +1,6 @@ package datastream import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -51,17 +49,3 @@ func useClient(client datastream.DS, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/datastream/resource_akamai_datastream_test.go b/pkg/providers/datastream/resource_akamai_datastream_test.go index edc267408..2621739c3 100644 --- a/pkg/providers/datastream/resource_akamai_datastream_test.go +++ b/pkg/providers/datastream/resource_akamai_datastream_test.go @@ -12,7 +12,8 @@ import ( "github.com/tj/assert" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/datastream" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -371,7 +372,7 @@ func TestResourceStream(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResourceStream/lifecycle/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/lifecycle/create_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "id", strconv.FormatInt(streamID, 10)), resource.TestCheckResourceAttr("akamai_datastream.s", "active", "true"), @@ -405,7 +406,7 @@ func TestResourceStream(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/lifecycle/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/lifecycle/update_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "id", strconv.FormatInt(streamID, 10)), resource.TestCheckResourceAttr("akamai_datastream.s", "active", "true"), @@ -707,14 +708,14 @@ func TestResourceUpdate(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/update_resource/create_stream_%s.tf", createStreamFilenameSuffix)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/update_resource/create_stream_%s.tf", createStreamFilenameSuffix)), Check: resource.ComposeTestCheckFunc( commonChecks, resource.TestCheckResourceAttr("akamai_datastream.s", "active", strconv.FormatBool(test.CreateStreamActive)), ), }, { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/update_resource/update_stream_%s.tf", updateStreamFilenameSuffix)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/update_resource/update_stream_%s.tf", updateStreamFilenameSuffix)), Check: resource.ComposeTestCheckFunc( commonChecks, resource.TestCheckResourceAttr("akamai_datastream.s", "active", strconv.FormatBool(test.UpdateStreamActive)), @@ -784,7 +785,7 @@ func TestResourceStreamErrors(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.tfFile), + Config: testutils.LoadFixtureString(t, test.tfFile), ExpectError: test.withError, }, }, @@ -844,7 +845,7 @@ func TestResourceStreamCustomDiff(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.tfFile), + Config: testutils.LoadFixtureString(t, test.tfFile), ExpectError: test.withError, PlanOnly: true, ExpectNonEmptyPlan: true, @@ -1002,7 +1003,7 @@ func TestEmailIDs(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/email_ids/%s", test.Filename)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/email_ids/%s", test.Filename)), Check: resource.ComposeTestCheckFunc(test.TestChecks...), }, }, @@ -1201,7 +1202,7 @@ func TestDatasetIDsDiff(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.preConfig), + Config: testutils.LoadFixtureString(t, test.preConfig), ExpectNonEmptyPlan: test.expectNonEmptyPlan, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.splunk_stream", "dataset_fields.#", "2"), @@ -1505,7 +1506,7 @@ func TestCustomHeaders(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/custom_headers/%s", test.Filename)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/custom_headers/%s", test.Filename)), Check: resource.ComposeTestCheckFunc(test.TestChecks...), }, }, @@ -1734,7 +1735,7 @@ func TestMTLS(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/mtls/%s", test.Filename)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/mtls/%s", test.Filename)), Check: resource.ComposeTestCheckFunc(test.TestChecks...), }, }, @@ -1855,7 +1856,7 @@ func TestUrlSuppressor(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/idempotency/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/idempotency/create_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -1863,7 +1864,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/idempotency/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/idempotency/create_stream.tf"), PlanOnly: true, }, }, @@ -1902,7 +1903,7 @@ func TestUrlSuppressor(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/update_endpoint_field/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/update_endpoint_field/create_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -1910,7 +1911,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/update_endpoint_field/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/update_endpoint_field/update_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -1957,7 +1958,7 @@ func TestUrlSuppressor(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/adding_fields/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/adding_fields/create_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -1965,7 +1966,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/adding_fields/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/adding_fields/update_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -1975,7 +1976,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/adding_fields/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/adding_fields/update_stream.tf"), PlanOnly: true, }, }, @@ -2012,7 +2013,7 @@ func TestUrlSuppressor(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/change_connector/create_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/change_connector/create_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.collector_code", "collector_code"), resource.TestCheckResourceAttr("akamai_datastream.s", "sumologic_connector.0.display_name", "display_name"), @@ -2020,7 +2021,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/change_connector/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/change_connector/update_stream.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_datastream.s", "datadog_connector.0.display_name", "display_name"), resource.TestCheckResourceAttr("akamai_datastream.s", "datadog_connector.0.auth_token", "auth_token"), @@ -2028,7 +2029,7 @@ func TestUrlSuppressor(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResourceStream/urlSuppressor/change_connector/update_stream.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceStream/urlSuppressor/change_connector/update_stream.tf"), PlanOnly: true, }, }, @@ -2207,7 +2208,7 @@ func TestConnectors(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("testdata/TestResourceStream/connectors/%s", test.Filename)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestResourceStream/connectors/%s", test.Filename)), Check: resource.ComposeTestCheckFunc(test.TestChecks...), }, }, diff --git a/pkg/providers/dns/data_authorities_set_test.go b/pkg/providers/dns/data_authorities_set_test.go index 2c8741903..2684b2433 100644 --- a/pkg/providers/dns/data_authorities_set_test.go +++ b/pkg/providers/dns/data_authorities_set_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/dns" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -30,7 +31,7 @@ func TestDataSourceAuthoritiesSet_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataSetAuthorities/basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataSetAuthorities/basic.tf"), Check: resource.ComposeTestCheckFunc( // check the values set in dataSourceAuthoritiesSetRead // authorities is an array that becomes authorities.0 and authorities.1 in tf state @@ -55,7 +56,7 @@ func TestDataSourceAuthoritiesSet_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataSetAuthorities/missing_contract.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataSetAuthorities/missing_contract.tf"), ExpectError: regexp.MustCompile(`Missing required argument`), }, }, @@ -78,7 +79,7 @@ func TestDataSourceAuthoritiesSet_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataSetAuthorities/basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataSetAuthorities/basic.tf"), ExpectError: regexp.MustCompile(`invalid contract`), }, }, diff --git a/pkg/providers/dns/data_dns_record_set_test.go b/pkg/providers/dns/data_dns_record_set_test.go index 16d7bc36d..e815cba7f 100644 --- a/pkg/providers/dns/data_dns_record_set_test.go +++ b/pkg/providers/dns/data_dns_record_set_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/dns" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -33,7 +34,7 @@ func TestDataSourceDNSRecordSet_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDnsRecordSet/basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDnsRecordSet/basic.tf"), Check: resource.ComposeTestCheckFunc( // check the values set in dataSourceDNSRecordSetRead // rdata is an array that becomes rdata.0 and rdata.1 in tf state @@ -65,7 +66,7 @@ func TestDataSourceDNSRecordSet_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDnsRecordSet/basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDnsRecordSet/basic.tf"), ExpectError: regexp.MustCompile(`invalid zone`), }, }, diff --git a/pkg/providers/dns/provider_test.go b/pkg/providers/dns/provider_test.go index 9bd7f5b14..61e794a5e 100644 --- a/pkg/providers/dns/provider_test.go +++ b/pkg/providers/dns/provider_test.go @@ -1,7 +1,6 @@ package dns import ( - "io/ioutil" "log" "os" "sync" @@ -71,17 +70,3 @@ func (d *data) GetOk(key string) (interface{}, bool) { func (d *data) List() []interface{} { return []interface{}{d.data} } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(path string) string { - return string(loadFixtureBytes(path)) -} diff --git a/pkg/providers/dns/resource_akamai_dns_record_test.go b/pkg/providers/dns/resource_akamai_dns_record_test.go index 93c5d65d3..a58714c05 100644 --- a/pkg/providers/dns/resource_akamai_dns_record_test.go +++ b/pkg/providers/dns/resource_akamai_dns_record_test.go @@ -7,8 +7,9 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/dns" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/session" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -88,13 +89,13 @@ func TestResDnsRecord(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDnsRecord/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDnsRecord/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "recordtype", "A"), ), }, { - Config: loadFixtureString("testdata/TestResDnsRecord/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDnsRecord/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "recordtype", "A"), ), @@ -200,7 +201,7 @@ func TestResDnsRecord(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDnsRecord/create_basic_txt.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDnsRecord/create_basic_txt.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "recordtype", "TXT"), resource.TestCheckResourceAttr(dataSourceName, "target.#", "1"), diff --git a/pkg/providers/dns/resource_akamai_dns_zone_test.go b/pkg/providers/dns/resource_akamai_dns_zone_test.go index e5d5ee4d7..c779309c4 100644 --- a/pkg/providers/dns/resource_akamai_dns_zone_test.go +++ b/pkg/providers/dns/resource_akamai_dns_zone_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/dns" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -80,13 +81,13 @@ func TestResDnsZone(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResDnsZone/create_primary.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDnsZone/create_primary.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "zone", "primaryexampleterraform.io"), ), }, { - Config: loadFixtureString("testdata/TestResDnsZone/update_primary.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResDnsZone/update_primary.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "zone", "primaryexampleterraform.io"), ), diff --git a/pkg/providers/edgeworkers/data_akamai_edgekv_group_items_test.go b/pkg/providers/edgeworkers/data_akamai_edgekv_group_items_test.go index 32196de8b..cb25c530c 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgekv_group_items_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgekv_group_items_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/edgeworkers/data_akamai_edgekv_groups_test.go b/pkg/providers/edgeworkers/data_akamai_edgekv_groups_test.go index 23032a7dc..ddb8117c5 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgekv_groups_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgekv_groups_test.go @@ -6,7 +6,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/edgeworkers/data_akamai_edgeworker_activation_test.go b/pkg/providers/edgeworkers/data_akamai_edgeworker_activation_test.go index e54c2b5fc..fab0ca51a 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgeworker_activation_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgeworker_activation_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -197,7 +198,7 @@ func TestDataEdgeWorkersActivation(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkAttrsForEdgeWorkerActivation(test.mockData), ExpectError: test.error, }, diff --git a/pkg/providers/edgeworkers/data_akamai_edgeworker_test.go b/pkg/providers/edgeworkers/data_akamai_edgeworker_test.go index 6d31485cc..f0a77d5df 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgeworker_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgeworker_test.go @@ -10,7 +10,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -330,7 +331,7 @@ func TestDataEdgeWorkersEdgeWorker(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkAttrsForEdgeWorker(test.mockData), ExpectError: test.error, }, diff --git a/pkg/providers/edgeworkers/data_akamai_edgeworkers_property_rules_test.go b/pkg/providers/edgeworkers/data_akamai_edgeworkers_property_rules_test.go index c44bf9f5f..be2a28293 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgeworkers_property_rules_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgeworkers_property_rules_test.go @@ -3,7 +3,8 @@ package edgeworkers import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataEdgeworkersPropertyRules(t *testing.T) { @@ -23,11 +24,11 @@ func TestDataEdgeworkersPropertyRules(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_edgeworkers_property_rules.test", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), resource.TestCheckResourceAttr( "data.akamai_edgeworkers_property_rules.test", "id", "123"), ), diff --git a/pkg/providers/edgeworkers/data_akamai_edgeworkers_resource_tier_test.go b/pkg/providers/edgeworkers/data_akamai_edgeworkers_resource_tier_test.go index c046228ae..8f58049ea 100644 --- a/pkg/providers/edgeworkers/data_akamai_edgeworkers_resource_tier_test.go +++ b/pkg/providers/edgeworkers/data_akamai_edgeworkers_resource_tier_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -34,7 +35,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), Check: resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "resource_tier_id", "100"), }, }, @@ -58,7 +59,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/ctr_prefix.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/ctr_prefix.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "resource_tier_id", "100"), resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "contract_id", "ctr_1-599K"), @@ -85,14 +86,14 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "resource_tier_id", "100"), resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "contract_id", "1-599K"), ), }, { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/ctr_prefix.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/ctr_prefix.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "resource_tier_id", "100"), resource.TestCheckResourceAttr("data.akamai_edgeworkers_resource_tier.test", "contract_id", "ctr_1-599K"), @@ -108,7 +109,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/basic.tf"), ExpectError: regexp.MustCompile("oops"), }, }, @@ -132,7 +133,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/incorrect_resource_tier_name.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/incorrect_resource_tier_name.tf"), ExpectError: regexp.MustCompile("Resource tier with name: 'Incorrect' was not found"), }, }, @@ -141,7 +142,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { init: func(m *edgeworkers.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/missing_contract_id.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/missing_contract_id.tf"), ExpectError: regexp.MustCompile(`The argument "contract_id" is required, but no definition was found`), }, }, @@ -150,7 +151,7 @@ func TestDataEdgeworkersResourceTier(t *testing.T) { init: func(m *edgeworkers.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDataEdgeWorkersResourceTier/missing_resource_tier_name.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDataEdgeWorkersResourceTier/missing_resource_tier_name.tf"), ExpectError: regexp.MustCompile(`The argument "resource_tier_name" is required, but no definition was found`), }, }, diff --git a/pkg/providers/edgeworkers/provider_test.go b/pkg/providers/edgeworkers/provider_test.go index 707da4445..6526b27db 100644 --- a/pkg/providers/edgeworkers/provider_test.go +++ b/pkg/providers/edgeworkers/provider_test.go @@ -1,8 +1,6 @@ package edgeworkers import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -51,17 +49,3 @@ func useClient(client edgeworkers.Edgeworkers, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/edgeworkers/resource_akamai_edgekv_group_items_test.go b/pkg/providers/edgeworkers/resource_akamai_edgekv_group_items_test.go index 51ceb72c9..72884148e 100644 --- a/pkg/providers/edgeworkers/resource_akamai_edgekv_group_items_test.go +++ b/pkg/providers/edgeworkers/resource_akamai_edgekv_group_items_test.go @@ -8,8 +8,9 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -160,7 +161,7 @@ func TestCreateEdgeKVGroupItems(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkEdgeKVGroupItemsAttrs(test.attrs), ExpectError: test.withError, }, @@ -325,12 +326,12 @@ func TestReadEdgeKVGroupItems(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPathForCreate), + Config: testutils.LoadFixtureString(t, test.configPathForCreate), Check: checkEdgeKVGroupItemsAttrs(test.attrsForCreate), ExpectError: test.errorForCreate, }, { - Config: loadFixtureString(test.configPathForUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForUpdate), Check: checkEdgeKVGroupItemsAttrs(test.attrsForUpdate), ExpectError: test.errorForUpdate, }, @@ -814,12 +815,12 @@ func TestUpdateEdgeKVGroupItems(t *testing.T) { { PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.expectNonEmptyPlan, - Config: loadFixtureString(test.configPathForCreate), + Config: testutils.LoadFixtureString(t, test.configPathForCreate), Check: checkEdgeKVGroupItemsAttrs(test.attrsForCreate), ExpectError: test.errorForCreate, }, { - Config: loadFixtureString(test.configPathForUpdate), + Config: testutils.LoadFixtureString(t, test.configPathForUpdate), Check: checkEdgeKVGroupItemsAttrs(test.attrsForUpdate), ExpectError: test.errorForUpdate, }, @@ -886,7 +887,7 @@ func TestDeleteEdgeKVGroupItems(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkEdgeKVGroupItemsAttrs(test.attrs), ExpectError: test.error, }, @@ -960,7 +961,7 @@ func TestImportEdgeKVGroupItems(t *testing.T) { Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), }, { ImportState: true, diff --git a/pkg/providers/edgeworkers/resource_akamai_edgekv_test.go b/pkg/providers/edgeworkers/resource_akamai_edgekv_test.go index 167e3f921..e9cfe2ebf 100644 --- a/pkg/providers/edgeworkers/resource_akamai_edgekv_test.go +++ b/pkg/providers/edgeworkers/resource_akamai_edgekv_test.go @@ -9,8 +9,9 @@ import ( "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" "github.com/stretchr/testify/mock" @@ -188,7 +189,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -212,7 +213,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic_retention_0.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic_retention_0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -237,7 +238,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/ekv_with_data.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/ekv_with_data.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -261,7 +262,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/ekv_with_data.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/ekv_with_data.tf"), ExpectError: regexp.MustCompile("The requested namespace does not exist"), }, }, @@ -274,7 +275,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), ExpectError: regexp.MustCompile(anError), }, }, @@ -288,7 +289,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), ExpectError: regexp.MustCompile("there was a timeout initializing"), }, }, @@ -301,7 +302,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), ExpectError: regexp.MustCompile(anError), }, }, @@ -316,7 +317,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), ExpectError: regexp.MustCompile(anError), }, }, @@ -331,7 +332,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -341,7 +342,7 @@ func TestResourceEdgeKV(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -362,7 +363,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -372,7 +373,7 @@ func TestResourceEdgeKV(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/update_diff_group_id.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/update_diff_group_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -397,7 +398,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -407,7 +408,7 @@ func TestResourceEdgeKV(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/update_retention.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/update_retention.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -428,7 +429,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgekv.test", "id", id), resource.TestCheckResourceAttr("akamai_edgekv.test", "namespace_name", namespaceName), @@ -438,7 +439,7 @@ func TestResourceEdgeKV(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/update_data.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/update_data.tf"), ExpectError: regexp.MustCompile("the field \"initial_data\" cannot be updated after resource creation"), }, }, @@ -457,7 +458,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), }, { ImportState: true, @@ -479,7 +480,7 @@ func TestResourceEdgeKV(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceEdgeWorkersEdgeKV/basic.tf"), }, { ImportState: true, diff --git a/pkg/providers/edgeworkers/resource_akamai_edgeworker_test.go b/pkg/providers/edgeworkers/resource_akamai_edgeworker_test.go index aa1c3bb86..30126ac51 100644 --- a/pkg/providers/edgeworkers/resource_akamai_edgeworker_test.go +++ b/pkg/providers/edgeworkers/resource_akamai_edgeworker_test.go @@ -14,7 +14,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/tj/assert" @@ -381,7 +382,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -427,7 +428,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_no_bundle.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_no_bundle.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -463,7 +464,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -474,7 +475,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_update_local_bundle.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_update_local_bundle.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -534,7 +535,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { Steps: []resource.TestStep{ { PreConfig: prepareTempBundleLink(t, bundlePathForCreate, tempBundlePath), - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_temp_bundle.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_temp_bundle.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -546,7 +547,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { }, { PreConfig: prepareTempBundleLink(t, bundlePathForUpdate, tempBundlePath), - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_temp_bundle.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_temp_bundle.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -582,7 +583,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -593,7 +594,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_update_group_id.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_update_group_id.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12346", @@ -625,7 +626,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -636,7 +637,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_update_group_id_prefix.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_update_group_id_prefix.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -672,7 +673,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -683,7 +684,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_update_name.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_update_name.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example update", groupID: "12345", @@ -756,7 +757,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -820,7 +821,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), Check: checkAttributes(edgeWorkerAttributes{ name: "example", groupID: "12345", @@ -853,7 +854,7 @@ func TestResourceEdgeWorkersEdgeWorker(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworker_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworker_create.tf", testDir)), }, { ImportState: true, diff --git a/pkg/providers/edgeworkers/resource_akamai_edgeworkers_activation_test.go b/pkg/providers/edgeworkers/resource_akamai_edgeworkers_activation_test.go index cfc4a1eb7..c11515389 100644 --- a/pkg/providers/edgeworkers/resource_akamai_edgeworkers_activation_test.go +++ b/pkg/providers/edgeworkers/resource_akamai_edgeworkers_activation_test.go @@ -7,7 +7,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/edgeworkers" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -44,7 +45,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -98,7 +99,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "8"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -134,7 +135,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -174,7 +175,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -212,7 +213,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -255,7 +256,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -263,7 +264,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_prod.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_prod.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "2"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -307,7 +308,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -315,7 +316,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "2"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test1"), @@ -367,7 +368,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -375,7 +376,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "3"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test1"), @@ -415,7 +416,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -423,7 +424,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "2"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test1"), @@ -470,7 +471,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -478,7 +479,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_prod.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_prod.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "2"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -530,7 +531,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "edgeworker_id", "1234"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), @@ -539,7 +540,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_different_edgeworker_id.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_different_edgeworker_id.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "edgeworker_id", "4321"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), @@ -575,7 +576,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -614,7 +615,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -651,7 +652,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -689,7 +690,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -721,7 +722,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), }, { ImportState: true, @@ -735,15 +736,15 @@ func TestResourceEdgeworkersActivation(t *testing.T) { init: func(m *edgeworkers.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), ExpectError: regexp.MustCompile("argument \"version\" is required"), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), ExpectError: regexp.MustCompile("argument \"edgeworker_id\" is required"), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_missing_required_args.tf", workdir)), ExpectError: regexp.MustCompile("argument \"edgeworker_id\" is required"), }, }, @@ -759,7 +760,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile(`version 'test' is not valid for edgeworker with id=1234`), }, }, @@ -775,7 +776,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: oops"), }, }, @@ -794,7 +795,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: oops"), }, }, @@ -806,7 +807,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: oops"), }, }, @@ -823,7 +824,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: oops"), }, }, @@ -847,7 +848,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: oops"), }, }, @@ -871,7 +872,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: edgeworker activation failure"), }, }, @@ -900,7 +901,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -908,7 +909,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), ExpectError: regexp.MustCompile(`version 'test1' is not valid for edgeworker with id=1234`), }, }, @@ -937,7 +938,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -945,7 +946,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_different_edgeworker_id.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_different_edgeworker_id.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation: edgeworker with id=4321 was not found"), }, }, @@ -982,7 +983,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -990,7 +991,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), ExpectError: regexp.MustCompile("edgeworker activation read: no version active on network 'STAGING' for edgeworker with id=1234"), }, }, @@ -1029,7 +1030,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "activation_id", "1"), resource.TestCheckResourceAttr("akamai_edgeworkers_activation.test", "version", "test"), @@ -1037,7 +1038,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test1_stag.tf", workdir)), ExpectError: regexp.MustCompile(`edgeworker activation: oops`), }, }, @@ -1049,7 +1050,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_version_test_stag.tf", workdir)), ExpectError: regexp.MustCompile(`edgeworker activation: oops`), }, }, @@ -1078,7 +1079,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), }, { ImportState: true, @@ -1111,7 +1112,7 @@ func TestResourceEdgeworkersActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/edgeworkers_activation_import.tf", workdir)), }, { ImportState: true, diff --git a/pkg/providers/gtm/data_akamai_gtm_datacenter_test.go b/pkg/providers/gtm/data_akamai_gtm_datacenter_test.go index 607340e0e..97a4953f9 100644 --- a/pkg/providers/gtm/data_akamai_gtm_datacenter_test.go +++ b/pkg/providers/gtm/data_akamai_gtm_datacenter_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -70,7 +71,7 @@ func TestDataGTMDatacenter(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkAttrsForGTMDatacenter(test.mockData), ExpectError: test.error, }, diff --git a/pkg/providers/gtm/data_akamai_gtm_datacenters_test.go b/pkg/providers/gtm/data_akamai_gtm_datacenters_test.go index 0bf982dc9..17205e406 100644 --- a/pkg/providers/gtm/data_akamai_gtm_datacenters_test.go +++ b/pkg/providers/gtm/data_akamai_gtm_datacenters_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -65,7 +66,7 @@ func TestDataGTMDatacenters(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkAttrsForGTMDatacenters(test.mockData), ExpectError: test.error, }, diff --git a/pkg/providers/gtm/data_akamai_gtm_default_datacenter_test.go b/pkg/providers/gtm/data_akamai_gtm_default_datacenter_test.go index b35af394c..43638ceb8 100644 --- a/pkg/providers/gtm/data_akamai_gtm_default_datacenter_test.go +++ b/pkg/providers/gtm/data_akamai_gtm_default_datacenter_test.go @@ -4,7 +4,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -32,7 +33,7 @@ func TestAccDataSourceGTMDefaultDatacenter_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDataDefaultDatacenter/basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataDefaultDatacenter/basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrSet(dataSourceName, "id"), ), diff --git a/pkg/providers/gtm/provider_test.go b/pkg/providers/gtm/provider_test.go index 74d6d6440..b98cf76a5 100644 --- a/pkg/providers/gtm/provider_test.go +++ b/pkg/providers/gtm/provider_test.go @@ -1,7 +1,6 @@ package gtm import ( - "io/ioutil" "log" "os" "sync" @@ -51,17 +50,3 @@ func useClient(client gtm.GTM, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(path string) string { - return string(loadFixtureBytes(path)) -} diff --git a/pkg/providers/gtm/resource_akamai_gtm_asmap_test.go b/pkg/providers/gtm/resource_akamai_gtm_asmap_test.go index 5f2551599..09966d9f2 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_asmap_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_asmap_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -78,13 +79,13 @@ func TestResGtmAsmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmAsmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_as_1"), ), }, { - Config: loadFixtureString("testdata/TestResGtmAsmap/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_as_1"), ), @@ -123,7 +124,7 @@ func TestResGtmAsmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmAsmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/create_basic.tf"), ExpectError: regexp.MustCompile("asMap Create failed"), }, }, @@ -161,7 +162,7 @@ func TestResGtmAsmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmAsmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -222,13 +223,13 @@ func TestResGtmAsmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmAsmap/import_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/import_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_as_1"), ), }, { - Config: loadFixtureString("testdata/TestResGtmAsmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmAsmap/create_basic.tf"), ImportState: true, ImportStateVerify: true, ImportStateId: fmt.Sprintf("%s:%s", gtmTestDomain, "tfexample_as_1"), @@ -323,10 +324,10 @@ func TestGTMAsMapOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_cidrmap_test.go b/pkg/providers/gtm/resource_akamai_gtm_cidrmap_test.go index 83b34aaef..d81651678 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_cidrmap_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_cidrmap_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -70,13 +71,13 @@ func TestResGtmCidrmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmCidrmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmCidrmap/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_cidrmap_1"), ), }, { - Config: loadFixtureString("testdata/TestResGtmCidrmap/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmCidrmap/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_cidrmap_1"), ), @@ -115,7 +116,7 @@ func TestResGtmCidrmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmCidrmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmCidrmap/create_basic.tf"), ExpectError: regexp.MustCompile("cidrMap Create failed"), }, }, @@ -153,7 +154,7 @@ func TestResGtmCidrmap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmCidrmap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmCidrmap/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -245,10 +246,10 @@ func TestGTMCidrMapOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_datacenter_test.go b/pkg/providers/gtm/resource_akamai_gtm_datacenter_test.go index b9ba9e638..44b9b433d 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_datacenter_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_datacenter_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -88,14 +89,14 @@ func TestResGtmDatacenter(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDatacenter/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDatacenter/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "nickname", "tfexample_dc_1"), resource.TestCheckResourceAttr(dataSourceName, "continent", "EU"), ), }, { - Config: loadFixtureString("testdata/TestResGtmDatacenter/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDatacenter/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "nickname", "tfexample_dc_1"), resource.TestCheckResourceAttr(dataSourceName, "continent", "NA"), @@ -128,7 +129,7 @@ func TestResGtmDatacenter(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDatacenter/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDatacenter/create_basic.tf"), ExpectError: regexp.MustCompile("Datacenter Create failed"), }, }, @@ -159,7 +160,7 @@ func TestResGtmDatacenter(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDatacenter/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDatacenter/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_domain_test.go b/pkg/providers/gtm/resource_akamai_gtm_domain_test.go index fd0bab327..d4810c41a 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_domain_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_domain_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -62,7 +63,7 @@ func TestResGtmDomain(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", gtmTestDomain), resource.TestCheckResourceAttr(resourceName, "type", "weighted"), @@ -70,7 +71,7 @@ func TestResGtmDomain(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResGtmDomain/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", gtmTestDomain), resource.TestCheckResourceAttr(resourceName, "type", "weighted"), @@ -126,7 +127,7 @@ func TestResGtmDomain(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", gtmTestDomain), resource.TestCheckResourceAttr(resourceName, "type", "weighted"), @@ -134,7 +135,7 @@ func TestResGtmDomain(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResGtmDomain/update_domain_name.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/update_domain_name.tf"), ExpectError: regexp.MustCompile("Error: once the domain is created, updating its name is not allowed"), }, }, @@ -166,7 +167,7 @@ func TestResGtmDomain(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), ExpectError: regexp.MustCompile("Domain Create failed"), }, }, @@ -199,7 +200,7 @@ func TestResGtmDomain(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -251,7 +252,7 @@ func TestResGtmDomain(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", gtmTestDomain), resource.TestCheckResourceAttr(resourceName, "type", "weighted"), @@ -259,7 +260,7 @@ func TestResGtmDomain(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResGtmDomain/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmDomain/create_basic.tf"), ImportState: true, ImportStateId: gtmTestDomain, ResourceName: resourceName, @@ -306,10 +307,10 @@ func TestGTMDomainOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_geomap_test.go b/pkg/providers/gtm/resource_akamai_gtm_geomap_test.go index a31dab7e1..db846d01c 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_geomap_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_geomap_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -75,13 +76,13 @@ func TestResGtmGeomap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmGeomap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmGeomap/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_geomap_1"), ), }, { - Config: loadFixtureString("testdata/TestResGtmGeomap/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmGeomap/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_geomap_1"), ), @@ -120,7 +121,7 @@ func TestResGtmGeomap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmGeomap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmGeomap/create_basic.tf"), ExpectError: regexp.MustCompile("geoMap Create failed"), }, }, @@ -158,7 +159,7 @@ func TestResGtmGeomap(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmGeomap/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmGeomap/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -243,10 +244,10 @@ func TestGTMGeoMapOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_property_test.go b/pkg/providers/gtm/resource_akamai_gtm_property_test.go index 0e1aafef0..96c3c78c7 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_property_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_property_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -161,14 +162,14 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_prop_1"), resource.TestCheckResourceAttr(dataSourceName, "type", "weighted-round-robin"), ), }, { - Config: loadFixtureString("testdata/TestResGtmProperty/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_prop_1"), resource.TestCheckResourceAttr(dataSourceName, "type", "weighted-round-robin"), @@ -232,7 +233,7 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/create_basic.tf"), ExpectError: regexp.MustCompile("property Create failed"), }, }, @@ -294,7 +295,7 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -387,14 +388,14 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/test_object/test_object_not_required.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/test_object/test_object_not_required.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_prop_1"), resource.TestCheckResourceAttr(dataSourceName, "type", "weighted-round-robin"), ), }, { - Config: loadFixtureString("testdata/TestResGtmProperty/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_prop_1"), resource.TestCheckResourceAttr(dataSourceName, "type", "weighted-round-robin"), @@ -415,7 +416,7 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/test_object/test_object_protocol_ftp.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/test_object/test_object_protocol_ftp.tf"), ExpectError: regexp.MustCompile(`Error: attribute 'test_object' is required when 'test_object_protocol' is set to 'HTTP', 'HTTPS' or 'FTP'`), }, }, @@ -433,7 +434,7 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/test_object/test_object_protocol_http.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/test_object/test_object_protocol_http.tf"), ExpectError: regexp.MustCompile(`Error: attribute 'test_object' is required when 'test_object_protocol' is set to 'HTTP', 'HTTPS' or 'FTP'`), }, }, @@ -451,7 +452,7 @@ func TestResGtmProperty(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmProperty/test_object/test_object_protocol_https.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmProperty/test_object/test_object_protocol_https.tf"), ExpectError: regexp.MustCompile(`Error: attribute 'test_object' is required when 'test_object_protocol' is set to 'HTTP', 'HTTPS' or 'FTP'`), }, }, @@ -565,10 +566,10 @@ func TestResourceGTMTrafficTargetOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/gtm/resource_akamai_gtm_resource_test.go b/pkg/providers/gtm/resource_akamai_gtm_resource_test.go index 3228949a2..187dca436 100644 --- a/pkg/providers/gtm/resource_akamai_gtm_resource_test.go +++ b/pkg/providers/gtm/resource_akamai_gtm_resource_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/gtm" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -87,14 +88,14 @@ func TestResGtmResource(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmResource/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmResource/create_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_resource_1"), resource.TestCheckResourceAttr(dataSourceName, "aggregation_type", "latest"), ), }, { - Config: loadFixtureString("testdata/TestResGtmResource/update_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmResource/update_basic.tf"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "name", "tfexample_resource_1"), resource.TestCheckResourceAttr(dataSourceName, "aggregation_type", "latest"), @@ -150,7 +151,7 @@ func TestResGtmResource(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmResource/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmResource/create_basic.tf"), ExpectError: regexp.MustCompile("Resource Create failed"), }, }, @@ -204,7 +205,7 @@ func TestResGtmResource(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResGtmResource/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResGtmResource/create_basic.tf"), ExpectError: regexp.MustCompile("Request could not be completed. Invalid credentials."), }, }, @@ -275,10 +276,10 @@ func TestGTMResourceOrder(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.pathForCreate), + Config: testutils.LoadFixtureString(t, test.pathForCreate), }, { - Config: loadFixtureString(test.pathForUpdate), + Config: testutils.LoadFixtureString(t, test.pathForUpdate), PlanOnly: test.planOnly, ExpectNonEmptyPlan: test.nonEmptyPlan, }, diff --git a/pkg/providers/iam/data_akamai_iam_contact_types_test.go b/pkg/providers/iam/data_akamai_iam_contact_types_test.go index 4fb362207..7cc4c2685 100644 --- a/pkg/providers/iam/data_akamai_iam_contact_types_test.go +++ b/pkg/providers/iam/data_akamai_iam_contact_types_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" diff --git a/pkg/providers/iam/data_akamai_iam_countries_test.go b/pkg/providers/iam/data_akamai_iam_countries_test.go index c3a6d08d7..36e25a02f 100644 --- a/pkg/providers/iam/data_akamai_iam_countries_test.go +++ b/pkg/providers/iam/data_akamai_iam_countries_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" diff --git a/pkg/providers/iam/data_akamai_iam_grantable_roles_test.go b/pkg/providers/iam/data_akamai_iam_grantable_roles_test.go index 5e8a8cfeb..2da24e136 100644 --- a/pkg/providers/iam/data_akamai_iam_grantable_roles_test.go +++ b/pkg/providers/iam/data_akamai_iam_grantable_roles_test.go @@ -7,7 +7,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/iam/data_akamai_iam_groups_test.go b/pkg/providers/iam/data_akamai_iam_groups_test.go index ac0edada8..71ec2af8a 100644 --- a/pkg/providers/iam/data_akamai_iam_groups_test.go +++ b/pkg/providers/iam/data_akamai_iam_groups_test.go @@ -5,8 +5,8 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/pkg/providers/iam/data_akamai_iam_roles_test.go b/pkg/providers/iam/data_akamai_iam_roles_test.go index c467ad4d0..915bd10fa 100644 --- a/pkg/providers/iam/data_akamai_iam_roles_test.go +++ b/pkg/providers/iam/data_akamai_iam_roles_test.go @@ -7,7 +7,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/iam/data_akamai_iam_states_test.go b/pkg/providers/iam/data_akamai_iam_states_test.go index ceee5df90..bf4a9aaf4 100644 --- a/pkg/providers/iam/data_akamai_iam_states_test.go +++ b/pkg/providers/iam/data_akamai_iam_states_test.go @@ -5,7 +5,7 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" diff --git a/pkg/providers/iam/data_akamai_iam_supported_langs_test.go b/pkg/providers/iam/data_akamai_iam_supported_langs_test.go index cfaa48c7a..664312c21 100644 --- a/pkg/providers/iam/data_akamai_iam_supported_langs_test.go +++ b/pkg/providers/iam/data_akamai_iam_supported_langs_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" diff --git a/pkg/providers/iam/data_akamai_iam_timeout_policies_test.go b/pkg/providers/iam/data_akamai_iam_timeout_policies_test.go index a561bb1e6..33b22d9ae 100644 --- a/pkg/providers/iam/data_akamai_iam_timeout_policies_test.go +++ b/pkg/providers/iam/data_akamai_iam_timeout_policies_test.go @@ -5,7 +5,7 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" diff --git a/pkg/providers/iam/data_akamai_iam_timezones_test.go b/pkg/providers/iam/data_akamai_iam_timezones_test.go index 748edd32f..fcace85a4 100644 --- a/pkg/providers/iam/data_akamai_iam_timezones_test.go +++ b/pkg/providers/iam/data_akamai_iam_timezones_test.go @@ -7,7 +7,7 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) diff --git a/pkg/providers/iam/provider_test.go b/pkg/providers/iam/provider_test.go index 3b0ed870e..01b0d1788 100644 --- a/pkg/providers/iam/provider_test.go +++ b/pkg/providers/iam/provider_test.go @@ -1,8 +1,6 @@ package iam import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -51,17 +49,3 @@ func useClient(client iam.IAM, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/iam/resource_akamai_iam_blocked_user_properties_test.go b/pkg/providers/iam/resource_akamai_iam_blocked_user_properties_test.go index 6d86628cf..f6652e8c4 100644 --- a/pkg/providers/iam/resource_akamai_iam_blocked_user_properties_test.go +++ b/pkg/providers/iam/resource_akamai_iam_blocked_user_properties_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -72,11 +73,11 @@ func TestResourceIAMBlockedUserProperties(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/create.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/create.tf"), Check: checkAttributes(propertiesCreate), }, { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/update.tf"), Check: checkAttributes(propertiesUpdate), }, }, @@ -102,11 +103,11 @@ func TestResourceIAMBlockedUserProperties(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/create.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/create.tf"), Check: checkAttributes(propertiesCreate), }, { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/update-group-id.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/update-group-id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_iam_blocked_user_properties.test", "id", "test_identity_id:23456"), resource.TestCheckResourceAttr("akamai_iam_blocked_user_properties.test", "identity_id", identityID), @@ -123,7 +124,7 @@ func TestResourceIAMBlockedUserProperties(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/create.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/create.tf"), ExpectError: regexp.MustCompile("there are already blocked properties on server, please import resource first"), }, }, @@ -132,7 +133,7 @@ func TestResourceIAMBlockedUserProperties(t *testing.T) { init: func(m *iam.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/create-empty-properties.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/create-empty-properties.tf"), ExpectError: regexp.MustCompile("Not enough list items"), }, }, @@ -152,7 +153,7 @@ func TestResourceIAMBlockedUserProperties(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceIAMBlockedUserProperties/create.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceIAMBlockedUserProperties/create.tf"), Check: checkAttributes(propertiesCreate), }, { diff --git a/pkg/providers/iam/resource_akamai_iam_group_test.go b/pkg/providers/iam/resource_akamai_iam_group_test.go index 13ae87ec2..c62877b7d 100644 --- a/pkg/providers/iam/resource_akamai_iam_group_test.go +++ b/pkg/providers/iam/resource_akamai_iam_group_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -36,7 +37,7 @@ func TestResourceGroup(t *testing.T) { "creation error": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResGroup/basic/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResGroup/basic/basic.tf"), ExpectError: regexp.MustCompile("group creation error"), }, }, @@ -47,7 +48,7 @@ func TestResourceGroup(t *testing.T) { "group read error": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResGroup/basic/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResGroup/basic/basic.tf"), ExpectError: regexp.MustCompile("group read error"), }, }, @@ -64,7 +65,7 @@ func TestResourceGroup(t *testing.T) { "basic": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResGroup/basic/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResGroup/basic/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_iam_group.test", "parent_group_id", strconv.FormatInt(groupCreate.ParentGroupID, 10)), resource.TestCheckResourceAttr("akamai_iam_group.test", "id", strconv.FormatInt(groupCreate.GroupID, 10)), @@ -92,7 +93,7 @@ func TestResourceGroup(t *testing.T) { "update": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResGroup/basic/basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResGroup/basic/basic.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_iam_group.test", "parent_group_id", strconv.FormatInt(groupCreate.ParentGroupID, 10)), resource.TestCheckResourceAttr("akamai_iam_group.test", "id", strconv.FormatInt(groupCreate.GroupID, 10)), @@ -104,7 +105,7 @@ func TestResourceGroup(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestResGroup/update/update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResGroup/update/update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_iam_group.test", "parent_group_id", strconv.FormatInt(groupUpdate.ParentGroupID, 10)), resource.TestCheckResourceAttr("akamai_iam_group.test", "id", strconv.FormatInt(groupUpdate.GroupID, 10)), diff --git a/pkg/providers/iam/resource_akamai_iam_role_test.go b/pkg/providers/iam/resource_akamai_iam_role_test.go index c6485c43c..532c647f8 100644 --- a/pkg/providers/iam/resource_akamai_iam_role_test.go +++ b/pkg/providers/iam/resource_akamai_iam_role_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -137,7 +138,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -166,7 +167,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -174,7 +175,7 @@ func TestResourceIAMRole(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/role_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_update.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name update", description: "role description update", @@ -200,7 +201,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -208,7 +209,7 @@ func TestResourceIAMRole(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/role_with_reordered_granted_roles.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_with_reordered_granted_roles.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -237,7 +238,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -245,7 +246,7 @@ func TestResourceIAMRole(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/role_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_update.tf", testDir)), ExpectError: regexp.MustCompile(updateAPIError), }, }, @@ -270,7 +271,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), Check: checkAttributes(roleAttributes{ name: "role name", description: "role description", @@ -278,7 +279,7 @@ func TestResourceIAMRole(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/role_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_update.tf", testDir)), ExpectError: regexp.MustCompile(readAPIError), }, }, @@ -300,7 +301,7 @@ func TestResourceIAMRole(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/role_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/role_create.tf", testDir)), }, { ImportState: true, diff --git a/pkg/providers/iam/resource_akamai_iam_user_test.go b/pkg/providers/iam/resource_akamai_iam_user_test.go index d623851bb..f0eeb8b1b 100644 --- a/pkg/providers/iam/resource_akamai_iam_user_test.go +++ b/pkg/providers/iam/resource_akamai_iam_user_test.go @@ -7,11 +7,12 @@ import ( "strings" "testing" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" "github.com/stretchr/testify/assert" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/iam" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -279,7 +280,7 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, }, @@ -295,7 +296,7 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic_lock.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic_lock.tf"), Check: checkUserAttributes(userCreateLocked), }, }, @@ -307,7 +308,7 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), ExpectError: regexp.MustCompile("failed to create user: error create"), }, }, @@ -326,11 +327,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, }, @@ -352,11 +353,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/update_user_info.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/update_user_info.tf"), Check: checkUserAttributes(userUpdateInfo), }, }, @@ -382,15 +383,15 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic_lock.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic_lock.tf"), Check: checkUserAttributes(userCreateLocked), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, }, @@ -411,11 +412,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/update_user_info.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/update_user_info.tf"), ExpectError: regexp.MustCompile("failed to update user: error updating"), }, }, @@ -437,11 +438,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/update_auth_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/update_auth_grants.tf"), Check: checkUserAttributes(userUpdateGrants), }, }, @@ -460,11 +461,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic_grants.tf"), Check: checkUserAttributes(userSubgroupCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic_grants_swap.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic_grants_swap.tf"), Check: checkUserAttributes(userSubgroupCreate), }, }, @@ -485,11 +486,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_auth_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_auth_grants.tf"), Check: checkUserAttributes(userCreateWithIgnoredFieldsResponse), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_auth_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_auth_grants.tf"), Check: checkUserAttributes(userCreateWithIgnoredFieldsResponse), }, }, @@ -510,11 +511,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/update_auth_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/update_auth_grants.tf"), ExpectError: regexp.MustCompile("failed to update user AuthGrants: error update user auth grants"), }, }, @@ -533,7 +534,7 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { @@ -549,7 +550,7 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/auth_grants_interpolated.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/auth_grants_interpolated.tf"), PlanOnly: true, ExpectNonEmptyPlan: true, }, @@ -569,11 +570,11 @@ func TestResourceUser(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/create_basic.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/create_basic.tf"), Check: checkUserAttributes(userCreate), }, { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/update_email.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/update_email.tf"), ExpectError: regexp.MustCompile("cannot change email address"), }, }, @@ -582,7 +583,7 @@ func TestResourceUser(t *testing.T) { init: func(m *iam.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestResourceUserLifecycle/invalid_auth_grants.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestResourceUserLifecycle/invalid_auth_grants.tf"), ExpectError: regexp.MustCompile("auth_grants_json is not valid"), }, }, diff --git a/pkg/providers/imaging/data_akamai_imaging_policy_image_test.go b/pkg/providers/imaging/data_akamai_imaging_policy_image_test.go index f4d7a2583..de7708a3b 100644 --- a/pkg/providers/imaging/data_akamai_imaging_policy_image_test.go +++ b/pkg/providers/imaging/data_akamai_imaging_policy_image_test.go @@ -3,7 +3,8 @@ package imaging import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataPolicyImage(t *testing.T) { @@ -39,11 +40,11 @@ func TestDataPolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_imaging_policy_image.policy", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), ), }, }, diff --git a/pkg/providers/imaging/data_akamai_imaging_policy_video_test.go b/pkg/providers/imaging/data_akamai_imaging_policy_video_test.go index 7ed8415f2..85929656e 100644 --- a/pkg/providers/imaging/data_akamai_imaging_policy_video_test.go +++ b/pkg/providers/imaging/data_akamai_imaging_policy_video_test.go @@ -3,7 +3,8 @@ package imaging import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataPolicyVideo(t *testing.T) { @@ -27,11 +28,11 @@ func TestDataPolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr( "data.akamai_imaging_policy_video.policy", "json", - loadFixtureString(test.expectedJSONPath)), + testutils.LoadFixtureString(t, test.expectedJSONPath)), ), }, }, diff --git a/pkg/providers/imaging/provider_test.go b/pkg/providers/imaging/provider_test.go index 946ee48c2..5427f970e 100644 --- a/pkg/providers/imaging/provider_test.go +++ b/pkg/providers/imaging/provider_test.go @@ -1,8 +1,6 @@ package imaging import ( - "fmt" - "io/ioutil" "log" "os" "sync" @@ -53,17 +51,3 @@ func useClient(client imaging.Imaging, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} diff --git a/pkg/providers/imaging/resource_akamai_imaging_policy_image_test.go b/pkg/providers/imaging/resource_akamai_imaging_policy_image_test.go index 9c9a2f218..ed51d8970 100644 --- a/pkg/providers/imaging/resource_akamai_imaging_policy_image_test.go +++ b/pkg/providers/imaging/resource_akamai_imaging_policy_image_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/imaging" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/tj/assert" ) @@ -172,7 +173,7 @@ func TestResourcePolicyImage(t *testing.T) { checkPolicyAttributes = func(attrs policyAttributes) resource.TestCheckFunc { var policyJSON string if attrs.policyPath != "" { - policyJSON = loadFixtureString(attrs.policyPath) + policyJSON = testutils.LoadFixtureString(t, attrs.policyPath) } f := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_imaging_policy_image.policy", "id", fmt.Sprintf("%s:%s", attrs.policySetID, attrs.policyID)), @@ -218,7 +219,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -250,7 +251,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -260,7 +261,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -301,7 +302,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -311,7 +312,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "2", policyID: "test_policy", @@ -349,7 +350,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -359,7 +360,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -397,7 +398,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -407,7 +408,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -417,7 +418,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update_staging.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update_staging.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "2", policyID: "test_policy", @@ -448,7 +449,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: ".auto", @@ -458,7 +459,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: ".auto", @@ -490,7 +491,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/default.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/default.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -500,7 +501,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/diff_order.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/diff_order.tf", testDir)), ExpectNonEmptyPlan: false, }, }, @@ -546,7 +547,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -556,7 +557,7 @@ func TestResourcePolicyImage(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -589,10 +590,10 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), }, { ImportState: true, @@ -623,7 +624,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -658,7 +659,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -698,7 +699,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -710,7 +711,7 @@ func TestResourcePolicyImage(t *testing.T) { //ImportStateVerify: true, }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), PlanOnly: true, }, }, @@ -727,7 +728,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("\"json\" contains an invalid JSON: invalid character '6' looking for beginning of object key string"), }, }, @@ -744,7 +745,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("unmarshalling transformation list: unsupported transformation type: MaxColors3"), }, }, @@ -771,7 +772,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("\"detail\": \"Policy fails to be properly created by AkaImaging: Unrecognized transformation type: MaxColors2\","), }, }, @@ -794,7 +795,7 @@ func TestResourcePolicyImage(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -890,8 +891,8 @@ func TestDiffSuppressPolicy(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - oldJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.oldPath)) - newJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.newPath)) + oldJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.oldPath)) + newJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.newPath)) res := diffSuppressPolicyImage("", oldJSON, newJSON, nil) assert.Equal(t, test.expected, res) }) diff --git a/pkg/providers/imaging/resource_akamai_imaging_policy_set_test.go b/pkg/providers/imaging/resource_akamai_imaging_policy_set_test.go index c9d3deaf2..492b18773 100644 --- a/pkg/providers/imaging/resource_akamai_imaging_policy_set_test.go +++ b/pkg/providers/imaging/resource_akamai_imaging_policy_set_test.go @@ -10,7 +10,8 @@ import ( "github.com/tj/assert" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/imaging" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestResourceImagingPolicySet(t *testing.T) { @@ -97,7 +98,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "id", "testID"), resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "name", "test_policy_set"), @@ -116,7 +117,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), ExpectError: regexp.MustCompile(anError.Error()), }, }, @@ -142,7 +143,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), ExpectError: regexp.MustCompile(anError.Error()), }, }, @@ -175,7 +176,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "id", "testID"), resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "name", "test_policy_set"), @@ -184,7 +185,7 @@ func TestResourceImagingPolicySet(t *testing.T) { ), }, { - Config: loadFixtureString("%s/lifecycle/update_region_us.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/update_region_us.tf", testDir), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "id", "testID"), resource.TestCheckResourceAttr("akamai_imaging_policy_set.test_image_set", "name", "test_policy_set"), @@ -214,7 +215,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), }, { ImportState: true, @@ -244,7 +245,7 @@ func TestResourceImagingPolicySet(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/lifecycle/create.tf", testDir), + Config: testutils.LoadFixtureString(t, "%s/lifecycle/create.tf", testDir), }, { ImportState: true, diff --git a/pkg/providers/imaging/resource_akamai_imaging_policy_video_test.go b/pkg/providers/imaging/resource_akamai_imaging_policy_video_test.go index 0e4698904..58f5f5cac 100644 --- a/pkg/providers/imaging/resource_akamai_imaging_policy_video_test.go +++ b/pkg/providers/imaging/resource_akamai_imaging_policy_video_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/imaging" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -129,7 +130,7 @@ func TestResourcePolicyVideo(t *testing.T) { checkPolicyAttributes = func(attrs policyAttributes) resource.TestCheckFunc { var policyJSON string if attrs.policyPath != "" { - policyJSON = loadFixtureString(attrs.policyPath) + policyJSON = testutils.LoadFixtureString(t, attrs.policyPath) } f := resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_imaging_policy_video.policy", "id", fmt.Sprintf("%s:%s", attrs.policySetID, attrs.policyID)), @@ -175,7 +176,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -207,7 +208,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -217,7 +218,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -258,7 +259,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -268,7 +269,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "2", policyID: "test_policy", @@ -306,7 +307,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -316,7 +317,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -354,7 +355,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -364,7 +365,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -374,7 +375,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update_staging.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update_staging.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "2", policyID: "test_policy", @@ -405,7 +406,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: ".auto", @@ -415,7 +416,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: ".auto", @@ -448,10 +449,10 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { - Config: loadFixtureString(fmt.Sprintf("%s/policy_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_update.tf", testDir)), }, { ImportState: true, @@ -482,7 +483,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/default.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/default.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -492,7 +493,7 @@ func TestResourcePolicyVideo(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/diff_order.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/diff_order.tf", testDir)), ExpectNonEmptyPlan: false, }, }, @@ -518,7 +519,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -553,7 +554,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -575,7 +576,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("\"json\" contains an invalid JSON: invalid character '6' looking for beginning of object key string"), }, }, @@ -598,7 +599,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), Check: checkPolicyAttributes(policyAttributes{ version: "1", policyID: "test_policy", @@ -631,7 +632,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), ExpectError: regexp.MustCompile("\"detail\": \"Unable to parse element 'output' in JSON.\","), }, }, @@ -654,7 +655,7 @@ func TestResourcePolicyVideo(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/policy_create.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/policy_create.tf", testDir)), }, { ImportState: true, @@ -726,8 +727,8 @@ func TestDiffSuppressPolicyVideo(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - oldJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.oldPath)) - newJSON := loadFixtureString(fmt.Sprintf("%s/%s", basePath, test.newPath)) + oldJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.oldPath)) + newJSON := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", basePath, test.newPath)) res := diffSuppressPolicyVideo("", oldJSON, newJSON, nil) assert.Equal(t, test.expected, res) }) diff --git a/pkg/providers/networklists/data_akamai_networklist_network_lists_test.go b/pkg/providers/networklists/data_akamai_networklist_network_lists_test.go index bc4655482..49d4492ce 100644 --- a/pkg/providers/networklists/data_akamai_networklist_network_lists_test.go +++ b/pkg/providers/networklists/data_akamai_networklist_network_lists_test.go @@ -5,7 +5,8 @@ import ( "testing" network "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/networklists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,7 +16,7 @@ func TestAccAkamaiNetworkList_data_basic(t *testing.T) { client := &network.Mock{} networkListsResponse := network.GetNetworkListsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSNetworkList/NetworkList.json"), &networkListsResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSNetworkList/NetworkList.json"), &networkListsResponse) require.NoError(t, err) client.On("GetNetworkLists", @@ -29,7 +30,7 @@ func TestAccAkamaiNetworkList_data_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSNetworkList/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSNetworkList/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_networklist_network_lists.test", "id", "365_AKAMAITOREXITNODES"), ), @@ -47,7 +48,7 @@ func TestAccAkamaiNetworkList_data_by_uniqueID(t *testing.T) { client := &network.Mock{} networkListResponse := network.GetNetworkListResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestDSNetworkList/SingleNetworkList.json"), &networkListResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestDSNetworkList/SingleNetworkList.json"), &networkListResponse) require.NoError(t, err) client.On("GetNetworkList", @@ -61,7 +62,7 @@ func TestAccAkamaiNetworkList_data_by_uniqueID(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSNetworkList/match_by_uniqueid.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSNetworkList/match_by_uniqueid.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_networklist_network_lists.test", "id", "86093_AGEOLIST"), resource.TestCheckResourceAttr("data.akamai_networklist_network_lists.test", "contract_id", "3-4168BG"), diff --git a/pkg/providers/networklists/provider_test.go b/pkg/providers/networklists/provider_test.go index efb5103bd..70fefd6b7 100644 --- a/pkg/providers/networklists/provider_test.go +++ b/pkg/providers/networklists/provider_test.go @@ -1,7 +1,6 @@ package networklists import ( - "io/ioutil" "log" "os" "sync" @@ -49,17 +48,3 @@ func useClient(client networklists.NTWRKLISTS, f func()) { f() } - -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(path string) string { - return string(loadFixtureBytes(path)) -} diff --git a/pkg/providers/networklists/resource_akamai_networklist_activations_test.go b/pkg/providers/networklists/resource_akamai_networklist_activations_test.go index 33c61f832..c87277299 100644 --- a/pkg/providers/networklists/resource_akamai_networklist_activations_test.go +++ b/pkg/providers/networklists/resource_akamai_networklist_activations_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/networklists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAccAkamaiActivations_res_basic(t *testing.T) { client := &networklists.Mock{} cu := networklists.RemoveActivationsResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/ActivationsDelete.json"), &cu) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/ActivationsDelete.json"), &cu) require.NoError(t, err) ga := networklists.GetActivationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/Activations.json"), &ga) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/Activations.json"), &ga) require.NoError(t, err) cr := networklists.CreateActivationsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResActivations/Activations.json"), &cr) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResActivations/Activations.json"), &cr) require.NoError(t, err) client.On("GetActivations", @@ -47,7 +48,7 @@ func TestAccAkamaiActivations_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResActivations/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResActivations/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_activations.test", "id", "547694"), resource.TestCheckResourceAttr("akamai_networklist_activations.test", "name", "Network list test"), @@ -57,7 +58,7 @@ func TestAccAkamaiActivations_res_basic(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResActivations/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResActivations/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_activations.test", "id", "547694"), resource.TestCheckResourceAttr("akamai_networklist_activations.test", "name", "Network list test"), diff --git a/pkg/providers/networklists/resource_akamai_networklist_network_list_description_test.go b/pkg/providers/networklists/resource_akamai_networklist_network_list_description_test.go index 35eb54e99..5c77afb02 100644 --- a/pkg/providers/networklists/resource_akamai_networklist_network_list_description_test.go +++ b/pkg/providers/networklists/resource_akamai_networklist_network_list_description_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/networklists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,11 +16,11 @@ func TestAccAkamaiNetworkListDescription_res_basic(t *testing.T) { client := &networklists.Mock{} cu := networklists.UpdateNetworkListDescriptionResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkListDescription/NetworkListDescription.json"), &cu) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkListDescription/NetworkListDescription.json"), &cu) require.NoError(t, err) cr := networklists.GetNetworkListDescriptionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkListDescription/NetworkListDescription.json"), &cr) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkListDescription/NetworkListDescription.json"), &cr) require.NoError(t, err) client.On("GetNetworkListDescription", @@ -38,7 +39,7 @@ func TestAccAkamaiNetworkListDescription_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResNetworkListDescription/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResNetworkListDescription/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_description.test", "id", "2275_VOYAGERCALLCENTERWHITELI"), ), diff --git a/pkg/providers/networklists/resource_akamai_networklist_network_list_subscription_test.go b/pkg/providers/networklists/resource_akamai_networklist_network_list_subscription_test.go index 14618c8c2..fe0ed1371 100644 --- a/pkg/providers/networklists/resource_akamai_networklist_network_list_subscription_test.go +++ b/pkg/providers/networklists/resource_akamai_networklist_network_list_subscription_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/networklists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,15 +16,15 @@ func TestAccAkamaiNetworkListSubscription_res_basic(t *testing.T) { client := &networklists.Mock{} cu := networklists.UpdateNetworkListSubscriptionResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cu) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cu) require.NoError(t, err) cr := networklists.GetNetworkListSubscriptionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cr) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cr) require.NoError(t, err) cd := networklists.RemoveNetworkListSubscriptionResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cd) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkListSubscription/NetworkListSubscription.json"), &cd) require.NoError(t, err) client.On("GetNetworkListSubscription", @@ -47,7 +48,7 @@ func TestAccAkamaiNetworkListSubscription_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResNetworkListSubscription/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResNetworkListSubscription/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_subscription.test", "id", "f7a36129f691baa1201d963b8537eb69caa28863:dd6085a7b8c8f8efaecbd420aff85a3e865ad5ca"), ), diff --git a/pkg/providers/networklists/resource_akamai_networklist_network_list_test.go b/pkg/providers/networklists/resource_akamai_networklist_network_list_test.go index 0f1c2f99a..e3f0c244e 100644 --- a/pkg/providers/networklists/resource_akamai_networklist_network_list_test.go +++ b/pkg/providers/networklists/resource_akamai_networklist_network_list_test.go @@ -5,7 +5,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/networklists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -15,27 +16,27 @@ func TestAccAkamaiNetworkList_res_basic(t *testing.T) { client := &networklists.Mock{} createResponse := networklists.CreateNetworkListResponse{} - err := json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/NetworkList.json"), &createResponse) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/NetworkList.json"), &createResponse) require.NoError(t, err) crl := networklists.GetNetworkListsResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/NetworkLists.json"), &crl) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/NetworkLists.json"), &crl) require.NoError(t, err) getResponse := networklists.GetNetworkListResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/NetworkList.json"), &getResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/NetworkList.json"), &getResponse) require.NoError(t, err) updateResponse := networklists.UpdateNetworkListResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/NetworkListUpdated.json"), &updateResponse) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/NetworkListUpdated.json"), &updateResponse) require.NoError(t, err) getResponseAfterUpdate := networklists.GetNetworkListResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/NetworkListUpdated.json"), &getResponseAfterUpdate) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/NetworkListUpdated.json"), &getResponseAfterUpdate) require.NoError(t, err) cd := networklists.RemoveNetworkListResponse{} - err = json.Unmarshal(loadFixtureBytes("testdata/TestResNetworkList/empty.json"), &cd) + err = json.Unmarshal(testutils.LoadFixtureBytes(t, "testdata/TestResNetworkList/empty.json"), &cd) require.NoError(t, err) client.On("CreateNetworkList", @@ -74,13 +75,13 @@ func TestAccAkamaiNetworkList_res_basic(t *testing.T) { ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResNetworkList/match_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResNetworkList/match_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_network_list.test", "name", "Voyager Call Center Whitelist"), ), }, { - Config: loadFixtureString("testdata/TestResNetworkList/update_by_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResNetworkList/update_by_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_networklist_network_list.test", "name", "Voyager Call Center Whitelist"), ), diff --git a/pkg/providers/property/data_akamai_contracts_test.go b/pkg/providers/property/data_akamai_contracts_test.go index 41b504ac3..8e9643869 100644 --- a/pkg/providers/property/data_akamai_contracts_test.go +++ b/pkg/providers/property/data_akamai_contracts_test.go @@ -4,9 +4,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/stretchr/testify/mock" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataContracts(t *testing.T) { @@ -31,7 +32,7 @@ func TestDataContracts(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataContracts/contracts.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataContracts/contracts.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_contracts.akacontracts", "id", "act_test"), resource.TestCheckOutput("aka_contract_id1", "ctr_test1"), diff --git a/pkg/providers/property/data_akamai_cp_code_test.go b/pkg/providers/property/data_akamai_cp_code_test.go index 998ae8fda..fac59e7a2 100644 --- a/pkg/providers/property/data_akamai_cp_code_test.go +++ b/pkg/providers/property/data_akamai_cp_code_test.go @@ -4,10 +4,11 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDSCPCode(t *testing.T) { @@ -29,7 +30,7 @@ func TestDSCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSCPCode/match_by_name.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCPCode/match_by_name.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_cp_code.test", "id", "234"), resource.TestCheckResourceAttr("data.akamai_cp_code.test", "name", "test cpcode"), @@ -61,7 +62,7 @@ func TestDSCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSCPCode/match_by_name_output_products.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCPCode/match_by_name_output_products.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_cp_code.test", "id", "234"), resource.TestCheckResourceAttr("data.akamai_cp_code.test", "name", "test cpcode"), @@ -95,7 +96,7 @@ func TestDSCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSCPCode/match_by_full_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCPCode/match_by_full_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_cp_code.test", "id", "234"), resource.TestCheckResourceAttr("data.akamai_cp_code.test", "name", "cpc_234"), @@ -127,7 +128,7 @@ func TestDSCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSCPCode/match_by_unprefixed_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCPCode/match_by_unprefixed_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_cp_code.test", "id", "234"), ), @@ -156,7 +157,7 @@ func TestDSCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSCPCode/match_by_unprefixed_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSCPCode/match_by_unprefixed_id.tf"), ExpectError: regexp.MustCompile(`cp code not found`), }}, }) @@ -181,7 +182,7 @@ func TestDSCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, IsUnitTest: true, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSGroupNotFound/cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSGroupNotFound/cp_code.tf"), }}, }) }) diff --git a/pkg/providers/property/data_akamai_properties_search_test.go b/pkg/providers/property/data_akamai_properties_search_test.go index 7c614031d..af75414c6 100644 --- a/pkg/providers/property/data_akamai_properties_search_test.go +++ b/pkg/providers/property/data_akamai_properties_search_test.go @@ -4,10 +4,11 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDSPropertiesSearch(t *testing.T) { @@ -56,7 +57,7 @@ func TestDSPropertiesSearch(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertiesSearch/match_by_hostname.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertiesSearch/match_by_hostname.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_properties_search.test", "id", "hostname:www.example.com"), resource.TestCheckResourceAttr("data.akamai_properties_search.test", "properties.#", "2"), @@ -97,7 +98,7 @@ func TestDSPropertiesSearch(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertiesSearch/match_by_hostname.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertiesSearch/match_by_hostname.tf"), ExpectError: regexp.MustCompile("searching for properties"), }}, }) diff --git a/pkg/providers/property/data_akamai_properties_test.go b/pkg/providers/property/data_akamai_properties_test.go index 33e9d8a77..646e08369 100644 --- a/pkg/providers/property/data_akamai_properties_test.go +++ b/pkg/providers/property/data_akamai_properties_test.go @@ -4,10 +4,11 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDataProperties(t *testing.T) { @@ -25,7 +26,7 @@ func TestDataProperties(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataProperties/properties.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataProperties/properties.tf"), Check: buildAggregatedTest(properties, "grp_testctr_test", "grp_test", "ctr_test"), }}, }) @@ -48,7 +49,7 @@ func TestDataProperties(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataProperties/properties_no_group_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataProperties/properties_no_group_prefix.tf"), Check: buildAggregatedTest(properties, "grp_testctr_test", "test", "ctr_test"), }}, }) @@ -71,7 +72,7 @@ func TestDataProperties(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataProperties/properties_no_contract_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataProperties/properties_no_contract_prefix.tf"), Check: buildAggregatedTest(properties, "grp_testctr_test", "grp_test", "test"), }}, }) diff --git a/pkg/providers/property/data_akamai_property_activation_test.go b/pkg/providers/property/data_akamai_property_activation_test.go index 79e0e1a20..fc8dfa5ab 100644 --- a/pkg/providers/property/data_akamai_property_activation_test.go +++ b/pkg/providers/property/data_akamai_property_activation_test.go @@ -6,7 +6,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataSourcePAPIPropertyActivation(t *testing.T) { @@ -36,7 +37,7 @@ func TestDataSourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("data.akamai_property_activation.test", "property_id", "prp_test"), @@ -58,7 +59,7 @@ func TestDataSourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("data.akamai_property_activation.test", "property_id", "prp_test"), @@ -77,7 +78,7 @@ func TestDataSourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDSPropertyActivation/ok/datasource_property_activation.tf"), ExpectError: regexp.MustCompile("failed to create request"), }, }, @@ -85,7 +86,7 @@ func TestDataSourcePAPIPropertyActivation(t *testing.T) { "check schema property activation - no property id": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDSPropertyActivation/no_propertyId/datasource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDSPropertyActivation/no_propertyId/datasource_property_activation.tf"), ExpectError: regexp.MustCompile("Error: Missing required argument"), }, }, @@ -96,7 +97,7 @@ func TestDataSourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestDSPropertyActivation/ok/datasource_property_activation_prod.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestDSPropertyActivation/ok/datasource_property_activation_prod.tf"), ExpectError: regexp.MustCompile("there is no active version on PRODUCTION network"), }, }, diff --git a/pkg/providers/property/data_akamai_property_hostnames_test.go b/pkg/providers/property/data_akamai_property_hostnames_test.go index e3193437d..19af25895 100644 --- a/pkg/providers/property/data_akamai_property_hostnames_test.go +++ b/pkg/providers/property/data_akamai_property_hostnames_test.go @@ -4,10 +4,11 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDataPropertyHostnames(t *testing.T) { @@ -49,7 +50,7 @@ func TestDataPropertyHostnames(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataPropertyHostnames/property_hostnames.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataPropertyHostnames/property_hostnames.tf"), Check: buildAggregatedHostnamesTest(hostnameItems, "prp_test1", "grp_test", "ctr_test", "prp_test"), }}, }) @@ -96,7 +97,7 @@ func TestDataPropertyHostnames(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataPropertyHostnames/property_hostnames_no_group_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataPropertyHostnames/property_hostnames_no_group_prefix.tf"), Check: buildAggregatedHostnamesTest(hostnameItems, "prp_test1", "test", "ctr_test", "prp_test"), }}, }) @@ -143,7 +144,7 @@ func TestDataPropertyHostnames(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataPropertyHostnames/property_hostnames_no_contract_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataPropertyHostnames/property_hostnames_no_contract_prefix.tf"), Check: buildAggregatedHostnamesTest(hostnameItems, "prp_test1", "grp_test", "test", "prp_test"), }}, }) @@ -190,7 +191,7 @@ func TestDataPropertyHostnames(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDataPropertyHostnames/property_hostnames_no_property_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDataPropertyHostnames/property_hostnames_no_property_prefix.tf"), Check: buildAggregatedHostnamesTest(hostnameItems, "prp_test1", "grp_test", "ctr_test", "prp_test"), }}, }) diff --git a/pkg/providers/property/data_akamai_property_include_activation_test.go b/pkg/providers/property/data_akamai_property_include_activation_test.go index 55fd01763..a9e8271db 100644 --- a/pkg/providers/property/data_akamai_property_include_activation_test.go +++ b/pkg/providers/property/data_akamai_property_include_activation_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -165,7 +166,7 @@ func TestDataPropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, IsUnitTest: true, Steps: []resource.TestStep{{ - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkPropertyIncludeActivationAttrs(test.attrs), ExpectError: test.error, }}, diff --git a/pkg/providers/property/data_akamai_property_include_parents_test.go b/pkg/providers/property/data_akamai_property_include_parents_test.go index 35780c739..a0967c016 100644 --- a/pkg/providers/property/data_akamai_property_include_parents_test.go +++ b/pkg/providers/property/data_akamai_property_include_parents_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -162,7 +163,7 @@ func TestDataPropertyIncludeParents(t *testing.T) { IsUnitTest: true, ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString(fmt.Sprintf("testdata/TestDataPropertyIncludeParents/%s", test.givenTF)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestDataPropertyIncludeParents/%s", test.givenTF)), Check: resource.ComposeAggregateTestCheckFunc(checkFuncs...), ExpectError: test.expectError, }}, diff --git a/pkg/providers/property/data_akamai_property_include_rules_test.go b/pkg/providers/property/data_akamai_property_include_rules_test.go index fc0a1456e..5ce28b885 100644 --- a/pkg/providers/property/data_akamai_property_include_rules_test.go +++ b/pkg/providers/property/data_akamai_property_include_rules_test.go @@ -9,7 +9,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -30,17 +31,6 @@ type testDataPropertyIncludeRules struct { var ( workdir = "./testdata/TestDSPropertyIncludeRules" - propertyIncludeRules = testDataPropertyIncludeRules{ - ContractID: "ctr_1", - GroupID: "grp_2", - IncludeID: "12345", - Version: 1, - RuleFormat: "v2022-06-28", - Name: "TestIncludeName", - IncludeType: "MICROSERVICES", - Rules: loadFixtureString("%s/property-snippets/rules_without_errors.json", workdir), - } - propertyIncludeRulesWithRuleErrors = func(propertyIncludeRules testDataPropertyIncludeRules, rulesErrors string) testDataPropertyIncludeRules { propertyIncludeRules.RuleErrors = rulesErrors return propertyIncludeRules @@ -72,7 +62,7 @@ var ( } var ruleResp papi.GetIncludeRuleTreeResponse - err := json.Unmarshal(loadFixtureBytes(path.Join(workdir, "expected-response", rulesFileName)), &ruleResp) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, path.Join(workdir, "expected-response", rulesFileName)), &ruleResp) assert.NoError(t, err) getIncludeRuleTreeResponse.Rules = ruleResp.Rules @@ -111,29 +101,29 @@ func TestDataPropertyIncludeRules(t *testing.T) { init: func(t *testing.T, m *papi.Mock, testData testDataPropertyIncludeRules) { expectReadPropertyRulesInclude(t, m, testData, 5, true, false, "rules_with_errors.json") }, - mockData: propertyIncludeRulesWithRuleErrors(propertyIncludeRules, loadFixtureString("%s/property-snippets/rule_errors.json", workdir)), + mockData: propertyIncludeRulesWithRuleErrors(testDataIncludeRules(t), testutils.LoadFixtureString(t, "%s/property-snippets/rule_errors.json", workdir)), configPath: "./testdata/TestDSPropertyIncludeRules/property_include_rules.tf", }, "happy path include rules with rules warnings": { init: func(t *testing.T, m *papi.Mock, testData testDataPropertyIncludeRules) { expectReadPropertyRulesInclude(t, m, testData, 5, false, true, "rules_with_warnings.json") }, - mockData: propertyIncludeRulesWithRuleWarnings(propertyIncludeRules, loadFixtureString("%s/property-snippets/rule_warnings.json", workdir)), + mockData: propertyIncludeRulesWithRuleWarnings(testDataIncludeRules(t), testutils.LoadFixtureString(t, "%s/property-snippets/rule_warnings.json", workdir)), configPath: "./testdata/TestDSPropertyIncludeRules/property_include_rules.tf", }, "happy path include rules with rules warnings and errors": { init: func(t *testing.T, m *papi.Mock, testData testDataPropertyIncludeRules) { expectReadPropertyRulesInclude(t, m, testData, 5, true, true, "rules_with_errors_and_warnings.json") }, - mockData: propertyIncludeRulesWithRuleWarningsAndErrors(propertyIncludeRules, loadFixtureString("%s/property-snippets/rule_warnings.json", workdir), - loadFixtureString("%s/property-snippets/rule_errors.json", workdir)), + mockData: propertyIncludeRulesWithRuleWarningsAndErrors(testDataIncludeRules(t), testutils.LoadFixtureString(t, "%s/property-snippets/rule_warnings.json", workdir), + testutils.LoadFixtureString(t, "%s/property-snippets/rule_errors.json", workdir)), configPath: "./testdata/TestDSPropertyIncludeRules/property_include_rules.tf", }, "happy path include rules": { init: func(t *testing.T, m *papi.Mock, testData testDataPropertyIncludeRules) { expectReadPropertyRulesInclude(t, m, testData, 5, false, false, "rules_without_errors.json") }, - mockData: propertyIncludeRules, + mockData: testDataIncludeRules(t), configPath: "./testdata/TestDSPropertyIncludeRules/property_include_rules.tf", }, "groupID not provided": { @@ -160,7 +150,7 @@ func TestDataPropertyIncludeRules(t *testing.T) { init: func(t *testing.T, m *papi.Mock, testData testDataPropertyIncludeRules) { expectGetIncludeRuleTreeError(t, m, testData) }, - mockData: propertyIncludeRulesWithRuleErrors(propertyIncludeRules, loadFixtureString("%s/property-snippets/rule_errors.json", workdir)), + mockData: propertyIncludeRulesWithRuleErrors(testDataIncludeRules(t), testutils.LoadFixtureString(t, "%s/property-snippets/rule_errors.json", workdir)), configPath: "./testdata/TestDSPropertyIncludeRules/property_include_rules_api_error.tf", error: regexp.MustCompile("GetIncludeRuleTree response error"), }, @@ -176,7 +166,7 @@ func TestDataPropertyIncludeRules(t *testing.T) { IsUnitTest: true, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkPropertyIncludeRulesAttrs(test.mockData, t), ExpectError: test.error, }, @@ -215,3 +205,17 @@ func checkPropertyIncludeRulesAttrs(data testDataPropertyIncludeRules, t *testin } return resource.ComposeAggregateTestCheckFunc(testCheckFuncs...) } + +func testDataIncludeRules(t *testing.T) testDataPropertyIncludeRules { + t.Helper() + return testDataPropertyIncludeRules{ + ContractID: "ctr_1", + GroupID: "grp_2", + IncludeID: "12345", + Version: 1, + RuleFormat: "v2022-06-28", + Name: "TestIncludeName", + IncludeType: "MICROSERVICES", + Rules: testutils.LoadFixtureString(t, "%s/property-snippets/rules_without_errors.json", workdir), + } +} diff --git a/pkg/providers/property/data_akamai_property_include_test.go b/pkg/providers/property/data_akamai_property_include_test.go index 1ce99ac2c..49ffe3266 100644 --- a/pkg/providers/property/data_akamai_property_include_test.go +++ b/pkg/providers/property/data_akamai_property_include_test.go @@ -6,10 +6,11 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" "github.com/stretchr/testify/mock" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestDataPropertyInclude(t *testing.T) { @@ -138,7 +139,7 @@ func TestDataPropertyInclude(t *testing.T) { IsUnitTest: true, ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString(fmt.Sprintf("testdata/TestDataPropertyInclude/%s", test.givenTF)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestDataPropertyInclude/%s", test.givenTF)), Check: resource.ComposeAggregateTestCheckFunc(checkFuncs...), ExpectError: test.expectError, }}, diff --git a/pkg/providers/property/data_akamai_property_includes_test.go b/pkg/providers/property/data_akamai_property_includes_test.go index 9cad943a4..9c39ef927 100644 --- a/pkg/providers/property/data_akamai_property_includes_test.go +++ b/pkg/providers/property/data_akamai_property_includes_test.go @@ -9,8 +9,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" ) @@ -299,7 +300,7 @@ func TestDataPropertyIncludes(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, IsUnitTest: true, Steps: []resource.TestStep{{ - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: checkPropertyIncludesAttrs(test.attrs), ExpectError: test.error, }}, diff --git a/pkg/providers/property/data_akamai_property_products_test.go b/pkg/providers/property/data_akamai_property_products_test.go index a92b29f0f..e326eba7d 100644 --- a/pkg/providers/property/data_akamai_property_products_test.go +++ b/pkg/providers/property/data_akamai_property_products_test.go @@ -5,7 +5,7 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" diff --git a/pkg/providers/property/data_akamai_property_rule_formats_test.go b/pkg/providers/property/data_akamai_property_rule_formats_test.go index bd30a44fb..165fb09f0 100644 --- a/pkg/providers/property/data_akamai_property_rule_formats_test.go +++ b/pkg/providers/property/data_akamai_property_rule_formats_test.go @@ -3,10 +3,11 @@ package property import ( "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func Test_readPropertyRuleFormats(t *testing.T) { @@ -24,7 +25,7 @@ func Test_readPropertyRuleFormats(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRuleFormats/rule_formats.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRuleFormats/rule_formats.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rule_formats.akarulesformats", "id", "rule_format"), resource.TestCheckResourceAttr("data.akamai_property_rule_formats.akarulesformats", "rule_format.0", "latest"), diff --git a/pkg/providers/property/data_akamai_property_rules_builder_test.go b/pkg/providers/property/data_akamai_property_rules_builder_test.go index aa2409e5a..ae61e30d2 100644 --- a/pkg/providers/property/data_akamai_property_rules_builder_test.go +++ b/pkg/providers/property/data_akamai_property_rules_builder_test.go @@ -5,9 +5,10 @@ import ( "regexp" "testing" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" ) func TestDataPropertyRulesBuilder(t *testing.T) { @@ -16,35 +17,35 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_v2023_01_05.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_v2023_01_05.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rules_builder.default", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.default", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/default.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/default.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.content_compression", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.content_compression", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/content_compression.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/content_compression.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.static_content", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.static_content", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/static_content.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/static_content.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.dynamic_content", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.dynamic_content", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/dynamic_content.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/dynamic_content.json")), ), }}, }) @@ -55,35 +56,35 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_v2023_05_30.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_v2023_05_30.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rules_builder.default", "rule_format", "v2023-05-30"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.default", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/default_v2023_05_30.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/default_v2023_05_30.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.content_compression", "rule_format", "v2023-05-30"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.content_compression", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/content_compression_v2023_05_30.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/content_compression_v2023_05_30.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.static_content", "rule_format", "v2023-05-30"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.static_content", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/static_content_v2023_05_30.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/static_content_v2023_05_30.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.dynamic_content", "rule_format", "v2023-05-30"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.dynamic_content", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/dynamic_content_v2023_05_30.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/dynamic_content_v2023_05_30.json")), ), }}, }) @@ -94,7 +95,7 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_mixed_versions.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_mixed_versions.tf"), ExpectError: regexp.MustCompile(`child rule is using different rule format \(rules_v2023_05_30\) than expected \(rules_v2023_01_05\)`), }}, }) @@ -105,7 +106,7 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_error_too_many_elements.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_error_too_many_elements.tf"), ExpectError: regexp.MustCompile(`expected 1 element\(s\), got 2`), }}, }) @@ -116,7 +117,7 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_with_is_secure_outside_default.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_with_is_secure_outside_default.tf"), ExpectError: regexp.MustCompile(`cannot be used outside 'default' rule: is_secure`), }}, }) @@ -127,7 +128,7 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_with_variable_outside_default.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_with_variable_outside_default.tf"), ExpectError: regexp.MustCompile(`cannot be used outside 'default' rule: variable`), }}, }) @@ -138,21 +139,21 @@ func TestDataPropertyRulesBuilder(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRulesBuilder/rules_variables.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/rules_variables.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rules_builder.default", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.default", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/default_variables.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/default_variables.json")), resource.TestCheckResourceAttr("data.akamai_property_rules_builder.content_compression", "rule_format", "v2023-01-05"), testCheckResourceAttrJSON("data.akamai_property_rules_builder.content_compression", "json", - loadFixtureString("testdata/TestDSPropertyRulesBuilder/content_compression_variables.json")), + testutils.LoadFixtureString(t, "testdata/TestDSPropertyRulesBuilder/content_compression_variables.json")), ), }}, }) diff --git a/pkg/providers/property/data_akamai_property_rules_template_test.go b/pkg/providers/property/data_akamai_property_rules_template_test.go index 9b76aff17..89334beb6 100644 --- a/pkg/providers/property/data_akamai_property_rules_template_test.go +++ b/pkg/providers/property/data_akamai_property_rules_template_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/common/tf" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/require" "github.com/tj/assert" ) @@ -21,15 +22,15 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_map.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_map.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_map_with_data.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_map_with_data.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, }, @@ -43,15 +44,15 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_map_ns.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_map_ns.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_map_with_data_ns.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_map_with_data_ns.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, }, @@ -65,15 +66,15 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_null_values.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_null_values.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_defaults.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_defaults.json")), ), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_null_values_with_data.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_null_values_with_data.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_defaults.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_defaults.json")), ), }, }, @@ -87,15 +88,15 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_file.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_file.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_file_with_data.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_file_with_data.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString("testdata/TestDSRulesTemplate/rules/rules_out.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/rules_out.json")), ), }, }, @@ -109,11 +110,11 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_file_data_conflict.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_file_data_conflict.tf"), ExpectError: regexp.MustCompile(`"template_file": only one of .template,template_file. can be specified`), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_file_data_missing.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_file_data_missing.tf"), ExpectError: regexp.MustCompile(`"template_file": one of .template,template_file. must be specified`), }, }, @@ -127,11 +128,11 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_missing_data.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_missing_data.tf"), ExpectError: regexp.MustCompile(`The argument "template_data" is required, but no definition was found.`), }, { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_missing_dir.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_missing_dir.tf"), ExpectError: regexp.MustCompile(`The argument "template_dir" is required, but no definition was found.`), }, }, @@ -145,7 +146,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_conflict.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_conflict.tf"), ExpectError: regexp.MustCompile(`"variables": conflicts with var_definition_file`), }, }, @@ -159,7 +160,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_invalid_type.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_invalid_type.tf"), ExpectError: regexp.MustCompile(`'type' has invalid value: should be 'bool', 'number', 'string' or 'jsonBlock'`), }, }, @@ -173,7 +174,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_var_not_found.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_var_not_found.tf"), ExpectError: regexp.MustCompile(`executing "snippets/sub/another-template.json" at <.options>: map has no entry for key "options"`), }, }, @@ -187,7 +188,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_invalid_value.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_invalid_value.tf"), ExpectError: regexp.MustCompile(`value could not be represented as number: strconv.ParseFloat: parsing "all": invalid syntax`), }, }, @@ -201,7 +202,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_vars_file_not_found.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_vars_file_not_found.tf"), ExpectError: regexp.MustCompile(`reading file: open invalid_path: no such file or directory`), }, }, @@ -215,7 +216,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_invalid_json.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_invalid_json.tf"), ExpectError: regexp.MustCompile(`snippets file should be with .json extension and valid json data. Invalid file: testdata/TestDSRulesTemplate/property-snippets/template_invalid_json.json`), }, }, @@ -229,7 +230,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_file_not_found.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_file_not_found.tf"), ExpectError: regexp.MustCompile(`Error: stat testdata/TestDSRulesTemplate/rules/property-snippets/non-existent.json: no such file or directory`), }, }, @@ -244,7 +245,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_file_is_empty.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_file_is_empty.tf"), ExpectError: regexp.MustCompile(`Error: snippets file should be with .json extension and valid json data. Invalid file: testdata/TestDSRulesTemplate/property-snippets/empty_json.json`), }, }, @@ -259,7 +260,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_invalid_snippets_folder_json.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_invalid_snippets_folder_json.tf"), ExpectError: regexp.MustCompile(`Error: snippets file should be with .json extension and valid json data. Invalid file: testdata/TestDSRulesTemplate/output/template_invalid_json.json`), }, }, @@ -274,7 +275,7 @@ func TestDataAkamaiPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_invalid_snippets_only_one_folder_json.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_invalid_snippets_only_one_folder_json.tf"), ExpectError: regexp.MustCompile(`Error: snippets file should be with .json extension and valid json data. Invalid file: property-snippet/template_invalid_json.json`), }, }, @@ -501,21 +502,21 @@ func TestFlattenTemplate(t *testing.T) { "valid list": { givenList: []interface{}{ map[string]interface{}{ - "template_data": loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), + "template_data": testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), "template_dir": "testdata/TestDSRulesTemplate/rules/property-snippets/", }, }, - expectedData: loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), + expectedData: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), expectedDir: "testdata/TestDSRulesTemplate/rules/property-snippets", }, "invalid list length": { givenList: []interface{}{ map[string]interface{}{ - "template_data": loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), + "template_data": testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/plain_json.json"), "template_dir": "testdata/TestDSRulesTemplate/rules/property-snippets/", }, map[string]interface{}{ - "template_data": loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), + "template_data": testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), "template_dir": "testdata/TestDSRulesTemplate/rules/property-snippets", }, }, @@ -532,7 +533,7 @@ func TestFlattenTemplate(t *testing.T) { "missing 'template_dir' in list": { givenList: []interface{}{ map[string]interface{}{ - "template_data": loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), + "template_data": testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), }, }, withError: tf.ErrNotFound, @@ -549,7 +550,7 @@ func TestFlattenTemplate(t *testing.T) { "invalid 'template_dir' in list": { givenList: []interface{}{ map[string]interface{}{ - "template_data": loadFixtureString("testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), + "template_data": testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/rules/property-snippets/template_in.json"), "template_dir": true, }, }, @@ -607,7 +608,7 @@ func TestConvertToTemplate(t *testing.T) { return } require.NoError(t, err) - expected := loadFixtureString(fmt.Sprintf("%s/%s", templatesOut, test.expectedFile)) + expected := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", templatesOut, test.expectedFile)) assert.Equal(t, expected, res) }) } @@ -639,7 +640,7 @@ func TestStringToTemplate(t *testing.T) { } for name, test := range tests { t.Run(name, func(t *testing.T) { - givenString := loadFixtureString(fmt.Sprintf("%s/%s", templates, test.givenFile)) + givenString := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", templates, test.givenFile)) res, err := stringToTemplate(givenString, test.varMaps, "main") fmt.Println(res) if test.withError != nil { @@ -647,7 +648,7 @@ func TestStringToTemplate(t *testing.T) { return } require.NoError(t, err) - expected := loadFixtureString(fmt.Sprintf("%s/%s", templatesOut, test.expectedFile)) + expected := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", templatesOut, test.expectedFile)) assert.Equal(t, expected, res) }) } @@ -691,9 +692,9 @@ func TestVariablesNesting(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", loadFixtureString(test.expectedPath)), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.test", "json", testutils.LoadFixtureString(t, test.expectedPath)), ), }, }, @@ -725,7 +726,7 @@ func TestVariablesAndIncludesNestingCyclicDependency(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configPath), + Config: testutils.LoadFixtureString(t, test.configPath), ExpectError: regexp.MustCompile(test.withError), }, }, @@ -743,10 +744,10 @@ func TestMultipleTemplates(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSRulesTemplate/template_multiple_templates.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/template_multiple_templates.tf"), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.akamai_property_rules_template.rules1", "json", loadFixtureString("testdata/TestDSRulesTemplate/output/template_multiple_templates_snippet1.json")), - resource.TestCheckResourceAttr("data.akamai_property_rules_template.rules2", "json", loadFixtureString("testdata/TestDSRulesTemplate/output/template_multiple_templates_snippet2.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.rules1", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/output/template_multiple_templates_snippet1.json")), + resource.TestCheckResourceAttr("data.akamai_property_rules_template.rules2", "json", testutils.LoadFixtureString(t, "testdata/TestDSRulesTemplate/output/template_multiple_templates_snippet2.json")), ), }, }, diff --git a/pkg/providers/property/data_akamai_property_rules_test.go b/pkg/providers/property/data_akamai_property_rules_test.go index de1f31034..02ec6cd7d 100644 --- a/pkg/providers/property/data_akamai_property_rules_test.go +++ b/pkg/providers/property/data_akamai_property_rules_test.go @@ -5,10 +5,11 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDSPropertyRulesRead(t *testing.T) { @@ -53,7 +54,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/ds_property_rules.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/ds_property_rules.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rules.rules", "id", "prp_2"), resource.TestCheckResourceAttr("data.akamai_property_rules.rules", "property_id", "prp_2"), @@ -129,7 +130,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(test.configFile), + Config: testutils.LoadFixtureString(t, test.configFile), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_property_rules.rules", "rule_format", test.expectedRuleFormat), ), @@ -159,7 +160,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/with_versioned_rule_format.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/with_versioned_rule_format.tf"), ExpectError: regexp.MustCompile("given 'rule_format' is not supported: \"v2015-08-17\""), }, }, @@ -178,7 +179,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/with_versioned_rule_format.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/with_versioned_rule_format.tf"), ExpectError: regexp.MustCompile("oops"), }, }, @@ -193,7 +194,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/missing_group_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/missing_group_id.tf"), ExpectError: regexp.MustCompile("\"contract_id\": all of `contract_id,group_id` must be specified"), }, }, @@ -208,7 +209,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/missing_contract_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/missing_contract_id.tf"), ExpectError: regexp.MustCompile("\"group_id\": all of `contract_id,group_id` must be specified"), }, }, @@ -223,7 +224,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/empty_contract_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/empty_contract_id.tf"), ExpectError: regexp.MustCompile(`provided value cannot be blank((.|\n)*)contract_id = ""`), }, }, @@ -238,7 +239,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/empty_group_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/empty_group_id.tf"), ExpectError: regexp.MustCompile(`provided value cannot be blank((.|\n)*)group_id += ""`), }, }, @@ -261,7 +262,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/ds_property_rules.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/ds_property_rules.tf"), ExpectError: regexp.MustCompile("fetching latest version"), }, }, @@ -298,7 +299,7 @@ func TestDSPropertyRulesRead(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestDSPropertyRules/ds_property_rules.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/ds_property_rules.tf"), ExpectError: regexp.MustCompile("fetching rule tree"), }, }, @@ -312,7 +313,7 @@ func TestDSPropertyRulesRead_Fail(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSPropertyRules/always_fails.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSPropertyRules/always_fails.tf"), ExpectError: regexp.MustCompile(`Error: provided value cannot be blank`), }}, }) diff --git a/pkg/providers/property/data_akamai_property_test.go b/pkg/providers/property/data_akamai_property_test.go index 1afd79f67..e447cc18d 100644 --- a/pkg/providers/property/data_akamai_property_test.go +++ b/pkg/providers/property/data_akamai_property_test.go @@ -9,8 +9,9 @@ import ( "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" ) func TestDataProperty(t *testing.T) { @@ -76,7 +77,7 @@ func TestDataProperty(t *testing.T) { }, expectedAttributes: map[string]string{ "name": "property_name", - "rules": compactJSON(loadFixtureBytes("testdata/TestDataProperty/no_version_rules.json")), + "rules": compactJSON(testutils.LoadFixtureBytes(t, "testdata/TestDataProperty/no_version_rules.json")), }, }, "valid rules, with version provided": { @@ -135,7 +136,7 @@ func TestDataProperty(t *testing.T) { }, expectedAttributes: map[string]string{ "name": "property_name", - "rules": compactJSON(loadFixtureBytes("testdata/TestDataProperty/with_version_rules.json")), + "rules": compactJSON(testutils.LoadFixtureBytes(t, "testdata/TestDataProperty/with_version_rules.json")), }, }, "error searching for property": { @@ -246,7 +247,7 @@ func TestDataProperty(t *testing.T) { IsUnitTest: true, ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString(fmt.Sprintf("testdata/TestDataProperty/%s", test.givenTF)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("testdata/TestDataProperty/%s", test.givenTF)), Check: resource.ComposeAggregateTestCheckFunc(checkFuncs...), ExpectError: test.withError, }, diff --git a/pkg/providers/property/data_property_akamai_contract_test.go b/pkg/providers/property/data_property_akamai_contract_test.go index 11396b7a8..e93e72f7b 100644 --- a/pkg/providers/property/data_property_akamai_contract_test.go +++ b/pkg/providers/property/data_property_akamai_contract_test.go @@ -4,9 +4,10 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func Test_DSReadContract(t *testing.T) { @@ -33,7 +34,7 @@ func Test_DSReadContract(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSContractRequired/ds_contract_with_group_name_and_group.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractRequired/ds_contract_with_group_name_and_group.tf"), ExpectError: regexp.MustCompile("only one of `group_id,group_name` can be specified"), }}, }) @@ -63,7 +64,7 @@ func Test_DSReadContract(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSContractRequired/ds_contract_with_group_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractRequired/ds_contract_with_group_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "id", "ctr_1234"), resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "group_id", "grp_12345"), @@ -97,7 +98,7 @@ func Test_DSReadContract(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSContractRequired/ds_contract_with_group_id_without_prefix.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractRequired/ds_contract_with_group_id_without_prefix.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "id", "ctr_1234"), resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "group_id", "grp_12345"), @@ -131,7 +132,7 @@ func Test_DSReadContract(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSContractRequired/ds_contract_with_group_name.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractRequired/ds_contract_with_group_name.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "id", "ctr_1234"), resource.TestCheckResourceAttr("data.akamai_contract.akacontract", "group_id", "grp_12345"), diff --git a/pkg/providers/property/data_property_akamai_group_test.go b/pkg/providers/property/data_property_akamai_group_test.go index a348c7b72..a00cdc65f 100644 --- a/pkg/providers/property/data_property_akamai_group_test.go +++ b/pkg/providers/property/data_property_akamai_group_test.go @@ -4,7 +4,8 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func Test_DSReadGroup(t *testing.T) { @@ -26,7 +27,7 @@ func Test_DSReadGroup(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, IsUnitTest: true, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSGroup/ds-group-w-group-name-and-contract_id.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSGroup/ds-group-w-group-name-and-contract_id.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.akamai_group.akagroup", "id", "grp_12345"), resource.TestCheckResourceAttr("data.akamai_group.akagroup", "group_name", "Example.com-1-1TJZH5"), diff --git a/pkg/providers/property/data_property_akamai_groups_test.go b/pkg/providers/property/data_property_akamai_groups_test.go index d9de51a9f..8b8f68fb2 100644 --- a/pkg/providers/property/data_property_akamai_groups_test.go +++ b/pkg/providers/property/data_property_akamai_groups_test.go @@ -4,10 +4,11 @@ import ( "log" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestDataSourceMultipleGroups_basic(t *testing.T) { @@ -72,7 +73,7 @@ func TestGroup_ContractNotFoundInState(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, IsUnitTest: true, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestDSContractRequired/groups.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestDSContractRequired/groups.tf"), }}, }) }) diff --git a/pkg/providers/property/provider_test.go b/pkg/providers/property/provider_test.go index 64a3829e0..ff07efdf9 100644 --- a/pkg/providers/property/provider_test.go +++ b/pkg/providers/property/provider_test.go @@ -2,8 +2,6 @@ package property import ( "context" - "fmt" - "io/ioutil" "log" "os" "sync" @@ -80,20 +78,6 @@ func useClient(papiCli papi.PAPI, hapiCli hapi.HAPI, f func()) { f() } -// loadFixtureBytes returns the entire contents of the given file as a byte slice -func loadFixtureBytes(path string) []byte { - contents, err := ioutil.ReadFile(path) - if err != nil { - panic(err) - } - return contents -} - -// loadFixtureString returns the entire contents of the given file as a string -func loadFixtureString(format string, args ...interface{}) string { - return string(loadFixtureBytes(fmt.Sprintf(format, args...))) -} - // suppressLogging prevents logging output during the given func unless TEST_LOGGING env var is not empty. Use this // to keep log messages from polluting test output. Not thread-safe. func suppressLogging(t *testing.T, f func()) { diff --git a/pkg/providers/property/resource_akamai_cp_code_test.go b/pkg/providers/property/resource_akamai_cp_code_test.go index 041b858d6..22c7afba6 100644 --- a/pkg/providers/property/resource_akamai_cp_code_test.go +++ b/pkg/providers/property/resource_akamai_cp_code_test.go @@ -9,9 +9,10 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stretchr/testify/mock" "github.com/tj/assert" @@ -156,7 +157,7 @@ func TestResCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResCPCode/create_new_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/create_new_cp_code.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), @@ -191,7 +192,7 @@ func TestResCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResCPCode/use_existing_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/use_existing_cp_code.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), @@ -227,7 +228,7 @@ func TestResCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResCPCode/use_existing_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/use_existing_cp_code.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "1"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), @@ -263,7 +264,7 @@ func TestResCPCode(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResCPCode/use_existing_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/use_existing_cp_code.tf"), ExpectError: regexp.MustCompile("Couldn't find product id on the CP Code"), }}, }) @@ -295,14 +296,14 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step0.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step1.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step1.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "renamed cpcode"), @@ -325,7 +326,7 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/import_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/import_cp_code.tf"), }, { ImportState: true, @@ -358,7 +359,7 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/import_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/import_cp_code.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cp_code.test", @@ -379,7 +380,7 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/import_cp_code.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/import_cp_code.tf"), ImportState: true, ImportStateId: id, ResourceName: "akamai_cp_code.test", @@ -410,7 +411,7 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step0.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), @@ -420,7 +421,7 @@ func TestResCPCode(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_immutable.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_immutable.tf"), ExpectError: regexp.MustCompile(`cp code attribute 'contract_id' cannot be changed after creation \(immutable\)`), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), @@ -431,7 +432,7 @@ func TestResCPCode(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_immutable.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_immutable.tf"), ExpectError: regexp.MustCompile(`cp code attribute 'product_id' cannot be changed after creation \(immutable\)`), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), @@ -442,7 +443,7 @@ func TestResCPCode(t *testing.T) { ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_immutable.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_immutable.tf"), ExpectError: regexp.MustCompile(`cp code attribute 'group_id' cannot be changed after creation \(immutable\)`), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), @@ -478,14 +479,14 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step0.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step1.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step1.tf"), ExpectError: regexp.MustCompile("oops"), }, }, @@ -515,14 +516,14 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step0.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step1.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step1.tf"), ExpectError: regexp.MustCompile("oops"), }, }, @@ -565,14 +566,14 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step0.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step0.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_cp_code.test", "id", "0"), resource.TestCheckResourceAttr("akamai_cp_code.test", "name", "test cpcode"), ), }, { - Config: loadFixtureString("testdata/TestResCPCode/change_name_step1.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/change_name_step1.tf"), ExpectNonEmptyPlan: true, }, }, @@ -587,7 +588,7 @@ func TestResCPCode(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResCPCode/missing_product.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResCPCode/missing_product.tf"), ExpectError: expectedErr, }, }, diff --git a/pkg/providers/property/resource_akamai_edge_hostname_test.go b/pkg/providers/property/resource_akamai_edge_hostname_test.go index 8ca93fbdf..28ec6bc62 100644 --- a/pkg/providers/property/resource_akamai_edge_hostname_test.go +++ b/pkg/providers/property/resource_akamai_edge_hostname_test.go @@ -8,14 +8,15 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/hapi" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" ) func TestResourceEdgeHostname(t *testing.T) { @@ -99,7 +100,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_edgesuite_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_edgesuite_net.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "ip_behavior", "IPV6_COMPLIANCE"), @@ -184,7 +185,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_edgekey_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_edgekey_net.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "ip_behavior", "IPV6_PERFORMANCE"), @@ -267,7 +268,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "ip_behavior", "IPV6_COMPLIANCE"), @@ -363,14 +364,14 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "ip_behavior", "IPV4"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "group_id", "grp_2"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "edge_hostname", "test.aka.edgesuite.net"), - resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "use_cases", loadFixtureString(fmt.Sprintf("%s/use_cases/use_cases_new.json", testDir))), + resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "use_cases", testutils.LoadFixtureString(t, fmt.Sprintf("%s/use_cases/use_cases_new.json", testDir))), resource.TestCheckOutput("edge_hostname", "test.aka.edgesuite.net"), ), }, @@ -404,7 +405,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -511,7 +512,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -521,7 +522,7 @@ func TestResourceEdgeHostname(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -602,7 +603,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -612,7 +613,7 @@ func TestResourceEdgeHostname(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_error_update_ipv6_performance.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_error_update_ipv6_performance.tf")), ExpectError: regexp.MustCompile("invalid IP version behavior: valid values are IPV4 and IPV6_IPV4_DUALSTACK; IPV6 and other values aren't currently supported"), }, }, @@ -673,7 +674,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -683,7 +684,7 @@ func TestResourceEdgeHostname(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior_no_email.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior_no_email.tf")), ExpectError: regexp.MustCompile("\"status_update_email\" is a required parameter to update an edge hostname"), }, }, @@ -744,7 +745,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_ipv4.tf")), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "id", "eh_123"), resource.TestCheckResourceAttr("akamai_edge_hostname.edgehostname", "contract_id", "ctr_2"), @@ -754,7 +755,7 @@ func TestResourceEdgeHostname(t *testing.T) { ), }, { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior_empty_email.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_update_ip_behavior_empty_email.tf")), ExpectError: regexp.MustCompile("\"status_update_email\" is a required parameter to update an edge hostname"), }, }, @@ -768,7 +769,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), ExpectError: regexp.MustCompile("oops"), }, }, @@ -782,7 +783,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "missing_certificate.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "missing_certificate.tf")), ExpectError: regexp.MustCompile("a certificate enrollment ID is required for Enhanced TLS edge hostnames with 'edgekey.net' suffix"), }, }, @@ -826,7 +827,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), ExpectError: regexp.MustCompile("oops"), }, }, @@ -872,7 +873,7 @@ func TestResourceEdgeHostname(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net.tf")), ExpectError: regexp.MustCompile("unable to find edge hostname"), }, }, @@ -881,7 +882,7 @@ func TestResourceEdgeHostname(t *testing.T) { init: func(mp *papi.Mock, mh *hapi.Mock) {}, steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/%s", testDir, "new_akamaized_net_without_product_id.tf")), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, "new_akamaized_net_without_product_id.tf")), ExpectError: regexp.MustCompile("`product_id` must be specified for creation"), }, }, @@ -981,10 +982,10 @@ func TestResourceEdgeHostnames_WithImport(t *testing.T) { Steps: []resource.TestStep{ { // please note that import does not support product id, that why we only define it in config for creation - Config: loadFixtureString("testdata/TestResourceEdgeHostname/creation_before_import_edgehostname.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceEdgeHostname/creation_before_import_edgehostname.tf"), }, { - Config: loadFixtureString("testdata/TestResourceEdgeHostname/import_edgehostname.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResourceEdgeHostname/import_edgehostname.tf"), ImportState: true, ImportStateCheck: func(s []*terraform.InstanceState) error { assert.Len(t, s, 1) @@ -1206,8 +1207,8 @@ func TestSuppressEdgeHostnameUseCases(t *testing.T) { for name, test := range tests { t.Run(name, func(t *testing.T) { - oldFixture := loadFixtureString(fmt.Sprintf("%s/%s", testDir, test.oldPath)) - newFixture := loadFixtureString(fmt.Sprintf("%s/%s", testDir, test.newPath)) + oldFixture := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, test.oldPath)) + newFixture := testutils.LoadFixtureString(t, fmt.Sprintf("%s/%s", testDir, test.newPath)) assert.Equal(t, test.expected, suppressEdgeHostnameUseCases("", oldFixture, newFixture, nil)) }) @@ -1237,7 +1238,7 @@ func TestConvertingUseCases2JSON(t *testing.T) { UseCase: "Download_Mode", }, }, - expected: loadFixtureBytes(fmt.Sprintf("%s/%s", testDir, "use_cases1.json")), + expected: testutils.LoadFixtureBytes(t, fmt.Sprintf("%s/%s", testDir, "use_cases1.json")), }, } diff --git a/pkg/providers/property/resource_akamai_property_activation_test.go b/pkg/providers/property/resource_akamai_property_activation_test.go index 708965975..35c5a35bf 100644 --- a/pkg/providers/property/resource_akamai_property_activation_test.go +++ b/pkg/providers/property/resource_akamai_property_activation_test.go @@ -8,7 +8,8 @@ import ( "github.com/stretchr/testify/mock" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) func TestResourcePAPIPropertyActivation(t *testing.T) { @@ -48,7 +49,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -67,7 +68,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation_update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "contact.#", "1"), @@ -142,7 +143,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation_with_compliance_record.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation_with_compliance_record.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -181,7 +182,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -218,7 +219,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestPropertyActivation/ok/resource_property_activation_minimum_args.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestPropertyActivation/ok/resource_property_activation_minimum_args.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -264,11 +265,11 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/deactivated_in_other_source/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/deactivated_in_other_source/resource_property_activation.tf"), Check: resource.TestCheckResourceAttr("akamai_property_activation.test", "version", "1"), }, { - Config: loadFixtureString("./testdata/TestPropertyActivation/deactivated_in_other_source/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/deactivated_in_other_source/resource_property_activation.tf"), Check: resource.TestCheckResourceAttr("akamai_property_activation.test", "version", "1"), }, }, @@ -276,7 +277,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { "check schema property activation compliance record - error empty compliance_record block": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/cr_validation/resource_property_activation_with_empty_cr.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/cr_validation/resource_property_activation_with_empty_cr.tf"), ExpectError: regexp.MustCompile("one of\n`compliance_record.0.noncompliance_reason_emergency,compliance_record.0.noncompliance_reason_no_production_traffic,compliance_record.0.noncompliance_reason_none,compliance_record.0.noncompliance_reason_other`\nmust be specified"), }, }, @@ -284,7 +285,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { "check schema property activation compliance record - error more than one cr type": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/cr_validation/resource_property_activation_with_more_than_one_cr.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/cr_validation/resource_property_activation_with_more_than_one_cr.tf"), ExpectError: regexp.MustCompile("only one of\n`compliance_record.0.noncompliance_reason_emergency,compliance_record.0.noncompliance_reason_no_production_traffic,compliance_record.0.noncompliance_reason_none,compliance_record.0.noncompliance_reason_other`\ncan be specified"), }, }, @@ -295,7 +296,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), ExpectError: regexp.MustCompile("failed to create request"), }, }, @@ -303,7 +304,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { "check schema property activation - no property id nor property": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/no_propertyId/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/no_propertyId/resource_property_activation.tf"), ExpectError: regexp.MustCompile("Missing required argument"), }, }, @@ -311,7 +312,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { "check schema property activation - no contact": { steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/no_contact/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/no_contact/resource_property_activation.tf"), ExpectError: regexp.MustCompile("Missing required argument"), }, }, @@ -322,7 +323,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), ExpectError: regexp.MustCompile("activation cannot continue due to rule errors"), }, }, @@ -353,7 +354,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -369,7 +370,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/ok/resource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -418,7 +419,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/diff_suppress/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/diff_suppress/resource_property_activation.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), @@ -437,7 +438,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { ), }, { - Config: loadFixtureString("./testdata/TestPropertyActivation/diff_suppress/resource_property_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/diff_suppress/resource_property_activation_update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "contact.#", "2"), @@ -490,11 +491,11 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/500_on_activation/resource_property_activation.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/500_on_activation/resource_property_activation.tf"), Check: resource.TestCheckResourceAttr("akamai_property_activation.test", "version", "1"), }, { - Config: loadFixtureString("./testdata/TestPropertyActivation/500_on_activation/resource_property_activation_update.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/500_on_activation/resource_property_activation_update.tf"), Check: resource.TestCheckResourceAttr("akamai_property_activation.test", "version", "1"), ExpectError: regexp.MustCompile("some 500 error"), }, @@ -520,7 +521,7 @@ func TestResourcePAPIPropertyActivation(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("./testdata/TestPropertyActivation/import/resource_property_activation_creation_for_import.tf"), + Config: testutils.LoadFixtureString(t, "./testdata/TestPropertyActivation/import/resource_property_activation_creation_for_import.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_activation.test", "id", "prp_test:STAGING"), resource.TestCheckResourceAttr("akamai_property_activation.test", "property_id", "prp_test"), diff --git a/pkg/providers/property/resource_akamai_property_include_activation_test.go b/pkg/providers/property/resource_akamai_property_include_activation_test.go index bcd82c92c..a556a2285 100644 --- a/pkg/providers/property/resource_akamai_property_include_activation_test.go +++ b/pkg/providers/property/resource_akamai_property_include_activation_test.go @@ -9,7 +9,8 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -296,7 +297,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -357,7 +358,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -369,7 +370,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation_update.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation_update.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -415,7 +416,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -463,7 +464,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -513,7 +514,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/no_compliance_record_on_production.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/no_compliance_record_on_production.tf", testDir)), ExpectError: regexp.MustCompile(`Error: for 'PRODUCTION' network, 'compliance_record' must be specified`), }, }, @@ -553,7 +554,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -566,7 +567,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ExpectError: regexp.MustCompile("oops"), }, { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -609,7 +610,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), }, { ImportState: true, @@ -649,7 +650,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -717,7 +718,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_activation.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_activation.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, @@ -729,7 +730,7 @@ func TestResourcePropertyIncludeActivation(t *testing.T) { }), }, { - Config: loadFixtureString(fmt.Sprintf("%s/property_include_update_note_not_suppressed.tf", testDir)), + Config: testutils.LoadFixtureString(t, fmt.Sprintf("%s/property_include_update_note_not_suppressed.tf", testDir)), Check: checkAttributes(attrs{ includeID: includeID, contractID: contractID, diff --git a/pkg/providers/property/resource_akamai_property_include_test.go b/pkg/providers/property/resource_akamai_property_include_test.go index 3a1c7750e..4254fdace 100644 --- a/pkg/providers/property/resource_akamai_property_include_test.go +++ b/pkg/providers/property/resource_akamai_property_include_test.go @@ -9,8 +9,9 @@ import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/hapi" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/test" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -64,7 +65,7 @@ func TestResourcePropertyInclude(t *testing.T) { } var rulesResp papi.GetIncludeRuleTreeResponse - err := json.Unmarshal(loadFixtureBytes(path.Join(workdir, "rules_response", testData.rulesPath)), &rulesResp) + err := json.Unmarshal(testutils.LoadFixtureBytes(t, path.Join(workdir, "rules_response", testData.rulesPath)), &rulesResp) assert.NoError(t, err) resp.Rules = rulesResp.Rules @@ -147,6 +148,12 @@ func TestResourcePropertyInclude(t *testing.T) { } newUpdateIncludeRuleTreeReq := func(testData *testData) papi.UpdateIncludeRuleTreeRequest { + unifiedRules := testutils.LoadFixtureString(t, path.Join(workdir, "property-snippets", testData.rulesPath)) + + var rules papi.RulesUpdate + err := json.Unmarshal([]byte(unifiedRules), &rules) + assert.NoError(t, err) + return papi.UpdateIncludeRuleTreeRequest{ ContractID: testData.contractID, GroupID: testData.groupID, @@ -299,7 +306,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_no_rules.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_no_rules.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -310,7 +317,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/default_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/default_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -336,7 +343,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -347,7 +354,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -373,7 +380,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_with_comment.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_with_comment.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -384,7 +391,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules_with_comment.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules_with_comment.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -411,7 +418,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -422,8 +429,8 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", loadFixtureString("%s/expected/simple_rules_errors.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", testutils.LoadFixtureString(t, "%s/expected/simple_rules_errors.json", workdir)), ), }, }, @@ -448,7 +455,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -459,8 +466,8 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", loadFixtureString("%s/expected/simple_rules_warnings.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", testutils.LoadFixtureString(t, "%s/expected/simple_rules_warnings.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), ), }, @@ -486,7 +493,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -497,9 +504,9 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", loadFixtureString("%s/expected/simple_rules_errors.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", loadFixtureString("%s/expected/simple_rules_warnings.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", testutils.LoadFixtureString(t, "%s/expected/simple_rules_errors.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", testutils.LoadFixtureString(t, "%s/expected/simple_rules_warnings.json", workdir)), ), }, }, @@ -529,7 +536,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -540,13 +547,13 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", loadFixtureString("%s/expected/simple_rules_warnings.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", testutils.LoadFixtureString(t, "%s/expected/simple_rules_warnings.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), ), }, { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -557,7 +564,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), ), @@ -589,7 +596,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -600,13 +607,13 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), - resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", loadFixtureString("%s/expected/simple_rules_errors.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", testutils.LoadFixtureString(t, "%s/expected/simple_rules_errors.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), }, { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -617,7 +624,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -651,7 +658,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_no_rules.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_no_rules.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -662,13 +669,13 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/default_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/default_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), }, { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -679,7 +686,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -718,7 +725,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_no_rules.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_no_rules.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -729,13 +736,13 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/default_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/default_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), }, { - Config: loadFixtureString("%s/property_include.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "group_id", "grp_123"), resource.TestCheckResourceAttr("akamai_property_include.test", "contract_id", "ctr_123"), @@ -746,7 +753,7 @@ func TestResourcePropertyInclude(t *testing.T) { resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "2"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_errors", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "rule_warnings", ""), ), @@ -800,22 +807,22 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_with_ds_create.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_with_ds_create.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", ""), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/default_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/default_rules.json", workdir)), resource.TestCheckResourceAttrPair("akamai_property_include.test", "latest_version", "data.akamai_property_include_rules.rules", "version"), ), }, { - Config: loadFixtureString("%s/property_include_with_ds_update.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_with_ds_update.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "latest_version", "2"), resource.TestCheckResourceAttr("akamai_property_include.test", "staging_version", "1"), resource.TestCheckResourceAttr("akamai_property_include.test", "production_version", ""), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/simple_rules.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/simple_rules.json", workdir)), resource.TestCheckResourceAttrPair("akamai_property_include.test", "latest_version", "data.akamai_property_include_rules.rules", "version"), ), }, @@ -840,10 +847,10 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_null_cpcode.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_null_cpcode.tf", workdir), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property_include.test", "name", "test include"), - resource.TestCheckResourceAttr("akamai_property_include.test", "rules", loadFixtureString("%s/expected/rules_cpcode_null.json", workdir)), + resource.TestCheckResourceAttr("akamai_property_include.test", "rules", testutils.LoadFixtureString(t, "%s/expected/rules_cpcode_null.json", workdir)), ), }, }, @@ -867,7 +874,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_import.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_import.tf", workdir), }, { ImportState: true, @@ -897,7 +904,7 @@ func TestResourcePropertyInclude(t *testing.T) { }, steps: []resource.TestStep{ { - Config: loadFixtureString("%s/property_include_import.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/property_include_import.tf", workdir), }, { ImportState: true, @@ -910,43 +917,43 @@ func TestResourcePropertyInclude(t *testing.T) { "validation errors": { steps: []resource.TestStep{ { - Config: loadFixtureString("%s/validation_required_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/validation_required_errors.tf", workdir), ExpectError: regexp.MustCompile(`The argument "name" is required, but no definition was found`), }, { - Config: loadFixtureString("%s/validation_required_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/validation_required_errors.tf", workdir), ExpectError: regexp.MustCompile(`The argument "group_id" is required, but no definition was found`), }, { - Config: loadFixtureString("%s/validation_required_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/validation_required_errors.tf", workdir), ExpectError: regexp.MustCompile(`The argument "contract_id" is required, but no definition was found`), }, { - Config: loadFixtureString("%s/validation_required_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/validation_required_errors.tf", workdir), ExpectError: regexp.MustCompile(`The argument "type" is required, but no definition was found`), }, { - Config: loadFixtureString("%s/custom_validation_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/custom_validation_errors.tf", workdir), ExpectError: regexp.MustCompile(`Error: expected type to be one of \[MICROSERVICES COMMON_SETTINGS]`), }, { - Config: loadFixtureString("%s/custom_validation_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/custom_validation_errors.tf", workdir), ExpectError: regexp.MustCompile(`Error: "rule_format" must be of the form vYYYY-MM-DD \(with a leading "v"\)`), }, { - Config: loadFixtureString("%s/custom_validation_errors.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/custom_validation_errors.tf", workdir), ExpectError: regexp.MustCompile(`Error: "rules" contains an invalid JSON`), }, { - Config: loadFixtureString("%s/product_id_error.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/product_id_error.tf", workdir), ExpectError: regexp.MustCompile(`The argument "product_id" is required during create, but no definition was found`), }, { - Config: loadFixtureString("%s/rule_format_latest.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/rule_format_latest.tf", workdir), ExpectError: regexp.MustCompile(`"rule_format" 'latest' is not valid, must be of the form vYYYY-MM-DD`), }, { - Config: loadFixtureString("%s/rule_format_blank.tf", workdir), + Config: testutils.LoadFixtureString(t, "%s/rule_format_blank.tf", workdir), ExpectError: regexp.MustCompile(`provided value cannot be blank`), }, }, diff --git a/pkg/providers/property/resource_akamai_property_test.go b/pkg/providers/property/resource_akamai_property_test.go index db09d1ce8..fcb74c966 100644 --- a/pkg/providers/property/resource_akamai_property_test.go +++ b/pkg/providers/property/resource_akamai_property_test.go @@ -9,9 +9,10 @@ import ( "testing" "github.com/akamai/AkamaiOPEN-edgegrid-golang/v7/pkg/papi" + "github.com/akamai/terraform-provider-akamai/v5/pkg/common/testutils" "github.com/akamai/terraform-provider-akamai/v5/pkg/tools" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -298,7 +299,7 @@ func TestResProperty(t *testing.T) { }}, } }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -307,7 +308,7 @@ func TestResProperty(t *testing.T) { StagingVersion := 1 State.Property.StagingVersion = &StagingVersion }, - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to2.test.domain", "2", "1", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -339,7 +340,7 @@ func TestResProperty(t *testing.T) { }}, } }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -348,7 +349,7 @@ func TestResProperty(t *testing.T) { ProductionVersion := 1 State.Property.ProductionVersion = &ProductionVersion }, - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to2.test.domain", "2", "0", "1", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -380,7 +381,7 @@ func TestResProperty(t *testing.T) { }}, } }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -389,7 +390,7 @@ func TestResProperty(t *testing.T) { StagingVersion := 1 State.Property.StagingVersion = &StagingVersion }, - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to2.test.domain", "2", "1", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -421,7 +422,7 @@ func TestResProperty(t *testing.T) { }}, } }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -430,7 +431,7 @@ func TestResProperty(t *testing.T) { ProductionVersion := 1 State.Property.ProductionVersion = &ProductionVersion }, - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to2.test.domain", "2", "0", "1", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -454,12 +455,12 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, { - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to2.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -485,7 +486,7 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -494,7 +495,7 @@ func TestResProperty(t *testing.T) { State.Property.LatestVersion = 2 State.Hostnames[0].CnameTo = "changed.test.domain" }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "2", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, @@ -519,12 +520,12 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"children":[{"name":"Default CORS Policy","options":{},"criteriaMustSatisfy":"all"}],"name":"","options":{}}}`), }, { - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"children":[{"name":"Default CORS Policy","options":{},"criteriaMustSatisfy":"all"}],"name":"","options":{}}}`), }, @@ -588,7 +589,7 @@ func TestResProperty(t *testing.T) { Steps: func(State *TestState, FixturePath string) []resource.TestStep { return []resource.TestStep{ { - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"behaviors":[{"name":"cpCode","options":{"value":{"cpCodeLimits":null,"description":"CliTerraformCPCode","id":1050269,"name":"DevExpCliTerraformPapiAsSchemaTest","products":["Web_App_Accel"]}}}],"name":"default","options":{}}}`), }, @@ -625,12 +626,12 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"behaviors":[{"name":"caching","options":{"behavior":"MAX_AGE","mustRevalidate":false,"ttl":"12d"}}],"name":"default","options":{}}}`), }, { - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"behaviors":[{"name":"caching","options":{"behavior":"MAX_AGE","mustRevalidate":false,"ttl":"13d"}}],"name":"default","options":{}}}`), }, @@ -654,12 +655,12 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to1.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"children":[{"name":"Default CORS Policy","options":{},"criteriaMustSatisfy":"all"}],"name":"","options":{}}}`), }, { - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to1.test.domain", "1", "0", "0", "ehn_123", `{"rules":{"children":[{"name":"Default CORS Policy","options":{},"criteriaMustSatisfy":"all"}],"name":"","options":{}}}`), }, @@ -684,7 +685,7 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.VersionItems = papi.PropertyVersionItems{Items: []papi.PropertyVersionGetItem{{PropertyVersion: 1, ProductionStatus: papi.VersionStatusInactive}}} }, - Config: loadFixtureString("%s/step0.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step0.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"behaviors\":[{\"name\":\"origin\",\"options\":{\"cacheKeyHostname\":\"REQUEST_HOST_HEADER\",\"compress\":true,\"enableTrueClientIp\":true,\"forwardHostHeader\":\"REQUEST_HOST_HEADER\",\"hostname\":\"test.domain\",\"httpPort\":80,\"httpsPort\":443,\"originCertificate\":\"\",\"originSni\":true,\"originType\":\"CUSTOMER\",\"ports\":\"\",\"trueClientIpClientSetting\":false,\"trueClientIpHeader\":\"True-Client-IP\",\"verificationMode\":\"PLATFORM_SETTINGS\"}}],\"children\":[{\"behaviors\":[{\"name\":\"baseDirectory\",\"options\":{\"value\":\"/smth/\"}}],\"criteria\":[{\"name\":\"requestHeader\",\"options\":{\"headerName\":\"Accept-Encoding\",\"matchCaseSensitiveValue\":true,\"matchOperator\":\"IS_ONE_OF\",\"matchWildcardName\":false,\"matchWildcardValue\":false}}],\"name\":\"change fwd path\",\"options\":{},\"criteriaMustSatisfy\":\"all\"},{\"behaviors\":[{\"name\":\"caching\",\"options\":{\"behavior\":\"MAX_AGE\",\"mustRevalidate\":false,\"ttl\":\"1m\"}}],\"name\":\"caching\",\"options\":{},\"criteriaMustSatisfy\":\"any\"}],\"comments\":\"The behaviors in the Default Rule apply to all requests for the property hostname(s) unless another rule overrides the Default Rule settings.\",\"name\":\"default\",\"options\":{},\"variables\":[{\"description\":\"\",\"hidden\":true,\"name\":\"TEST_EMPTY_FIELDS\",\"sensitive\":false,\"value\":\"\"},{\"description\":null,\"hidden\":true,\"name\":\"TEST_NIL_FIELD\",\"sensitive\":false,\"value\":\"\"}]}}"), }, @@ -692,7 +693,7 @@ func TestResProperty(t *testing.T) { PreConfig: func() { State.Property.LatestVersion = 1 }, - Config: loadFixtureString("%s/step1.tf", FixturePath), + Config: testutils.LoadFixtureString(t, "%s/step1.tf", FixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"behaviors\":[{\"name\":\"origin\",\"options\":{\"cacheKeyHostname\":\"REQUEST_HOST_HEADER\",\"compress\":true,\"enableTrueClientIp\":true,\"forwardHostHeader\":\"REQUEST_HOST_HEADER\",\"hostname\":\"test.domain\",\"httpPort\":80,\"httpsPort\":443,\"originCertificate\":\"\",\"originSni\":true,\"originType\":\"CUSTOMER\",\"ports\":\"\",\"trueClientIpClientSetting\":false,\"trueClientIpHeader\":\"True-Client-IP\",\"verificationMode\":\"PLATFORM_SETTINGS\"}}],\"children\":[{\"behaviors\":[{\"name\":\"baseDirectory\",\"options\":{\"value\":\"/smth/\"}}],\"criteria\":[{\"name\":\"requestHeader\",\"options\":{\"headerName\":\"Accept-Encoding\",\"matchCaseSensitiveValue\":true,\"matchOperator\":\"IS_ONE_OF\",\"matchWildcardName\":false,\"matchWildcardValue\":false}}],\"name\":\"change fwd path\",\"options\":{},\"criteriaMustSatisfy\":\"all\"},{\"behaviors\":[{\"name\":\"caching\",\"options\":{\"behavior\":\"MAX_AGE\",\"mustRevalidate\":false,\"ttl\":\"1m\"}}],\"name\":\"caching\",\"options\":{},\"criteriaMustSatisfy\":\"any\"}],\"comments\":\"The behaviors in the Default Rule apply to all requests for the property hostname(s) unless another rule overrides the Default Rule settings.\",\"name\":\"default\",\"options\":{},\"variables\":[{\"description\":\"\",\"hidden\":true,\"name\":\"TEST_EMPTY_FIELDS\",\"sensitive\":false,\"value\":\"\"},{\"description\":\"\",\"hidden\":true,\"name\":\"TEST_NIL_FIELD\",\"sensitive\":false,\"value\":\"\"}]}}"), }, @@ -711,7 +712,7 @@ func TestResProperty(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResProperty/ConfigError/%s.tf", fixtureName), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/ConfigError/%s.tf", fixtureName), ExpectError: regexp.MustCompile(rx), }}, }) @@ -782,7 +783,7 @@ func TestResProperty(t *testing.T) { Steps: func(State *TestState, _ string) []resource.TestStep { return []resource.TestStep{ { - Config: loadFixtureString(fixturePath), + Config: testutils.LoadFixtureString(t, fixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", rules), }, // this step is used to refresh state with updated staging/production statuses @@ -799,7 +800,7 @@ func TestResProperty(t *testing.T) { State.Property.StagingVersion = &stagingVersion }, - Config: loadFixtureString(fixturePath), + Config: testutils.LoadFixtureString(t, fixturePath), Check: checkAttrs("prp_0", "to.test.domain", "1", "1", "0", "ehn_123", rules), }, { @@ -807,7 +808,7 @@ func TestResProperty(t *testing.T) { ImportStateVerify: true, ImportStateId: importID, ResourceName: "akamai_property.test", - Config: loadFixtureString(fixturePath), + Config: testutils.LoadFixtureString(t, fixturePath), ImportStateVerifyIgnore: []string{"product", "read_version"}, Check: checkAttrs("prp_0", "to.test.domain", "1", "1", "0", "ehn_123", rules), }, @@ -926,12 +927,12 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/%s-step0.tf", t.Name()), + Config: testutils.LoadFixtureString(t, "testdata/%s-step0.tf", t.Name()), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, { - Config: loadFixtureString("testdata/%s-step1.tf", t.Name()), + Config: testutils.LoadFixtureString(t, "testdata/%s-step1.tf", t.Name()), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property.test", "id", "prp_1"), resource.TestCheckResourceAttr("akamai_property.test", "name", "renamed_property"), @@ -975,12 +976,12 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/%s/step0.tf", t.Name()), + Config: testutils.LoadFixtureString(t, "testdata/%s/step0.tf", t.Name()), Check: checkAttrs("prp_0", "to.test.domain", "1", "0", "0", "ehn_123", "{\"rules\":{\"name\":\"default\",\"options\":{}}}"), }, { - Config: loadFixtureString("testdata/%s/step1.tf", t.Name()), + Config: testutils.LoadFixtureString(t, "testdata/%s/step1.tf", t.Name()), ExpectError: regexp.MustCompile(`cannot remove active property`), }, }, @@ -1026,7 +1027,7 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResProperty/property_update_with_validation_error_for_rules.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/property_update_with_validation_error_for_rules.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckNoResourceAttr("akamai_property.test", "rules")), ExpectError: regexp.MustCompile(`validation.required_behavior`), @@ -1107,11 +1108,11 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), Check: resource.TestCheckResourceAttr("akamai_property.test", "id", "prp_0"), }, { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateNoHostnames/update/property_update.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateNoHostnames/update/property_update.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property.test", "id", "prp_0"), resource.TestCheckResourceAttr("akamai_property.test", "hostnames.#", "0"), @@ -1163,7 +1164,7 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), Check: resource.TestCheckResourceAttr("akamai_property.test", "id", "prp_0"), ExpectError: regexp.MustCompile("updating hostnames: not possible to use cert_provisioning_type = 'DEFAULT' as the limit for DEFAULT certificates has been reached"), }, @@ -1211,7 +1212,7 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateNoHostnames/creation/property_create.tf"), Check: resource.TestCheckResourceAttr("akamai_property.test", "id", "prp_0"), ExpectError: regexp.MustCompile("updating hostnames: not possible to use cert_provisioning_type = 'DEFAULT' as secure-by-default is not enabled in this account"), }, @@ -1253,7 +1254,7 @@ func TestResProperty(t *testing.T) { resource.UnitTest(t, resource.TestCase{ ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{{ - Config: loadFixtureString("testdata/TestResProperty/Creation/property.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/Creation/property.tf"), ExpectError: regexp.MustCompile("group not found: grp_0"), }}, }) @@ -1281,7 +1282,7 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/%s.tf", t.Name()), + Config: testutils.LoadFixtureString(t, "testdata/%s.tf", t.Name()), Check: resource.TestCheckNoResourceAttr("akamai_property.test", "id"), ExpectError: regexp.MustCompile(`property name is not unique`), }, @@ -1500,14 +1501,14 @@ func TestResProperty(t *testing.T) { ProtoV5ProviderFactories: testAccProviders, Steps: []resource.TestStep{ { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateIncorrectEdgeHostname/create/property.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateIncorrectEdgeHostname/create/property.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property.akaproperty", "id", "prp_0"), resource.TestCheckResourceAttr("akamai_property.akaproperty", "hostnames.#", "2"), ), }, { - Config: loadFixtureString("testdata/TestResProperty/CreationUpdateIncorrectEdgeHostname/update/property.tf"), + Config: testutils.LoadFixtureString(t, "testdata/TestResProperty/CreationUpdateIncorrectEdgeHostname/update/property.tf"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("akamai_property.akaproperty", "id", "prp_0"), resource.TestCheckResourceAttr("akamai_property.akaproperty", "hostnames.#", "3"), diff --git a/pkg/providers/property/ruleformats/rule_format_v2023_05_30.gen.go b/pkg/providers/property/ruleformats/rule_format_v2023_05_30.gen.go index 973928dff..13268fbe7 100644 --- a/pkg/providers/property/ruleformats/rule_format_v2023_05_30.gen.go +++ b/pkg/providers/property/ruleformats/rule_format_v2023_05_30.gen.go @@ -3410,7 +3410,10 @@ func getBehaviorsSchemaV20230530() map[string]*schema.Schema { "log_stream_name": { Optional: true, Description: "Specifies the unique IDs of streams configured for the property. For properties created with the previous version of the rule format, this option contains a string instead of an array of strings. You can use the `List streams` operation to get stream IDs.", - Type: schema.TypeString, + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, }, "sampling_percentage": { Optional: true, @@ -11455,7 +11458,7 @@ func getBehaviorsSchemaV20230530() map[string]*schema.Schema { "set_variable": { Optional: true, Type: schema.TypeList, - Description: "Modify a variable to insert into subsequent fields within the rule tree. Use this behavior to specify the predeclared `variableName` and determine from where to derive its new value. Based on this `valueSource`, you can either generate the value, extract it from some part of the incoming request, assign it from another variable (including a set of built-in system variables), or directly specify its text. Optionally choose a `transform` function to modify the value once. See `Support for variables` for more information. This behavior cannot be used in includes.", + Description: "Modify a variable to insert into subsequent fields within the rule tree. Use this behavior to specify the predeclared `variableName` and determine from where to derive its new value. Based on this `valueSource`, you can either generate the value, extract it from some part of the incoming request, assign it from another variable (including a set of built-in system variables), or directly specify its text. Optionally choose a `transform` function to modify the value once. See `Support for variables` for more information. This behavior can be used in includes.", MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/pkg/providers/providers.go b/pkg/providers/providers.go index 3cbe46a75..ee4fa83a8 100644 --- a/pkg/providers/providers.go +++ b/pkg/providers/providers.go @@ -2,10 +2,12 @@ package providers import ( - // This is where providers are import so they can register themselves + // This is where providers are imported, so they can register themselves _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/appsec" _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/botman" + _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/clientlists" _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/cloudlets" + _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/cloudwrapper" _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/cps" _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/datastream" _ "github.com/akamai/terraform-provider-akamai/v5/pkg/providers/dns"