From 75a7487fc2a905781ab41b67d0c4d036e90d69a9 Mon Sep 17 00:00:00 2001 From: Ramya-c4 Date: Thu, 17 Oct 2024 22:51:02 +0530 Subject: [PATCH] bug fix (#5723) * bug fix * configs change * review changes requested --- examples/ibm-configuration-aggregator/main.tf | 2 +- .../ibm-configuration-aggregator/outputs.tf | 28 +++++- .../ibm-configuration-aggregator/variables.tf | 2 - .../ibm-configuration-aggregator/versions.tf | 6 +- ...ce_ibm_config_aggregator_configurations.go | 95 ++++--------------- ...resource_ibm_config_aggregator_settings.go | 8 -- ...ig_aggregator_configurations.html.markdown | 4 +- 7 files changed, 49 insertions(+), 96 deletions(-) diff --git a/examples/ibm-configuration-aggregator/main.tf b/examples/ibm-configuration-aggregator/main.tf index 44d5f32998..c558ba48d7 100644 --- a/examples/ibm-configuration-aggregator/main.tf +++ b/examples/ibm-configuration-aggregator/main.tf @@ -10,7 +10,7 @@ resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance" resource_collection_regions = var.config_aggregator_settings_regions } -data "ibm_config_aggregator_configurations" "config_aggregator_configurations_instance" { +data "ibm_config_aggregator_configurations" "example" { instance_id=var.instance_id region =var.region diff --git a/examples/ibm-configuration-aggregator/outputs.tf b/examples/ibm-configuration-aggregator/outputs.tf index 8551200963..1589b9d663 100644 --- a/examples/ibm-configuration-aggregator/outputs.tf +++ b/examples/ibm-configuration-aggregator/outputs.tf @@ -1,5 +1,29 @@ // This output allows config_aggregator_settings data to be referenced by other resources and the terraform CLI // Modify this output if only certain data should be exposed +locals { + entries = [ + for config in data.ibm_config_aggregator_configurations.example.configs : { + about = { + account_id = config.about.account_id + config_type = config.about.config_type + last_config_refresh_time = config.about.last_config_refresh_time + location = config.about.location + resource_crn = config.about.resource_crn + resource_group_id = config.about.resource_group_id + resource_name = config.about.resource_name + service_name = config.about.service_name + tags={} + } + config = jsondecode(config.config) + } + ] +} + +output "ibm_config_aggregator_configurations" { + value = { + configs=local.entries + } +} output "config_aggregator_settings" { value = { additional_scope = [] @@ -18,10 +42,6 @@ output "aggregator_settings" { } } -output "ibm_config_aggregator_configurations" { - value = data.ibm_config_aggregator_configurations.config_aggregator_configurations_instance -} - output "config_aggregator_resource_collection_status"{ value={ status=data.ibm_config_aggregator_resource_collection_status.config_aggregator_resource_collection_status_instance.status diff --git a/examples/ibm-configuration-aggregator/variables.tf b/examples/ibm-configuration-aggregator/variables.tf index 9c3a3029dd..61bed75697 100644 --- a/examples/ibm-configuration-aggregator/variables.tf +++ b/examples/ibm-configuration-aggregator/variables.tf @@ -17,12 +17,10 @@ variable "instance_id"{ variable "config_aggregator_settings_resource_collection_enabled" { description = "The field denoting if the resource collection is enabled." type = bool - default = true } variable "config_aggregator_settings_trusted_profile_id" { description = "The trusted profile id that provides Reader access to the App Configuration instance to collect resource metadata." type = string - default="Profile-2546925a-7b46-40dd-81ff-48015a49ff43" } variable "config_aggregator_settings_regions" { description = "The list of regions across which the resource collection is enabled." diff --git a/examples/ibm-configuration-aggregator/versions.tf b/examples/ibm-configuration-aggregator/versions.tf index 1aba4e4655..3883805970 100644 --- a/examples/ibm-configuration-aggregator/versions.tf +++ b/examples/ibm-configuration-aggregator/versions.tf @@ -1,8 +1,8 @@ terraform { - required_version = ">= 1.0" +required_version = ">=1.0.0, <2.0" required_providers { ibm = { - source = "terraform.local/ibm-cloud/ibm" + source = "registry.terraform.io/ibm-cloud/ibm" } } -} +} \ No newline at end of file diff --git a/ibm/service/configurationaggregator/data_source_ibm_config_aggregator_configurations.go b/ibm/service/configurationaggregator/data_source_ibm_config_aggregator_configurations.go index 93cff5aacd..9cac155764 100644 --- a/ibm/service/configurationaggregator/data_source_ibm_config_aggregator_configurations.go +++ b/ibm/service/configurationaggregator/data_source_ibm_config_aggregator_configurations.go @@ -9,6 +9,7 @@ package configurationaggregator import ( "context" + "encoding/json" "fmt" "log" "time" @@ -77,75 +78,17 @@ func DataSourceIbmConfigAggregatorConfigurations() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "about": &schema.Schema{ - Type: schema.TypeList, + Type: schema.TypeMap, Computed: true, Description: "The basic metadata fetched from the query API.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "account_id": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The account ID in which the resource exists.", - }, - "config_type": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The type of configuration of the retrieved resource.", - }, - "resource_crn": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The unique CRN of the IBM Cloud resource.", - }, - "resource_group_id": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The account ID.", - }, - "service_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The name of the service to which the resources belongs.", - }, - "resource_name": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "User defined name of the resource.", - }, - "last_config_refresh_time": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "Date/time stamp identifying when the information was last collected. Must be in the RFC 3339 format.", - }, - "location": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "Location of the resource specified.", - }, - "tags": &schema.Schema{ - Type: schema.TypeList, - Computed: true, - Description: "Tags associated with the resource.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "tag": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - Description: "The name of the tag.", - }, - }, - }, - }, - }, + Elem: &schema.Schema{ + Type: schema.TypeString, }, }, "config": &schema.Schema{ - Type: schema.TypeList, + Type: schema.TypeString, Computed: true, Description: "The configuration of the resource.", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{}, - }, }, }, }, @@ -166,8 +109,6 @@ func dataSourceIbmConfigAggregatorConfigurationsRead(context context.Context, d instanceId := d.Get("instance_id").(string) log.Printf("Fetching config for instance_id: %s", instanceId) configurationAggregatorClient = getClientWithConfigurationInstanceEndpoint(configurationAggregatorClient, instanceId, region) - fmt.Println("Logging endpoint from datasource") - fmt.Println(configurationAggregatorClient.GetServiceURL()) listConfigsOptions := &configurationaggregatorv1.ListConfigsOptions{} @@ -244,12 +185,12 @@ func DataSourceIbmConfigAggregatorConfigurationsConfigToMap(model *configuration if err != nil { return modelMap, err } - modelMap["about"] = []map[string]interface{}{aboutMap} + modelMap["about"] = aboutMap configMap, err := DataSourceIbmConfigAggregatorConfigurationsConfigurationToMap(model.Config) if err != nil { return modelMap, err } - modelMap["config"] = []map[string]interface{}{configMap} + modelMap["config"] = configMap return modelMap, nil } @@ -263,13 +204,7 @@ func DataSourceIbmConfigAggregatorConfigurationsAboutToMap(model *configurationa modelMap["resource_name"] = *model.ResourceName modelMap["last_config_refresh_time"] = model.LastConfigRefreshTime.String() modelMap["location"] = *model.Location - if model.Tags != nil { - tagsMap, err := DataSourceIbmConfigAggregatorConfigurationsTagsToMap(model.Tags) - if err != nil { - return modelMap, err - } - modelMap["tags"] = []map[string]interface{}{tagsMap} - } + // modelMap["tags"] = make(map[string]interface{}) return modelMap, nil } @@ -281,7 +216,15 @@ func DataSourceIbmConfigAggregatorConfigurationsTagsToMap(model *configurationag return modelMap, nil } -func DataSourceIbmConfigAggregatorConfigurationsConfigurationToMap(model *configurationaggregatorv1.Configuration) (map[string]interface{}, error) { - modelMap := make(map[string]interface{}) - return modelMap, nil +func DataSourceIbmConfigAggregatorConfigurationsConfigurationToMap(model *configurationaggregatorv1.Configuration) (string, error) { + checkMap := model.GetProperties() + tryMap := make(map[string]interface{}) + for i, v := range checkMap { + tryMap[i] = v + } + jsonData, err := json.Marshal(tryMap) + if err != nil { + return "", err + } + return string(jsonData), nil } diff --git a/ibm/service/configurationaggregator/resource_ibm_config_aggregator_settings.go b/ibm/service/configurationaggregator/resource_ibm_config_aggregator_settings.go index b1bf8e4e34..17a29d4776 100644 --- a/ibm/service/configurationaggregator/resource_ibm_config_aggregator_settings.go +++ b/ibm/service/configurationaggregator/resource_ibm_config_aggregator_settings.go @@ -148,10 +148,6 @@ func resourceIbmConfigAggregatorSettingsCreate(context context.Context, d *schem } replaceSettingsOptions.SetAdditionalScope(additionalScope) } - fmt.Println("After Logging endpoint from datasource") - fmt.Println(configurationAggregatorClient.GetServiceURL()) - settingsResponse, _, err := configurationAggregatorClient.ReplaceSettingsWithContext(context, replaceSettingsOptions) - fmt.Println(settingsResponse) if err != nil { tfErr := flex.TerraformErrorf(err, fmt.Sprintf("ReplaceSettingsWithContext failed: %s", err.Error()), "ibm_config_aggregator_settings", "create") log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) @@ -180,10 +176,6 @@ func resourceIbmConfigAggregatorSettingsRead(context context.Context, d *schema. return diag.FromErr(err) } settingsResponse, response, err := configurationAggregatorClient.GetSettingsWithContext(context, getSettingsOptions) - fmt.Println("^The Settings Response^") - fmt.Println(settingsResponse) - fmt.Println(response) - fmt.Println(err) if err != nil { if response != nil && response.StatusCode == 404 { d.SetId("") diff --git a/website/docs/d/config_aggregator_configurations.html.markdown b/website/docs/d/config_aggregator_configurations.html.markdown index fb8ab90fc5..6d7a898637 100644 --- a/website/docs/d/config_aggregator_configurations.html.markdown +++ b/website/docs/d/config_aggregator_configurations.html.markdown @@ -43,7 +43,7 @@ After your data source is created, you can read values from the following attrib * `configs` - (List) Array of resource configurations. * Constraints: The maximum length is `100` items. The minimum length is `0` items. Nested schema for **configs**: - * `about` - (List) The basic metadata fetched from the query API. + * `about` - (Map) The basic metadata fetched from the query API. Nested schema for **about**: * `account_id` - (String) The account ID in which the resource exists. * Constraints: The maximum length is `32` characters. The minimum length is `0` characters. The value must match regular expression `/^[a-zA-Z0-9-]*$/`. @@ -64,7 +64,7 @@ Nested schema for **configs**: Nested schema for **tags**: * `tag` - (String) The name of the tag. * Constraints: The maximum length is `32` characters. The minimum length is `0` characters. The value must match regular expression `/^[a-zA-Z0-9-]*$/`. - * `config` - (List) The configuration of the resource. + * `config` - (String) The configuration of the resource. Nested schema for **config**: * `prev` - (List) The reference to the previous page of entries. Nested schema for **prev**: