From 6173008d5788484998b37048c7d09e1b5c1bcc73 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Tue, 21 Nov 2023 11:58:32 +0530 Subject: [PATCH 1/3] appconfiguration evaluation provider initial commit --- .github/labeler-issue.yml | 2 + .../README.md | 81 +++++++ .../ibm-app-configuration-evaluation/main.tf | 46 ++++ .../outputs.tf | 19 ++ .../variables.tf | 58 +++++ .../versions.tf | 9 + go.mod | 4 + go.sum | 21 +- ibm/provider/provider.go | 34 ++- .../appconfigurationevaluation/README.md | 10 + ...ce_ibm_app_config_evaluate_feature_flag.go | 194 ++++++++++++++++ ...m_app_config_evaluate_feature_flag_test.go | 43 ++++ ...source_ibm_app_config_evaluate_property.go | 211 ++++++++++++++++++ ...e_ibm_app_config_evaluate_property_test.go | 43 ++++ website/allowed-subcategories.txt | 1 + ...config_evaluate_feature_flag.html.markdown | 58 +++++ ...app_config_evaluate_property.html.markdown | 58 +++++ 17 files changed, 874 insertions(+), 18 deletions(-) create mode 100644 examples/ibm-app-configuration-evaluation/README.md create mode 100644 examples/ibm-app-configuration-evaluation/main.tf create mode 100644 examples/ibm-app-configuration-evaluation/outputs.tf create mode 100644 examples/ibm-app-configuration-evaluation/variables.tf create mode 100644 examples/ibm-app-configuration-evaluation/versions.tf create mode 100644 ibm/service/appconfigurationevaluation/README.md create mode 100644 ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag.go create mode 100644 ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag_test.go create mode 100644 ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property.go create mode 100644 ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property_test.go create mode 100644 website/docs/d/app_config_evaluate_feature_flag.html.markdown create mode 100644 website/docs/d/app_config_evaluate_property.html.markdown diff --git a/.github/labeler-issue.yml b/.github/labeler-issue.yml index 86318cb84b..81d81e3611 100644 --- a/.github/labeler-issue.yml +++ b/.github/labeler-issue.yml @@ -36,6 +36,8 @@ service/Activity Tracker: - '((\*|-) ?`?|(data|resource) "?)ibm_atracker' service/App Configuration: - '((\*|-) ?`?|(data|resource) "?)ibm_app_config' +service/App Configuration Evaluation: + - '((\*|-) ?`?|(data|resource) "?)ibm_app_config_evaluate_' service/APPID Management: - '((\*|-) ?`?|(data|resource) "?)ibm_appid' service/Catalog Management: diff --git a/examples/ibm-app-configuration-evaluation/README.md b/examples/ibm-app-configuration-evaluation/README.md new file mode 100644 index 0000000000..f2e3cb095d --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/README.md @@ -0,0 +1,81 @@ +# Example for AppConfigurationEvaluation + +This example illustrates how to use the AppConfigurationEvaluation for feature flags & properties. + +The following types of data sources are supported: + +* App Configuration evaluate feature flag. +* App Configuration evaluate property. + +## Usage + +To run this example, execute the following commands: + +```bash +terraform init +terraform plan +terraform apply +``` + +Run `terraform destroy` when you don't need these data sources. + +## AppConfigurationEvaluation data sources + +ibm_app_config_evaluate_feature_flag data source: + +```hcl +data "ibm_app_config_evaluate_feature_flag" "evaluate_feature_flag" { + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + feature_id = var.app_config_feature_id + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} +``` + +ibm_app_config_evaluate_property data source: + +```hcl +data "ibm_app_config_evaluate_property" "evaluate_property" { + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + property_id = var.app_config_property_id + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} +``` + +## Requirements + +| Name | Version | +| --------- | ------- | +| terraform | ~> 0.12 | + +## Providers + +| Name | Version | +| ---- | ------- | +| ibm | 1.60.0 | + +## Inputs + +| Name | Description | Type | Required | +| ------------------ | ---------------------------------- | -------- | -------- | +| ibmcloud\_api\_key | IBM Cloud API key | `string` | true | +| region | IBM Cloud region name. | `string` | true | +| guid | App Configuration instance Id. | `string` | true | +| collection_id | App Configuration Collection Id. | `string` | true | +| environment_id | App Configuration Environment Id. | `string` | true | +| feature_id | App Configuration Feature flag Id. | `string` | true | +| property_id | App Configuration Property Id. | `string` | true | +| entity_id | Entity Id. | `string` | true | +| entity_attributes | Entity attributes. | `object` | false | + +## Outputs +| Name | Description | +| -------------- | ------------------------------------------------------------- | +| result_boolean | Evaluated value of the BOOLEAN type feature flag or property. | +| result_string | Evaluated value of the STRING type feature flag or property. | +| result_numeric | Evaluated value of the NUMERIC type feature flag or property. | \ No newline at end of file diff --git a/examples/ibm-app-configuration-evaluation/main.tf b/examples/ibm-app-configuration-evaluation/main.tf new file mode 100644 index 0000000000..a4803319dd --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/main.tf @@ -0,0 +1,46 @@ +provider "ibm" { + ibmcloud_api_key = var.ibmcloud_api_key + region = var.region +} + +// Single feature flag +data "ibm_app_config_evaluate_feature_flag" "evaluate_feature_flag" { + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + feature_id = var.app_config_feature_id + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} + +// Multiple feature flags +data "ibm_app_config_evaluate_feature_flag" "evaluate_feature_flags" { + for_each = toset(var.app_config_feature_flag_ids) + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + feature_id = each.value + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} + +// Single property +data "ibm_app_config_evaluate_property" "evaluate_property" { + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + property_id = var.app_config_property_id + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} + +// Multiple properties +data "ibm_app_config_evaluate_property" "evaluate_properties" { + for_each = toset(var.app_config_property_ids) + guid = var.app_config_guid + environment_id = var.app_config_environment_id + collection_id = var.app_config_collection_id + property_id = each.value + entity_id = var.app_config_entity_id + entity_attributes = var.app_config_entity_attributes +} diff --git a/examples/ibm-app-configuration-evaluation/outputs.tf b/examples/ibm-app-configuration-evaluation/outputs.tf new file mode 100644 index 0000000000..bb34ae1e9d --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/outputs.tf @@ -0,0 +1,19 @@ +// This output allows ibm_app_config_evaluate_feature_flag data to be referenced by other resources and the terraform CLI +// Modify this output if only certain data should be exposed + +output "ibm_app_config_feature_flag_evaluated_value" { + value = data.ibm_app_config_evaluate_feature_flag.evaluate_feature_flag.result_numeric + description = "Feature flag evaluated value." +} +output "ibm_app_config_feature_flag_evaluated_values" { + value = data.ibm_app_config_evaluate_feature_flag.evaluate_feature_flags["f2"].result_string + description = "Feature flag evaluated values." +} +output "ibm_app_config_property_evaluated_value" { + value = data.ibm_app_config_evaluate_property.evaluate_property.result_numeric + description = "Property evaluated value." +} +output "ibm_app_config_property_evaluated_values" { + value = data.ibm_app_config_evaluate_property.evaluate_properties["p2"].result_boolean + description = "Property evaluated values." +} diff --git a/examples/ibm-app-configuration-evaluation/variables.tf b/examples/ibm-app-configuration-evaluation/variables.tf new file mode 100644 index 0000000000..45e10b5263 --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/variables.tf @@ -0,0 +1,58 @@ +variable "ibmcloud_api_key" { + description = "IBM Cloud API key" + type = string + default = "" +} +variable "region" { + description = "IBM Cloud region where your App Configuration instance is located." + type = string + default = "au-syd" +} +variable "app_config_guid" { + description = "App Configuration instance id or guid." + type = string + default = "36401ffc-6280-459a-ba98-456aba10d0c7" +} +variable "app_config_environment_id" { + description = "Id of the environment created in App Configuration instance under the Environments section." + type = string + default = "dev" +} +variable "app_config_collection_id" { + description = "Id of the collection created in App Configuration instance under the Collections section." + type = string + default = "car-rentals" +} +variable "app_config_feature_id" { + description = "Feature flag id required to be evaluated." + type = string + default = "weekend-discount" +} +variable "app_config_property_id" { + description = "Property id required to be evaluated." + type = string + default = "users-location" +} +variable "app_config_entity_id" { + description = "Entity Id." + type = string + default = "user123" +} +variable "app_config_entity_attributes" { + description = "Entity attributes for evaluation." + type = map() + default = { + "city" : "Bangalore", + "radius" : 60, + } +} +variable "app_config_feature_flag_ids" { + description = "List of feature flag id's required to evaluate." + type = list(string) + default = ["feature-1", "feature-2", "feature-3", "feature-4"] +} +variable "app_config_property_ids" { + description = "List of property id's required to evaluate." + type = list(string) + default = ["property-1", "property-2"] +} diff --git a/examples/ibm-app-configuration-evaluation/versions.tf b/examples/ibm-app-configuration-evaluation/versions.tf new file mode 100644 index 0000000000..e9a0e6bc2e --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.0" + required_providers { + ibm = { + source = "IBM-Cloud/ibm" + version = "1.60.0" + } + } +} diff --git a/go.mod b/go.mod index 9412a594f3..ebe9d790df 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/IBM-Cloud/power-go-client v1.5.2 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 + github.com/IBM/appconfiguration-go-sdk v0.5.1 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f github.com/IBM/cloud-databases-go-sdk v0.3.2 github.com/IBM/cloudant-go-sdk v0.0.43 @@ -117,6 +118,7 @@ require ( github.com/google/gnostic v0.6.9 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -188,9 +190,11 @@ require ( github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect + github.com/robfig/cron v1.2.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect github.com/sirupsen/logrus v1.9.0 // indirect github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e // indirect + github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/objx v0.5.0 // indirect github.com/stretchr/testify v1.8.4 // indirect diff --git a/go.sum b/go.sum index ea0d957ea6..ec9e2f8a9f 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,6 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3 github.com/DataDog/zstd v1.4.4/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/IBM-Cloud/bluemix-go v0.0.0-20231017073329-75ebe90c98ba h1:8U4HByOYJiaGWBpGjdRIzyzu0NBzjywh//CZnSbEsPw= github.com/IBM-Cloud/bluemix-go v0.0.0-20231017073329-75ebe90c98ba/go.mod h1:mt+O8ryLVANrBKlA4RxKdENp3q6Q7mKQIi2nkiibZbU= -github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20230822142550-30562e113de9 h1:sXRzCK3Glxpyu66Tu2NjztLdT5sDwj4qly+MJKRhdWY= -github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20230822142550-30562e113de9/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231106114255-c50117860a3c h1:tRS4VuOG3lHNG+yrsh3vZZQDVNLuFJB0oZbTJp9YXds= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20231106114255-c50117860a3c/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= @@ -115,6 +113,8 @@ github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+Y github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca/go.mod h1:IjXrnOcTe92Q4pEBHmui3H/GM1hw5Pd0zXA5cw5/iZU= github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 h1:OqFxnDxro0JiRwHBKytCcseY2YKD4n87JN1UcaOD4Ss= github.com/IBM/appconfiguration-go-admin-sdk v0.3.0/go.mod h1:xPxAYhr/uywUIDEo/JqWbkUdTryPdzRdYBfUpA5IjoE= +github.com/IBM/appconfiguration-go-sdk v0.5.1 h1:MzJcuc4a6zndJv3wGcxvnbzYlfxNV6Gfj8pltqLoRUs= +github.com/IBM/appconfiguration-go-sdk v0.5.1/go.mod h1:I6g4h2jqybCohHqsGXQsmZEX15TK2eoqRXStBclh6Wc= github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f h1:4c1kqY4GqmkQ+tO03rneDb74Tv7BhTj8jDiDB1p8mdM= github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f/go.mod h1:d22kTYY7RYBWcQlZpqrSdshpB/lJ16viWS5Sbjtlc8s= github.com/IBM/cloud-databases-go-sdk v0.3.2 h1:AUi7/xswqCwuXIlSyuXtDZJIm4d0ZicUBHhPrE9TnH0= @@ -157,10 +157,6 @@ github.com/IBM/keyprotect-go-client v0.12.2 h1:Cjxcqin9Pl0xz3MnxdiVd4v/eIa79xL3h github.com/IBM/keyprotect-go-client v0.12.2/go.mod h1:yr8h2noNgU8vcbs+vhqoXp3Lmv73PI0zAc6VMgFvWwM= github.com/IBM/networking-go-sdk v0.42.2 h1:caqjx4jyFHi10Vlf3skHvlL6K3YJRVstsmCBmvdyqkA= github.com/IBM/networking-go-sdk v0.42.2/go.mod h1:lTUZwtUkMANMnrLHFIgRhHrkBfwASY/Iho1fabaPHxo= -github.com/IBM/platform-services-go-sdk v0.52.0 h1:hbf640xE8T0Rwy2IUf5Pu4OATabGS4IDMnEInXUXs4o= -github.com/IBM/platform-services-go-sdk v0.52.0/go.mod h1:6LxcUhIaSLP4SuQJXF9oLXBamSQogs5D9BcVwr4hmfU= -github.com/IBM/platform-services-go-sdk v0.52.1 h1:fUCtYMAekzsWO/ylZi31j6BpyJ1xKb39NG62zBXePbg= -github.com/IBM/platform-services-go-sdk v0.52.1/go.mod h1:6LxcUhIaSLP4SuQJXF9oLXBamSQogs5D9BcVwr4hmfU= github.com/IBM/platform-services-go-sdk v0.53.1 h1:axpK4dzlf+C+KgHQZWXoKSUMoV2t6OrR5kGGumUEXrI= github.com/IBM/platform-services-go-sdk v0.53.1/go.mod h1:CWSprvsCsXWvujmBzbtoJSmbRZS9FVV3O594b0t/GiM= github.com/IBM/project-go-sdk v0.0.99 h1:rQU/uQLW83OsAUfP/d8fFSIjp8ooEQIFjalYQD4i4aY= @@ -173,6 +169,7 @@ github.com/IBM/scc-go-sdk/v5 v5.1.3 h1:8zqJx/HgChTlMaC21HzthIR4HbFkuJ3dR/D68254j github.com/IBM/scc-go-sdk/v5 v5.1.3/go.mod h1:YtAVlzq10bwR82QX4ZavhDIwa1s85RuVO9N/KmXVcuk= github.com/IBM/schematics-go-sdk v0.2.2 h1:8S3hoVLzF/ZRgWDaLqwHnLmZvlEBHCKgHszmMh7yD2E= github.com/IBM/schematics-go-sdk v0.2.2/go.mod h1:Tw2OSAPdpC69AxcwoyqcYYaGTTW6YpERF9uNEU+BFRQ= +github.com/IBM/secrets-manager-go-sdk v1.2.0/go.mod h1:qv+tQg8Z3Vb11DQYxDjEGeROHDtTLQxUWuOIrIdWg6E= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.1 h1:0Ouu31RsuOLdH26oNsnPErEjctWTplLEIXxwExnTZT0= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.1/go.mod h1:jagqWmjZ0zUEqh5jdGB42ApSQS40fu2LWw6pdg8JJko= github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc= @@ -568,6 +565,7 @@ github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+W github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= github.com/go-openapi/strfmt v0.21.2/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg= +github.com/go-openapi/strfmt v0.21.5/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg= github.com/go-openapi/strfmt v0.21.7 h1:rspiXgNWgeUzhjo1YU01do6qsahtJNByjLVbPLNHb8k= github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew= github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= @@ -588,6 +586,7 @@ github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/ 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= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= @@ -772,6 +771,8 @@ github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -1291,6 +1292,7 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.18.0/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= +github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc= github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM= @@ -1424,6 +1426,8 @@ github.com/rboyer/safeio v0.2.1 h1:05xhhdRNAdS3apYm7JRjOqngf4xruaW959jmRxGDuSU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= +github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= @@ -1477,6 +1481,8 @@ github.com/softlayer/xmlrpc v0.0.0-20200409220501-5f089df7cb7e/go.mod h1:fKZCUVd github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b h1:br+bPNZsJWKicw/5rALEo67QHs5weyD5tf8WST+4sJ0= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -1593,6 +1599,7 @@ go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R7 go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= +go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o= go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY= go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A= @@ -1663,6 +1670,7 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= @@ -1966,6 +1974,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index bdc22fc9a5..69fd4f4d2d 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -11,6 +11,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/apigateway" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/appconfiguration" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/appconfigurationevaluation" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/appid" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/atracker" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/catalogmanagement" @@ -539,18 +540,24 @@ func Provider() *schema.Provider { "ibm_kms_keys": kms.DataSourceIBMKMSkeys(), "ibm_kms_key": kms.DataSourceIBMKMSkey(), "ibm_pn_application_chrome": pushnotification.DataSourceIBMPNApplicationChrome(), - "ibm_app_config_environment": appconfiguration.DataSourceIBMAppConfigEnvironment(), - "ibm_app_config_environments": appconfiguration.DataSourceIBMAppConfigEnvironments(), - "ibm_app_config_collection": appconfiguration.DataSourceIBMAppConfigCollection(), - "ibm_app_config_collections": appconfiguration.DataSourceIBMAppConfigCollections(), - "ibm_app_config_feature": appconfiguration.DataSourceIBMAppConfigFeature(), - "ibm_app_config_features": appconfiguration.DataSourceIBMAppConfigFeatures(), - "ibm_app_config_property": appconfiguration.DataSourceIBMAppConfigProperty(), - "ibm_app_config_properties": appconfiguration.DataSourceIBMAppConfigProperties(), - "ibm_app_config_segment": appconfiguration.DataSourceIBMAppConfigSegment(), - "ibm_app_config_segments": appconfiguration.DataSourceIBMAppConfigSegments(), - "ibm_app_config_snapshot": appconfiguration.DataSourceIBMAppConfigSnapshot(), - "ibm_app_config_snapshots": appconfiguration.DataSourceIBMAppConfigSnapshots(), + + // Added for App Configuration + "ibm_app_config_environment": appconfiguration.DataSourceIBMAppConfigEnvironment(), + "ibm_app_config_environments": appconfiguration.DataSourceIBMAppConfigEnvironments(), + "ibm_app_config_collection": appconfiguration.DataSourceIBMAppConfigCollection(), + "ibm_app_config_collections": appconfiguration.DataSourceIBMAppConfigCollections(), + "ibm_app_config_feature": appconfiguration.DataSourceIBMAppConfigFeature(), + "ibm_app_config_features": appconfiguration.DataSourceIBMAppConfigFeatures(), + "ibm_app_config_property": appconfiguration.DataSourceIBMAppConfigProperty(), + "ibm_app_config_properties": appconfiguration.DataSourceIBMAppConfigProperties(), + "ibm_app_config_segment": appconfiguration.DataSourceIBMAppConfigSegment(), + "ibm_app_config_segments": appconfiguration.DataSourceIBMAppConfigSegments(), + "ibm_app_config_snapshot": appconfiguration.DataSourceIBMAppConfigSnapshot(), + "ibm_app_config_snapshots": appconfiguration.DataSourceIBMAppConfigSnapshots(), + + // Added for App Configuration evaluation + "ibm_app_config_evaluate_feature_flag": appconfigurationevaluation.DataSourceAppConfigEvaluateFeatureFlag(), + "ibm_app_config_evaluate_property": appconfigurationevaluation.DataSourceAppConfigEvaluateProperty(), "ibm_resource_quota": resourcecontroller.DataSourceIBMResourceQuota(), "ibm_resource_group": resourcemanager.DataSourceIBMResourceGroup(), @@ -1713,6 +1720,9 @@ func Validator() validate.ValidatorDict { "ibm_iam_access_group_policy": iampolicy.DataSourceIBMIAMAccessGroupPolicyValidator(), "ibm_iam_service_policy": iampolicy.DataSourceIBMIAMServicePolicyValidator(), "ibm_iam_trusted_profile_policy": iampolicy.DataSourceIBMIAMTrustedProfilePolicyValidator(), + + "ibm_app_config_evaluate_feature_flag": appconfigurationevaluation.DataSourceIBMAppConfigEvaluateFeatureFlagValidator(), + "ibm_app_config_evaluate_property": appconfigurationevaluation.DataSourceIBMAppConfigEvaluatePropertyValidator(), }, } }) diff --git a/ibm/service/appconfigurationevaluation/README.md b/ibm/service/appconfigurationevaluation/README.md new file mode 100644 index 0000000000..2059d0045b --- /dev/null +++ b/ibm/service/appconfigurationevaluation/README.md @@ -0,0 +1,10 @@ +# Terraform IBM Provider + +This area is primarily for IBM provider contributors and maintainers. For information on _using_ Terraform and the IBM provider, see the links below. + + +## Handy Links +* [Find out about contributing](../../../CONTRIBUTING.md) to the IBM provider! +* IBM Provider Docs: [Home](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs) +* IBM Provider Docs: [One of the App Configuration evaluation data source](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/app_config_evaluate_feature_flag) +* IBM App Configuration evaluation SDK: [IBM Go SDK for App Configuration evaluation](https://github.com/IBM/appconfiguration-go-sdk) diff --git a/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag.go b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag.go new file mode 100644 index 0000000000..3b1d2355b0 --- /dev/null +++ b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag.go @@ -0,0 +1,194 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package appconfigurationevaluation + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" + acLib "github.com/IBM/appconfiguration-go-sdk/lib" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceAppConfigEvaluateFeatureFlag() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceAppConfigurationFeatureFlagRead, + + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Required: true, + Description: "App Configuration instance id or guid.", + }, + "environment_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the environment created in App Configuration instance under the Environments section.", + }, + "collection_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the collection created in App Configuration instance under the Collections section.", + }, + "feature_id": { + Type: schema.TypeString, + Required: true, + Description: "Feature flag id required to be evaluated.", + }, + "entity_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the Entity. This will be a string identifier related to the Entity against which " + + "the feature is evaluated. For example, an entity might be an instance of an app that runs on a mobile device, " + + "a microservice that runs on the cloud, or a component of infrastructure that runs that microservice. " + + "For any entity to interact with App Configuration, it must provide a unique entity ID.", + }, + "entity_attributes": { + Type: schema.TypeMap, + Optional: true, + Description: "Key value pair consisting of the attribute name and their values that defines the specified entity. " + + "This is an optional parameter if the feature flag is not configured with any targeting definition. If the " + + "targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is " + + "a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity " + + "satisfies the targeting rules, and returns the appropriate feature flag value.", + Sensitive: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "result_boolean": { + Type: schema.TypeBool, + Computed: true, + Description: "Contains the evaluated value of the BOOLEAN type feature flag only.", + }, + "result_string": { + Type: schema.TypeString, + Computed: true, + Description: "Contains the evaluated value of the STRING type feature flag only.", + }, + "result_numeric": { + Type: schema.TypeInt, + Computed: true, + Description: "Contains the evaluated value of the NUMERIC type feature flag only.", + }, + }, + } +} + +func DataSourceIBMAppConfigEvaluateFeatureFlagValidator() *validate.ResourceValidator { + validateSchema := make([]validate.ValidateSchema, 0) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "guid", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "environment_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "collection_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "feature_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "entity_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "entity_attributes", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.ValueType(schema.TypeMap), + Required: false, + }) + + ibmAppConfigEvaluateFeatureFlagDataSourceValidator := validate.ResourceValidator{ + ResourceName: "ibm_app_config_evaluate_feature_flag", + Schema: validateSchema, + } + + return &ibmAppConfigEvaluateFeatureFlagDataSourceValidator +} + +func dataSourceAppConfigurationFeatureFlagRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + + ac := acLib.GetInstance() + sess, err := meta.(conns.ClientSession).BluemixSession() + if err != nil { + return diag.FromErr(err) + } + region := sess.Config.Region + apiKey := sess.Config.BluemixAPIKey + guid := d.Get("guid").(string) + collectionId := d.Get("collection_id").(string) + environmentId := d.Get("environment_id").(string) + + ac.Init(region, guid, apiKey) + ac.SetContext(collectionId, environmentId) + + featureId := d.Get("feature_id").(string) + entityId := d.Get("entity_id").(string) + entityAttributes := make(map[string]interface{}) + if d.Get("entity_attributes") != nil { + entityAttributes = d.Get("entity_attributes").(map[string]interface{}) + } + + feature, err := ac.GetFeature(featureId) + if err != nil { + return diag.FromErr(fmt.Errorf("failed to retrieve feature flag: %w", err)) + } + + result := feature.GetCurrentValue(entityId, entityAttributes) + + d.SetId(guid + "_" + featureId) + + switch result.(type) { + case string: + if err = d.Set("result_string", result.(string)); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + case float64: + if err = d.Set("result_numeric", result); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + case bool: + if err = d.Set("result_boolean", result.(bool)); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + default: + resultVal, err := json.Marshal(result) + if err != nil { + return diag.FromErr(fmt.Errorf("Error with json marshal : %w", err)) + } + stringRes := strings.Replace(string(resultVal), "\"", "'", -1) + if err = d.Set("result_string", stringRes); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + } + + return nil +} diff --git a/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag_test.go b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag_test.go new file mode 100644 index 0000000000..7cc4e93ddb --- /dev/null +++ b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_feature_flag_test.go @@ -0,0 +1,43 @@ +// Copyright IBM Corp. 2023 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package appconfigurationevaluation_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMAppConfigEvaluateFeatureFlagDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMAppConfigEvaluateFeatureFlagDataSourceBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_app_config_evaluate_feature_flag.evaluate_feature_flag", "id"), + ), + }, + }, + }) +} + +func testAccCheckIBMAppConfigEvaluateFeatureFlagDataSourceBasic() string { + return fmt.Sprintf(` + data "ibm_app_config_evaluate_feature_flag" "evaluate_feature_flag" { + guid = "36401ffc-6280-459a-ba98-456aba10d0c7" + environment_id = "dev" + collection_id = "car-rentals" + feature_id = "weekend-discount" + entity_id = "john_doe" + entity_attributes = { + "city" : "Bangalore", + "radius" : 60 + } + } + `) +} diff --git a/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property.go b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property.go new file mode 100644 index 0000000000..5349581874 --- /dev/null +++ b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property.go @@ -0,0 +1,211 @@ +// Copyright IBM Corp. 2021 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package appconfigurationevaluation + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" + acLib "github.com/IBM/appconfiguration-go-sdk/lib" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceAppConfigEvaluateProperty() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceAppConfigurationPropertyRead, + + Schema: map[string]*schema.Schema{ + "guid": { + Type: schema.TypeString, + Required: true, + Description: "App Configuration instance id or guid.", + }, + "environment_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the environment created in App Configuration instance under the Environments section.", + }, + "collection_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the collection created in App Configuration instance under the Collections section.", + }, + "property_id": { + Type: schema.TypeString, + Required: true, + Description: "Property id required to be evaluated.", + }, + "entity_id": { + Type: schema.TypeString, + Required: true, + Description: "Id of the Entity. This will be a string identifier related to the Entity against which" + + "the property is evaluated. For example, an entity might be an instance of an app that runs on a mobile device," + + "a microservice that runs on the cloud, or a component of infrastructure that runs that microservice." + + "For any entity to interact with App Configuration, it must provide a unique entity ID.", + }, + "entity_attributes": { + Type: schema.TypeMap, + Optional: true, + Description: "Key value pair consisting of the attribute name and their values that defines the specified entity. " + + "This is an optional parameter if the property is not configured with any targeting definition. If the " + + "targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is " + + "a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity " + + "satisfies the targeting rules, and returns the appropriate property value.", + Sensitive: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "secret": { + Type: schema.TypeBool, + Description: "Flag to check secret", + Default: false, + Optional: true, + }, + "result_boolean": { + Type: schema.TypeBool, + Computed: true, + Description: "Contains the evaluated value of the STRING type property only.", + }, + "result_string": { + Type: schema.TypeString, + Computed: true, + Description: "Contains the evaluated value of the STRING type property only.", + }, + "result_numeric": { + Type: schema.TypeInt, + Computed: true, + Description: "Contains the evaluated value of the STRING type property only.", + }, + }, + } +} + +func DataSourceIBMAppConfigEvaluatePropertyValidator() *validate.ResourceValidator { + validateSchema := make([]validate.ValidateSchema, 0) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "guid", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "environment_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "collection_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "property_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "entity_id", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + }) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "entity_attributes", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.ValueType(schema.TypeMap), + Required: false, + }) + + ibmAppConfigEvaluatePropertyDataSourceValidator := validate.ResourceValidator{ + ResourceName: "ibm_app_config_evaluate_property", + Schema: validateSchema, + } + return &ibmAppConfigEvaluatePropertyDataSourceValidator +} + +func dataSourceAppConfigurationPropertyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + ac := acLib.GetInstance() + sess, err := meta.(conns.ClientSession).BluemixSession() + if err != nil { + return diag.FromErr(err) + } + region := sess.Config.Region + apiKey := sess.Config.BluemixAPIKey + guid := d.Get("guid").(string) + collectionId := d.Get("collection_id").(string) + environmentId := d.Get("environment_id").(string) + + ac.Init(region, guid, apiKey) + ac.SetContext(collectionId, environmentId) + + propertyId := d.Get("property_id").(string) + entityId := d.Get("entity_id").(string) + entityAttributes := make(map[string]interface{}) + if d.Get("entity_attributes") != nil { + entityAttributes = d.Get("entity_attributes").(map[string]interface{}) + } + + property, err := ac.GetProperty(propertyId) + if err != nil { + return diag.FromErr(fmt.Errorf("failed to retrieve property: %w", err)) + } + + d.SetId(guid + "_" + propertyId) + + result := property.GetCurrentValue(entityId, entityAttributes) + + switch result.(type) { + case string: + if err = d.Set("result_string", result.(string)); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + case float64: + if err = d.Set("result_numeric", result); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + case bool: + if err = d.Set("result_boolean", result.(bool)); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + default: + + var resultMap map[string]interface{} + var ok bool + + if resultMap, ok = result.(map[string]interface{}); ok { + key := "secret_type" + + // Check if the key exists in the map + if _, exists := resultMap[key]; exists { + d.Set("secret", true) + } + } + resultVal, err := json.Marshal(resultMap) + if err != nil { + return diag.FromErr(fmt.Errorf("Error with json marshal : %w", err)) + } + stringRes := strings.Replace(string(resultVal), "\"", "'", -1) + + if err = d.Set("result_string", stringRes); err != nil { + return diag.FromErr(fmt.Errorf("Error setting the result: %s", err)) + } + } + + return nil +} diff --git a/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property_test.go b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property_test.go new file mode 100644 index 0000000000..f9d76edc05 --- /dev/null +++ b/ibm/service/appconfigurationevaluation/data_source_ibm_app_config_evaluate_property_test.go @@ -0,0 +1,43 @@ +// Copyright IBM Corp. 2023 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package appconfigurationevaluation_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMAppConfigEvaluatePropertyDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMAppConfigEvaluatePropertyDataSourceBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_app_config_evaluate_property.evaluate_property", "id"), + ), + }, + }, + }) +} + +func testAccCheckIBMAppConfigEvaluatePropertyDataSourceBasic() string { + return fmt.Sprintf(` + data "ibm_app_config_evaluate_property" "evaluate_property" { + guid = "36401ffc-6280-459a-ba98-456aba10d0c7" + environment_id = "dev" + collection_id = "car-rentals" + property_id = "users-location" + entity_id = "john_doe" + entity_attributes = { + "city" : "Bangalore", + "radius" : 60 + } + } + `) +} diff --git a/website/allowed-subcategories.txt b/website/allowed-subcategories.txt index 1e97423139..a5a3f03ad3 100644 --- a/website/allowed-subcategories.txt +++ b/website/allowed-subcategories.txt @@ -2,6 +2,7 @@ Activity Tracker API Gateway App ID Management App Configuration +App Configuration Evaluation Catalog Management Classic infrastructure Cloud Database diff --git a/website/docs/d/app_config_evaluate_feature_flag.html.markdown b/website/docs/d/app_config_evaluate_feature_flag.html.markdown new file mode 100644 index 0000000000..e499071965 --- /dev/null +++ b/website/docs/d/app_config_evaluate_feature_flag.html.markdown @@ -0,0 +1,58 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_app_config_evaluate_feature_flag" +description: |- + Get information about AppConfigurationFeatureFlagEvaluation +subcategory: "App Configuration Evaluation" +--- + +# ibm_app_config_evaluate_feature_flag + +Provides a read-only data source for feature flag evaluation. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_app_config_evaluate_feature_flag" "evaluate_feature_flag" { + guid = "0b5571f7-21e6-42b7-91c5-3f5ac9793a46" + environment_id = "dev" + collection_id = "car-rentals" + feature_id = "weekend-discount" + entity_id = "john_doe" + entity_attributes = { + "city" : "Bangalore", + "radius" : 60, + } +} +``` + +**provider.tf** +Please make sure to target right region in the provider block. + +```hcl +provider "ibm" { + ibmcloud_api_key = var.ibmcloud_api_key + region = var.region +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `region` - (Required, String) The region of the App Configuration instance. +* `guid` - (Required, String) The guid or instance id of the App Configuration instance. +* `environment_id` - (Required, String) Id of the environment created in App Configuration instance under the Environments section. +* `collection_id` - (Required, String) Id of the collection created in App Configuration instance under the Collections section. +* `feature_id` - (Required, String) Feature flag id required to be evaluated. +* `entity_id` - (Required, String) Id of the Entity. This will be a string identifier related to the Entity against which the feature is evaluated. For example, an entity might be an instance of an app that runs on a mobile device, a microservice that runs on the cloud, or a component of infrastructure that runs that microservice. For any entity to interact with App Configuration, it must provide a unique entity ID." +* `entity_attributes` - (Optional, Map) Key value pair consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the feature flag is not configured with any targeting definition. If the targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity satisfies the targeting rules, and returns the appropriate feature flag value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the AppConfigurationFeatureFlagEvaluation. +* `result_boolean` - (Boolean) Contains the evaluated value of the BOOLEAN type feature flags. +* `result_string` - (String) Contains the evaluated value of the STRING type feature flags. +* `result_numeric` - (Number) Contains the evaluated value of the NUMERIC type feature flags. diff --git a/website/docs/d/app_config_evaluate_property.html.markdown b/website/docs/d/app_config_evaluate_property.html.markdown new file mode 100644 index 0000000000..0cc6cd66a6 --- /dev/null +++ b/website/docs/d/app_config_evaluate_property.html.markdown @@ -0,0 +1,58 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_app_config_evaluate_property" +description: |- + Get information about AppConfigurationPropertyEvaluation +subcategory: "App Configuration Evaluation" +--- + +# ibm_app_config_evaluate_property + +Provides a read-only data source for property evaluation. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_app_config_evaluate_property" "evaluate_property" { + guid = "0b5571f7-21e6-42b7-91c5-3f5ac9793a46" + environment_id = "dev" + collection_id = "car-rentals" + property_id = "users-location" + entity_id = "john_doe" + entity_attributes = { + "city" : "Bangalore", + "radius" : 60, + } +} +``` + +**provider.tf** +Please make sure to target right region in the provider block. + +```hcl +provider "ibm" { + ibmcloud_api_key = var.ibmcloud_api_key + region = var.region +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `region` - (Required, String) The region of the App Configuration instance. +* `guid` - (Required, String) The guid or instance id of the App Configuration instance. +* `environment_id` - (Required, String) Id of the environment created in App Configuration instance under the Environments section. +* `collection_id` - (Required, String) Id of the collection created in App Configuration instance under the Collections section. +* `property_id` - (Required, String) Property id required to be evaluated. +* `entity_id` - (Required, String) Id of the Entity. This will be a string identifier related to the Entity against which the property is evaluated. For example, an entity might be an instance of an app that runs on a mobile device, a microservice that runs on the cloud, or a component of infrastructure that runs that microservice. For any entity to interact with App Configuration, it must provide a unique entity ID." +* `entity_attributes` - (Optional, Map) Key value pair consisting of the attribute name and their values that defines the specified entity. This is an optional parameter if the property is not configured with any targeting definition. If the targeting is configured, then entityAttributes should be provided for the rule evaluation. An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the specified entity satisfies the targeting rules, and returns the appropriate property value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the AppConfigurationPropertyEvaluation. +* `result_boolean` - (Boolean) Contains the evaluated value of the BOOLEAN type properties. +* `result_string` - (String) Contains the evaluated value of the STRING type properties. +* `result_numeric` - (Number) Contains the evaluated value of the NUMERIC type properties. From a63a43dba96377b9e9aaf66f7b2ba99bab5f20ac Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Tue, 21 Nov 2023 12:01:01 +0530 Subject: [PATCH 2/3] update go.sum --- go.sum | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/go.sum b/go.sum index 70de6a86b5..54af976a73 100644 --- a/go.sum +++ b/go.sum @@ -445,6 +445,7 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3 github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= @@ -599,6 +600,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.13.0/go.mod h1:dwu7+CG8/CtBiJFZDz4e+5Upb6OLw04gtBYw0mcG/z4= github.com/go-playground/validator/v10 v10.15.5 h1:LEBecTWb/1j5TNY1YYG2RcOUN3R7NLylN+x8TTueE24= github.com/go-playground/validator/v10 v10.15.5/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -860,6 +862,7 @@ github.com/hashicorp/go-retryablehttp v0.6.2/go.mod h1:gEx6HMUGxYYhJScX7W1Il64m6 github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-retryablehttp v0.7.4 h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA= github.com/hashicorp/go-retryablehttp v0.7.4/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= @@ -1116,6 +1119,7 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LE github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.2.3/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -1603,6 +1607,7 @@ go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R7 go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= +go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.mongodb.org/mongo-driver v1.12.1 h1:nLkghSU8fQNaK7oUmDhQFsnrtcoNy7Z6LVFKsEecqgE= go.mongodb.org/mongo-driver v1.12.1/go.mod h1:/rGBTebI3XYboVmgz+Wv3Bcbl3aD0QF9zl6kDDw18rQ= go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A= @@ -1938,6 +1943,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From f14c4240286e9cb435f8b1a529cb9c0f231f3959 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Thu, 23 Nov 2023 18:09:19 +0530 Subject: [PATCH 3/3] update example --- examples/ibm-app-configuration-evaluation/outputs.tf | 6 +++--- examples/ibm-app-configuration-evaluation/variables.tf | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/ibm-app-configuration-evaluation/outputs.tf b/examples/ibm-app-configuration-evaluation/outputs.tf index bb34ae1e9d..8d30c78f91 100644 --- a/examples/ibm-app-configuration-evaluation/outputs.tf +++ b/examples/ibm-app-configuration-evaluation/outputs.tf @@ -1,4 +1,4 @@ -// This output allows ibm_app_config_evaluate_feature_flag data to be referenced by other resources and the terraform CLI +// This output allows data to be referenced by other resources and the terraform CLI // Modify this output if only certain data should be exposed output "ibm_app_config_feature_flag_evaluated_value" { @@ -6,7 +6,7 @@ output "ibm_app_config_feature_flag_evaluated_value" { description = "Feature flag evaluated value." } output "ibm_app_config_feature_flag_evaluated_values" { - value = data.ibm_app_config_evaluate_feature_flag.evaluate_feature_flags["f2"].result_string + value = values(data.ibm_app_config_evaluate_feature_flag.evaluate_feature_flags)[*].result_boolean description = "Feature flag evaluated values." } output "ibm_app_config_property_evaluated_value" { @@ -14,6 +14,6 @@ output "ibm_app_config_property_evaluated_value" { description = "Property evaluated value." } output "ibm_app_config_property_evaluated_values" { - value = data.ibm_app_config_evaluate_property.evaluate_properties["p2"].result_boolean + value = values(data.ibm_app_config_evaluate_property.evaluate_properties)[*].result_string description = "Property evaluated values." } diff --git a/examples/ibm-app-configuration-evaluation/variables.tf b/examples/ibm-app-configuration-evaluation/variables.tf index 45e10b5263..b90ee110d4 100644 --- a/examples/ibm-app-configuration-evaluation/variables.tf +++ b/examples/ibm-app-configuration-evaluation/variables.tf @@ -40,10 +40,10 @@ variable "app_config_entity_id" { } variable "app_config_entity_attributes" { description = "Entity attributes for evaluation." - type = map() + type = map(any) default = { - "city" : "Bangalore", - "radius" : 60, + city = "Bangalore", + radius = 60, } } variable "app_config_feature_flag_ids" {