diff --git a/.github/labeler-issue.yml b/.github/labeler-issue.yml index 315ef69c2e..dcfa7c5472 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..8d30c78f91 --- /dev/null +++ b/examples/ibm-app-configuration-evaluation/outputs.tf @@ -0,0 +1,19 @@ +// 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" { + 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 = 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" { + value = data.ibm_app_config_evaluate_property.evaluate_property.result_numeric + description = "Property evaluated value." +} +output "ibm_app_config_property_evaluated_values" { + 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 new file mode 100644 index 0000000000..b90ee110d4 --- /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(any) + 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 42e8bb4760..29c1b89268 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/IBM-Cloud/power-go-client v1.9.0 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.7.1 github.com/IBM/cloud-db2-go-sdk v0.0.0-20241206113855-40a65de39906 @@ -127,6 +128,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 @@ -198,9 +200,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.2 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect diff --git a/go.sum b/go.sum index d705306645..767d3be851 100644 --- a/go.sum +++ b/go.sum @@ -126,6 +126,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.7.1 h1:5kK4/3NUsGxZzmuUe+1ftajpOQbeDVh5VeemrPgROP4= @@ -156,6 +158,7 @@ github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3bt github.com/IBM/go-sdk-core/v5 v5.7.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc= github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE= github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI= +github.com/IBM/go-sdk-core/v5 v5.14.1/go.mod h1:MUvIr/1mgGh198ZXL+ByKz9Qs1JoEh80v/96x8jPXNY= github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns= github.com/IBM/go-sdk-core/v5 v5.18.1 h1:wdftQO8xejECTWTKF3FGXyW0McKxxDAopH7MKwA187c= github.com/IBM/go-sdk-core/v5 v5.18.1/go.mod h1:3ywpylZ41WhWPusqtpJZWopYlt2brebcphV7mA2JncU= @@ -190,6 +193,8 @@ github.com/IBM/scc-go-sdk/v5 v5.4.1 h1:RXIuxOo9/hxkWyHCI69ae+KIJgSbXcAkJwTEl+fO3 github.com/IBM/scc-go-sdk/v5 v5.4.1/go.mod h1:2xQTDgNXG5QMEfQxBDKB067z+5ha6OgcaKCTcdGDAo8= github.com/IBM/schematics-go-sdk v0.3.0 h1:Vwxw85SONflakiBsNHAfViKLyp9zJiH5/hh6SewOP5Q= github.com/IBM/schematics-go-sdk v0.3.0/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/go.mod h1:jagqWmjZ0zUEqh5jdGB42ApSQS40fu2LWw6pdg8JJko= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7 h1:5lKt1rHuKaAaiZtbPfsF8dgiko/gGbVgreiut3zU128= github.com/IBM/secrets-manager-go-sdk/v2 v2.0.7/go.mod h1:RglK3v6CPe3T1myRtQCD6z+nBygXvNJwufAon0qcZok= github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w9M= @@ -604,6 +609,7 @@ github.com/go-openapi/strfmt v0.20.1/go.mod h1:43urheQI9dNtE5lTZQfuFJvjYJKPrxicA github.com/go-openapi/strfmt v0.20.2/go.mod h1:43urheQI9dNtE5lTZQfuFJvjYJKPrxicATpEfZwHUNk= github.com/go-openapi/strfmt v0.21.1/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/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew= github.com/go-openapi/strfmt v0.22.1/go.mod h1:OfVoytIXJasDkkGvkb1Cceb3BPyMOwk1FgmyyEw7NYg= github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= @@ -636,6 +642,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.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= @@ -820,6 +827,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= @@ -916,6 +925,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.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= @@ -1188,6 +1198,7 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 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.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= @@ -1371,6 +1382,7 @@ github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+t github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.0/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= @@ -1517,6 +1529,8 @@ github.com/rboyer/safeio v0.2.1/go.mod h1:Cq/cEPK+YXFn622lsQ0K4KsPZSPtaptHHEldsy 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= @@ -1577,6 +1591,8 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b h1:br+bPNZsJWKicw/5rALEo67QHs5weyD5tf8WST+4sJ0= github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= 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= @@ -1699,6 +1715,7 @@ go.mongodb.org/mongo-driver v1.7.0/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8N 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.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4l8= go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index f758b20e4c..8005b659fa 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -19,6 +19,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "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" @@ -618,18 +619,24 @@ func Provider() *schema.Provider { "ibm_kms_kmip_object": kms.DataSourceIBMKMSKMIPObject(), "ibm_kms_kmip_objects": kms.DataSourceIBMKMSKMIPObjects(), "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(), @@ -2211,6 +2218,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 2d74306a9b..34fc383963 100644 --- a/website/allowed-subcategories.txt +++ b/website/allowed-subcategories.txt @@ -2,6 +2,7 @@ Activity Tracker Event Routing 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.