Skip to content

Commit 31732cc

Browse files
Enabled the user to set 'enabled' value for feature flag (IBM-Cloud#5940)
* covered plain Fmt.ErrorF with flex.FmtErrorF wrapper * coverted error logs to flex errors * reverted flex error to plain error for get client function * resolved struct name changes from go-admin-sdk 0.3.0 to 0.4.4 upgrade * made code compliant with go fmt requirements * solving errors in struct type matching and string array conversion * test file changes * added switch cases for hrefUrl * enabled toggle of feature to be set by user * Added code to read enabled value and set in go-admin-sdk call * add documentation for app config feature "enabled" attribute * enabled update function to check for change in "enabled" value
1 parent 8c11394 commit 31732cc

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

ibm/service/appconfiguration/resource_ibm_app_config_feature.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func ResourceIBMIbmAppConfigFeature() *schema.Resource {
140140
},
141141
"enabled": {
142142
Type: schema.TypeBool,
143-
Computed: true,
143+
Optional: true,
144144
Description: "The state of the feature flag.",
145145
},
146146
"created_time": {
@@ -187,6 +187,9 @@ func resourceIbmIbmAppConfigFeatureCreate(d *schema.ResourceData, meta interface
187187
if _, ok := d.GetOk("tags"); ok {
188188
options.SetTags(d.Get("tags").(string))
189189
}
190+
if _, ok := d.GetOk("enabled"); ok {
191+
options.SetEnabled(d.Get("enabled").(bool))
192+
}
190193

191194
if _, ok := d.GetOk("segment_rules"); ok {
192195
var segmentRules []appconfigurationv1.FeatureSegmentRule
@@ -233,14 +236,17 @@ func resourceIbmIbmAppConfigFeatureUpdate(d *schema.ResourceData, meta interface
233236
options.SetEnvironmentID(parts[1])
234237
options.SetFeatureID(parts[2])
235238

236-
if ok := d.HasChanges("name", "enabled_value", "disabled_value", "description", "rollout_percentage", "tags", "segment_rules", "collections"); ok {
239+
if ok := d.HasChanges("name", "enabled_value", "disabled_value", "description", "rollout_percentage", "tags", "segment_rules", "collections", "enabled"); ok {
237240
options.SetName(d.Get("name").(string))
238241
options.SetEnabledValue(d.Get("enabled_value").(string))
239242
options.SetDisabledValue(d.Get("disabled_value").(string))
240243

241244
if _, ok := d.GetOk("description"); ok {
242245
options.SetDescription(d.Get("description").(string))
243246
}
247+
if _, ok := d.GetOk("enabled"); ok {
248+
options.SetEnabled(d.Get("enabled").(bool))
249+
}
244250
if _, ok := d.GetOk("rollout_percentage"); ok {
245251
options.SetRolloutPercentage(int64(d.Get("rollout_percentage").(int)))
246252
}

ibm/service/appconfiguration/resource_ibm_app_config_feature_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestAccIbmIbmAppConfigFeatureBasic(t *testing.T) {
4444
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "tags"),
4545
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "feature_id"),
4646
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "description"),
47+
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "enabled"),
4748
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "enabled_value"),
4849
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "disabled_value"),
4950
resource.TestCheckResourceAttrSet("ibm_app_config_feature.ibm_app_config_feature_resource1", "rollout_percentage"),
@@ -80,6 +81,7 @@ func testAccCheckIbmAppConfigFeatureConfigBasic(name, envName, featureID, featur
8081
description = "%s"
8182
tags = "%s"
8283
rollout_percentage = "80"
84+
enabled = false
8385
}`, name, envName, featureID, featureType, description, tags)
8486
}
8587

website/docs/r/app_config_feature.html.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Create, update, or delete an environment by using IBM Cloud™ App Configuration
1313
## Example usage
1414

1515
```terraform
16+
# Example 1
1617
resource "ibm_app_config_feature" "app_config_feature" {
1718
guid = "guid"
1819
name = "name"
@@ -24,6 +25,25 @@ resource "ibm_app_config_feature" "app_config_feature" {
2425
environment_id = "environment_id"
2526
disabled_value = "disabled_value"
2627
rollout_percentage = "rollout_percentage"
28+
enabled = false
29+
}
30+
31+
# Example 2
32+
resource "ibm_app_config_feature" "app_config_feature" {
33+
guid = "guid"
34+
name = "name"
35+
type = "type"
36+
tags = "tags"
37+
format="format"
38+
feature_id = "feature_id"
39+
enabled_value = "enabled_value"
40+
environment_id = "environment_id"
41+
disabled_value = "disabled_value"
42+
rollout_percentage = "rollout_percentage"
43+
collections {
44+
collection_id = "collection_id"
45+
}
46+
enabled = true
2747
}
2848
```
2949

@@ -39,6 +59,7 @@ Review the argument reference that you can specify for your resource.
3959
- `type` - (Required, String) The feature type. Supported values are **BOOLEAN**, **STRING**, or **NUMERIC**.
4060
- `enabled_value` - (Required, String) The value of the feature when it is enabled. The value can be **BOOLEAN**, **STRING**, or **NUMERIC** value as per the `type` attribute.
4161
- `disabled_value` - (Required, String) The value of the feature when it is disabled. The value can be **BOOLEAN**, **STRING**, or **NUMERIC** value as per the `type` attribute.
62+
- `enabled` - (Optional, Boolean) The value of the state of feature. (Note:- If enabled is set to *false*, collections is optional but for setting enabled to *true* collections is required to be set).
4263
- `description` - (Optional, String) The feature description.
4364
- `tags` - (Optional, String) Tags associated with the feature.
4465
- `rollout_percentage` - (String) Rollout percentage of the feature.

0 commit comments

Comments
 (0)