Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix #5723

Merged
merged 3 commits into from
Oct 17, 2024
Merged

bug fix #5723

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with Typemap then we have limitation from Terraform only can hold only string type. If you have combination of multiple types (string ,int, bool) then this will not be compatible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All fields of this attribute are of type string so there is no modification required.

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,16 @@ 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
}
fmt.Println(string(jsonData))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this fmt stmt

return string(jsonData), nil
}
Loading