Skip to content

Commit

Permalink
bug fix (#5723)
Browse files Browse the repository at this point in the history
* bug fix

* configs change

* review changes requested
  • Loading branch information
Ramya-c4 authored Oct 17, 2024
1 parent eae525f commit 75a7487
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 96 deletions.
2 changes: 1 addition & 1 deletion examples/ibm-configuration-aggregator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 24 additions & 4 deletions examples/ibm-configuration-aggregator/outputs.tf
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions examples/ibm-configuration-aggregator/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
6 changes: 3 additions & 3 deletions examples/ibm-configuration-aggregator/versions.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package configurationaggregator

import (
"context"
"encoding/json"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -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{},
},
},
},
},
Expand All @@ -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{}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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("")
Expand Down
4 changes: 2 additions & 2 deletions website/docs/d/config_aggregator_configurations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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-]*$/`.
Expand All @@ -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**:
Expand Down

0 comments on commit 75a7487

Please sign in to comment.