Skip to content

Commit a3d30cc

Browse files
authored
Config agg v2 changes (#6218)
* document changes * Update config_aggregator_settings.html.markdown * aggregator changes * Update data_source_ibm_config_aggregator_configurations.go * remove print statements * customer issue changes * address review comments * review comments
1 parent c05e5e9 commit a3d30cc

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

examples/ibm-configuration-aggregator/outputs.tf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ locals {
44
entries = [
55
for config in data.ibm_config_aggregator_configurations.example.configs : {
66
about = {
7-
account_id = config.about.account_id
8-
config_type = config.about.config_type
9-
last_config_refresh_time = config.about.last_config_refresh_time
10-
location = config.about.location
11-
resource_crn = config.about.resource_crn
12-
resource_group_id = config.about.resource_group_id
13-
resource_name = config.about.resource_name
14-
service_name = config.about.service_name
15-
tags={}
7+
account_id = jsondecode(config.about).account_id
8+
config_type = jsondecode(config.about).config_type
9+
last_config_refresh_time = jsondecode(config.about).last_config_refresh_time
10+
location = jsondecode(config.about).location
11+
resource_crn = jsondecode(config.about).resource_crn
12+
resource_group_id = jsondecode(config.about).resource_group_id
13+
resource_name = jsondecode(config.about).resource_name
14+
service_name = jsondecode(config.about).service_name
15+
tags = {}
1616
}
1717
config = jsondecode(config.config)
1818
}
1919
]
2020
}
21-
2221
output "ibm_config_aggregator_configurations" {
2322
value = {
2423
configs=local.entries

ibm/conns/config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,12 +2479,16 @@ func (c *Config) ClientSession() (interface{}, error) {
24792479
}
24802480

24812481
// Construct an instance of the 'Configuration Aggregator' service.
2482-
var configBaseURL string
2483-
configBaseURL = ContructEndpoint(fmt.Sprintf("%s.apprapp", c.Region), cloudEndpoint)
2484-
2482+
configBaseURL := ContructEndpoint(fmt.Sprintf("%s", c.Region), fmt.Sprintf("%s.apprapp.", cloudEndpoint))
2483+
if c.Visibility == "private" || c.Visibility == "public-and-private" {
2484+
configBaseURL = ContructEndpoint(fmt.Sprintf("%s.private", c.Region), fmt.Sprintf("%s.apprapp", cloudEndpoint))
2485+
}
2486+
if fileMap != nil && c.Visibility != "public-and-private" {
2487+
configBaseURL = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_APP_CONFIG_ENDPOINT", c.Region, configBaseURL)
2488+
}
24852489
configurationAggregatorClientOptions := &configurationaggregatorv1.ConfigurationAggregatorV1Options{
24862490
Authenticator: authenticator,
2487-
URL: configBaseURL,
2491+
URL: EnvFallBack([]string{"IBMCLOUD_APP_CONFIG_ENDPOINT"}, configBaseURL),
24882492
}
24892493

24902494
// Construct the service client.

ibm/service/configurationaggregator/data_source_ibm_config_aggregator_configurations.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func dataSourceIbmConfigAggregatorConfigurationsRead(context context.Context, d
215215
d.SetId(dataSourceIbmConfigAggregatorConfigurationsID(d))
216216

217217
mapSlice := []map[string]interface{}{}
218-
for _, modelItem := range allItems {
219-
modelMap, err := DataSourceIbmConfigAggregatorConfigurationsConfigToMap(&modelItem)
218+
for _, model := range allItems {
219+
modelMap, err := DataSourceIbmConfigAggregatorConfigurationsConfigToMap(&model)
220220
if err != nil {
221221
tfErr := flex.TerraformErrorf(err, err.Error(), "(Data) ibm_config_aggregator_configurations", "read")
222222
return tfErr.GetDiag()
@@ -249,18 +249,34 @@ func DataSourceIbmConfigAggregatorConfigurationsPaginatedPreviousToMap(model *co
249249
}
250250

251251
func DataSourceIbmConfigAggregatorConfigurationsConfigToMap(model *configurationaggregatorv1.Config) (map[string]interface{}, error) {
252-
modelMap := make(map[string]interface{})
253-
aboutMap, err := DataSourceIbmConfigAggregatorConfigurationsAboutToMap(model.About)
254-
if err != nil {
255-
return modelMap, err
252+
if model == nil {
253+
return nil, fmt.Errorf("model is nil")
256254
}
257-
modelMap["about"] = aboutMap
258-
configMap, err := DataSourceIbmConfigAggregatorConfigurationsConfigurationToMap(model.Config)
259-
if err != nil {
260-
return modelMap, err
255+
256+
// Convert About struct to JSON string or "{}"
257+
aboutStr := "{}"
258+
if model.About != nil {
259+
bytes, err := json.Marshal(model.About)
260+
if err != nil {
261+
return nil, fmt.Errorf("failed to marshal About: %v", err)
262+
}
263+
aboutStr = string(bytes)
261264
}
262-
modelMap["config"] = configMap
263-
return modelMap, nil
265+
266+
// Convert Config struct to JSON string or "{}"
267+
configStr := "{}"
268+
if model.Config != nil {
269+
bytes, err := json.Marshal(model.Config)
270+
if err != nil {
271+
return nil, fmt.Errorf("failed to marshal Config: %v", err)
272+
}
273+
configStr = string(bytes)
274+
}
275+
276+
return map[string]interface{}{
277+
"about": aboutStr,
278+
"config": configStr,
279+
}, nil
264280
}
265281

266282
func DataSourceIbmConfigAggregatorConfigurationsAboutToMap(model *configurationaggregatorv1.About) (string, error) {
@@ -293,14 +309,21 @@ func DataSourceIbmConfigAggregatorConfigurationsAboutToMap(model *configurationa
293309
// }
294310

295311
func DataSourceIbmConfigAggregatorConfigurationsConfigurationToMap(model *configurationaggregatorv1.Configuration) (string, error) {
296-
checkMap := model.GetProperties()
297-
tryMap := make(map[string]interface{})
298-
for i, v := range checkMap {
299-
tryMap[i] = v
312+
if model == nil {
313+
return "", nil
300314
}
301-
jsonData, err := json.Marshal(tryMap)
302-
if err != nil {
303-
return "", err
315+
316+
if len(model.GetProperties()) != 0 {
317+
checkMap := model.GetProperties()
318+
tryMap := make(map[string]interface{})
319+
for i, v := range checkMap {
320+
tryMap[i] = v
321+
}
322+
jsonData, err := json.Marshal(tryMap)
323+
if err != nil {
324+
return "", err
325+
}
326+
return string(jsonData), nil
304327
}
305-
return string(jsonData), nil
328+
return "", nil
306329
}

ibm/service/configurationaggregator/utils.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ func getConfigurationInstanceRegion(originalClient *configurationaggregatorv1.Co
2626
}
2727

2828
func getClientWithConfigurationInstanceEndpoint(originalClient *configurationaggregatorv1.ConfigurationAggregatorV1, instanceId string, region string) *configurationaggregatorv1.ConfigurationAggregatorV1 {
29-
// build the api endpoint
3029
domain := cloudEndpoint
30+
prefix := region
31+
baseUrl := originalClient.GetServiceURL()
3132
if strings.Contains(os.Getenv("IBMCLOUD_IAM_API_ENDPOINT"), "test") {
3233
domain = testCloudEndpoint
3334
}
34-
endpoint := fmt.Sprintf("https://%s.apprapp.%s/apprapp/config_aggregator/v1/instances/%s", region, domain, instanceId)
35+
if strings.Contains(baseUrl, "private") {
36+
prefix = fmt.Sprintf("private.%s", region)
37+
}
38+
endpoint := fmt.Sprintf("https://%s.apprapp.%s/apprapp/config_aggregator/v1/instances/%s", prefix, domain, instanceId)
3539

3640
// clone the client and set endpoint
3741
newClient := &configurationaggregatorv1.ConfigurationAggregatorV1{
@@ -42,7 +46,6 @@ func getClientWithConfigurationInstanceEndpoint(originalClient *configurationagg
4246

4347
return newClient
4448
}
45-
4649
func AddConfigurationAggregatorInstanceFields(resource *schema.Resource) *schema.Resource {
4750
resource.Schema["instance_id"] = &schema.Schema{
4851
Type: schema.TypeString,

website/docs/guides/custom-service-endpoints.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ provider "ibm" {
5353
|Internet Services|IBMCLOUD_CIS_API_ENDPOINT|
5454
|Cloud Shell|IBMCLOUD_CLOUD_SHELL_API_ENDPOINT|
5555
|Compilance (Posture Management)|IBMCLOUD_COMPLIANCE_API_ENDPOINT|
56+
|Configuration Aggregator|IBMCLOUD_APP_CONFIG_ENDPOINT|
5657
|Container Registry|IBMCLOUD_CR_API_ENDPOINT|
5758
|Cloud Logs | IBMCLOUD_LOGS_API_ENDPOINT |
5859
|Kubernetes Service|IBMCLOUD_CS_API_ENDPOINT|

website/docs/r/config_aggregator_settings.html.markdown

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Create, update, and delete config_aggregator_settingss with this resource.
1414

1515
```hcl
1616
resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance" {
17-
instance_id=var.instance_id
18-
region=var.region
17+
instance_id = var.instance_id
18+
region = var.region
1919
additional_scope {
2020
type = "Enterprise"
2121
enterprise_id = "enterprise_id"
@@ -24,7 +24,7 @@ resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance"
2424
trusted_profile_id = "Profile-6bb60124-8fc3-4d18-b63d-0b99560865d3"
2525
}
2626
}
27-
resource_collection_regions = us-south
27+
resource_collection_regions = ["all"]
2828
resource_collection_enabled = true
2929
trusted_profile_id = "Profile-1260aec2-f2fc-44e2-8697-2cc15a447560"
3030
}
@@ -34,7 +34,7 @@ resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance"
3434

3535
You can specify the following arguments for this resource.
3636
* `instance_id` - (Required, Forces new resource, String) The GUID of the Configuration Aggregator instance.
37-
* `resource_collection_regions` - (Optional, Forces new resource, String) The region of the Configuration Aggregator instance. If not provided defaults to the region defined in the IBM provider configuration.
37+
* `region` - (Optional, Forces new resource, List) The region of the Configuration Aggregator instance. If not provided defaults to the region defined in the IBM provider configuration.
3838
* `additional_scope` - (Optional, Forces new resource, List) The additional scope that enables resource collection for Enterprise acccounts.
3939
* Constraints: The maximum length is `10` items. The minimum length is `0` items.
4040
Nested schema for **additional_scope**:
@@ -48,10 +48,10 @@ Nested schema for **additional_scope**:
4848
* Constraints: The maximum length is `44` characters. The minimum length is `44` characters. The value must match regular expression `/^[a-zA-Z0-9-]*$/`.
4949
* `type` - (Optional, String) The type of scope. Currently allowed value is Enterprise.
5050
* Constraints: The maximum length is `64` characters. The minimum length is `0` characters. The value must match regular expression `/[a-zA-Z0-9]/`.
51-
* `regions` - (Optional, Forces new resource, List) The list of regions across which the resource collection is enabled.
51+
* `resource_collection_regions` - (Required,List) Regions for which the resource collection is enabled.
5252
* Constraints: The list items must match regular expression `/^[a-zA-Z0-9-]*$/`. The maximum length is `10` items. The minimum length is `0` items.
53-
* `resource_collection_enabled` - (Optional, Forces new resource, Boolean) The field denoting if the resource collection is enabled.
54-
* `trusted_profile_id` - (Optional, Forces new resource, String) The trusted profile id that provides Reader access to the App Configuration instance to collect resource metadata.
53+
* `resource_collection_enabled` - (Required, Boolean) The field denoting if the resource collection is enabled.
54+
* `trusted_profile_id` - (Required, String) The trusted profile id that provides Reader access to the App Configuration instance to collect resource metadata.
5555
* Constraints: The maximum length is `44` characters. The minimum length is `44` characters. The value must match regular expression `/^[a-zA-Z0-9-]*$/`.
5656

5757
## Attribute Reference

0 commit comments

Comments
 (0)