Skip to content

Commit

Permalink
App config bug fix (#5748)
Browse files Browse the repository at this point in the history
* app-config-bug-fix

* app config bug fix

* review comments1

* review comments

* indent

* indent

* bug fix

* issue-fix

* doc changes

* docs

* review

* review comments

* documentation fix
  • Loading branch information
Ramya-c4 authored Oct 30, 2024
1 parent 15e4757 commit 619c55b
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package appconfiguration

import (
"fmt"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
10 changes: 10 additions & 0 deletions ibm/service/appconfiguration/data_source_ibm_app_config_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func DataSourceIBMAppConfigFeature() *schema.Resource {
Computed: true,
Description: "Rollout percentage of the feature.",
},
"format": {
Type: schema.TypeString,
Computed: true,
Description: "Format of the feature (TEXT, JSON, YAML) and it is a required attribute when `type` is `STRING`. It is not required for `BOOLEAN` and `NUMERIC` types. This property is populated in the response body of `POST, PUT and GET` calls if the type `STRING` is used and not populated for `BOOLEAN` and `NUMERIC` types.",
},
"segment_rules": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -216,6 +221,11 @@ func dataSourceIbmAppConfigFeatureRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("[ERROR] Error setting rollout_percentage: %s", err)
}
}
if result.Format != nil {
if err = d.Set("format", result.Format); err != nil {
return fmt.Errorf("[ERROR] Error setting format: %s", err)
}
}
if result.SegmentExists != nil {
if err = d.Set("segment_exists", result.SegmentExists); err != nil {
return fmt.Errorf("[ERROR] Error setting segment_exists: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func DataSourceIBMAppConfigFeatures() *schema.Resource {
Computed: true,
Description: "Feature description.",
},
"format": {
Type: schema.TypeString,
Computed: true,
Description: "Format of the feature (TEXT, JSON, YAML) and it is a required attribute when `type` is `STRING`. It is not required for `BOOLEAN` and `NUMERIC` types. This property is populated in the response body of `POST, PUT and GET` calls if the type `STRING` is used and not populated for `BOOLEAN` and `NUMERIC` types.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -430,6 +435,9 @@ func dataSourceFeaturesListFeaturesToMap(featuresItem appconfigurationv1.Feature
if featuresItem.RolloutPercentage != nil {
featuresMap["rollout_percentage"] = featuresItem.RolloutPercentage
}
if featuresItem.Format != nil {
featuresMap["format"] = featuresItem.Format
}
if featuresItem.SegmentRules != nil {
segmentRulesList := []map[string]interface{}{}
for _, segmentRulesItem := range featuresItem.SegmentRules {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

func TestAccIbmAppConfigFeaturesDataSourceBasic(t *testing.T) {
environmentID := "dev"
featureType := "BOOLEAN"
featureType := "STRING"
featureFormat := "TEXT"
tags := "development feature"
name := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100))
featureID := fmt.Sprintf("tf_feature_id_%d", acctest.RandIntRange(10, 100))
Expand All @@ -27,7 +28,7 @@ func TestAccIbmAppConfigFeaturesDataSourceBasic(t *testing.T) {
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, environmentID, featureID, featureType, description, tags),
Config: testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, environmentID, featureID, featureType, featureFormat, description, tags),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_app_config_features.app_config_features_data2", "id"),
resource.TestCheckResourceAttrSet("data.ibm_app_config_features.app_config_features_data2", "first.#"),
Expand All @@ -44,7 +45,7 @@ func TestAccIbmAppConfigFeaturesDataSourceBasic(t *testing.T) {
})
}

func testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, environmentID, featureID, featureType, description, tags string) string {
func testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, environmentID, featureID, featureType, featureFormat, description, tags string) string {
return fmt.Sprintf(`
resource "ibm_resource_instance" "app_config_terraform_test487" {
name = "%s"
Expand All @@ -59,6 +60,7 @@ func testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, e
environment_id = "%s"
feature_id = "%s"
type = "%s"
format="%s"
enabled_value = true
disabled_value = false
description = "%s"
Expand All @@ -71,5 +73,5 @@ func testAccCheckIbmAppConfigFeaturesDataSourceConfigBasic(instanceName, name, e
guid = ibm_app_config_feature.app_config_feature_resource2.guid
environment_id = ibm_app_config_feature.app_config_feature_resource2.environment_id
}
`, instanceName, name, environmentID, featureID, featureType, description, tags)
`, instanceName, name, environmentID, featureID, featureType, featureFormat, description, tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func DataSourceIBMAppConfigProperties() *schema.Resource {
Computed: true,
Description: "Tags associated with the property.",
},
"format": {
Type: schema.TypeString,
Computed: true,
Description: "Format of the feature (TEXT, JSON, YAML) and it is a required attribute when `type` is `STRING`. It is not required for `BOOLEAN` and `NUMERIC` types. This property is populated in the response body of `POST, PUT and GET` calls if the type `STRING` is used and not populated for `BOOLEAN` and `NUMERIC` types.",
},
"segment_rules": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -372,6 +377,9 @@ func dataSourcePropertiesListPropertiesToMap(property appconfigurationv1.Propert
if property.Href != nil {
propertyMap["href"] = property.Href
}
if property.Format != nil {
propertyMap["format"] = property.Format
}
if property.Collections != nil {
collectionsList := []map[string]interface{}{}
for _, collectionsItem := range property.Collections {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func DataSourceIBMAppConfigProperty() *schema.Resource {
Computed: true,
Description: "Tags associated with the property.",
},
"format": {
Type: schema.TypeString,
Computed: true,
Description: "Format of the feature (TEXT, JSON, YAML) and it is a required attribute when `type` is `STRING`. It is not required for `BOOLEAN` and `NUMERIC` types. This property is populated in the response body of `POST, PUT and GET` calls if the type `STRING` is used and not populated for `BOOLEAN` and `NUMERIC` types.",
},
"segment_rules": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -194,6 +199,11 @@ func dataSourceIbmAppConfigPropertyRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error setting tags: %s", err)
}
}
if property.Format != nil {
if err = d.Set("format", property.Format); err != nil {
return fmt.Errorf("error setting format: %s", err)
}
}
if property.SegmentRules != nil {
err = d.Set("segment_rules", dataSourcePropertyFlattenSegmentRules(property.SegmentRules))
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package appconfiguration

import (
"fmt"
"log"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
)

func DataSourceIBMAppConfigSegment() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appconfiguration

import (
"fmt"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package appconfiguration

import (
"fmt"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down
13 changes: 13 additions & 0 deletions ibm/service/appconfiguration/resource_ibm_app_config_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func ResourceIBMIbmAppConfigFeature() *schema.Resource {
Optional: true,
Description: "Rollout percentage of the feature.",
},
"format": {
Type: schema.TypeString,
Optional: true,
Description: "Format of the feature (TEXT, JSON, YAML).",
},
"segment_rules": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -174,6 +179,9 @@ func resourceIbmIbmAppConfigFeatureCreate(d *schema.ResourceData, meta interface
if _, ok := d.GetOk("rollout_percentage"); ok {
options.SetRolloutPercentage(int64(d.Get("rollout_percentage").(int)))
}
if _, ok := d.GetOk("format"); ok {
options.SetFormat(d.Get("format").(string))
}
if _, ok := d.GetOk("description"); ok {
options.SetDescription(d.Get("description").(string))
}
Expand Down Expand Up @@ -320,6 +328,11 @@ func resourceIbmIbmAppConfigFeatureRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("[ERROR] Error setting rollout_percentage: %s", err)
}
}
if result.Format != nil {
if err = d.Set("format", result.Format); err != nil {
return fmt.Errorf("[ERROR] Error setting format: %s", err)
}
}
if result.Tags != nil {
if err = d.Set("tags", result.Tags); err != nil {
return fmt.Errorf("[ERROR] Error setting tags: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package appconfiguration

import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"log"
"strconv"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package appconfiguration

import (
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
)

func ResourceIBMIbmAppConfigSegment() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package appconfiguration

import (
"fmt"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func ResourceIBMIbmAppConfigSnapshot() *schema.Resource {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/app_config_feature.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ In addition to all argument references list, you can access the following attrib
- `name` - (String) Feature name.
- `description` - (String) Feature description.
- `type` - (String) Type of the feature (BOOLEAN, STRING, NUMERIC).
- `format` - Format of the property (TEXT, JSON, YAML) and this is a required attribute when TYPE STRING is used, not required for BOOLEAN and NUMERIC types.
- `enabled_value` - (String) Value of the feature when it is enabled. The value can be Boolean, String or a Numeric value as per the `type` attribute.
- `disabled_value` - (String) Value of the feature when it is disabled. The value can be Boolean, String or a Numeric value as per the `type` attribute.
- `enabled` - (String) The state of the feature flag.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/app_config_feature.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ resource "ibm_app_config_feature" "app_config_feature" {
name = "name"
type = "type"
tags = "tags"
format="format"
feature_id = "feature_id"
enabled_value = "enabled_value"
environment_id = "environment_id"
Expand All @@ -33,6 +34,7 @@ Review the argument reference that you can specify for your resource.
- `guid` - (Required, String) The GUID of the App Configuration service. Fetch GUID from the service instance credentials section of the dashboard.
- `environment_id` - (Required, String) The environment ID.
- `name` - (Required, String) The feature name.
- `format` - Format of the property (TEXT, JSON, YAML) and this is a required attribute when TYPE STRING is used, not required for BOOLEAN and NUMERIC types.
- `feature_id` - (Required, String) The feature ID.
- `type` - (Required, String) The feature type. Supported values are **BOOLEAN**, **STRING**, or **NUMERIC**.
- `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.
Expand Down

0 comments on commit 619c55b

Please sign in to comment.