Skip to content

Commit 1defaa0

Browse files
authored
feat: add support for config aggregator and related trusted profiles (#214)
1 parent 8841a91 commit 1defaa0

File tree

16 files changed

+295
-32
lines changed

16 files changed

+295
-32
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ https://terraform-ibm-modules.github.io/documentation/#/implementation-guideline
2121
## Overview
2222
* [terraform-ibm-app-configuration](#terraform-ibm-app-configuration)
2323
* [Examples](./examples)
24+
* [Advanced example](./examples/advanced)
2425
* [Basic example](./examples/basic)
25-
* [Complete example](./examples/complete)
2626
* [Contributing](#contributing)
2727
<!-- END OVERVIEW HOOK -->
2828

@@ -79,19 +79,24 @@ For more information on access and permissions, see <https://cloud.ibm.com/docs/
7979
| Name | Version |
8080
|------|---------|
8181
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
82-
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.65.0, < 2.0.0 |
82+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.76.1, < 2.0.0 |
8383

8484
### Modules
8585

8686
| Name | Source | Version |
8787
|------|--------|---------|
8888
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module | 1.28.0 |
89+
| <a name="module_config_aggregator_trusted_profile"></a> [config\_aggregator\_trusted\_profile](#module\_config\_aggregator\_trusted\_profile) | terraform-ibm-modules/trusted-profile/ibm | 2.1.1 |
90+
| <a name="module_config_aggregator_trusted_profile_enterprise"></a> [config\_aggregator\_trusted\_profile\_enterprise](#module\_config\_aggregator\_trusted\_profile\_enterprise) | terraform-ibm-modules/trusted-profile/ibm | 2.1.1 |
91+
| <a name="module_config_aggregator_trusted_profile_template"></a> [config\_aggregator\_trusted\_profile\_template](#module\_config\_aggregator\_trusted\_profile\_template) | terraform-ibm-modules/trusted-profile/ibm//modules/trusted-profile-template | 2.2.0 |
8992

9093
### Resources
9194

9295
| Name | Type |
9396
|------|------|
9497
| [ibm_app_config_collection.collections](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/app_config_collection) | resource |
98+
| [ibm_config_aggregator_settings.config_aggregator_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/config_aggregator_settings) | resource |
99+
| [ibm_iam_custom_role.template_assignment_reader](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_custom_role) | resource |
95100
| [ibm_resource_instance.app_config](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
96101

97102
### Inputs
@@ -104,6 +109,13 @@ For more information on access and permissions, see <https://cloud.ibm.com/docs/
104109
| <a name="input_app_config_service_endpoints"></a> [app\_config\_service\_endpoints](#input\_app\_config\_service\_endpoints) | Service Endpoints for the App Configuration service instance, valid endpoints are public or public-and-private. | `string` | `"public-and-private"` | no |
105110
| <a name="input_app_config_tags"></a> [app\_config\_tags](#input\_app\_config\_tags) | Optional list of tags to be added to the App Config instance. | `list(string)` | `[]` | no |
106111
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restriction rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> tags = optional(list(object({<br/> name = string<br/> value = string<br/> })), [])<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> }))</pre> | `[]` | no |
112+
| <a name="input_config_aggregator_enterprise_account_group_ids_to_assign"></a> [config\_aggregator\_enterprise\_account\_group\_ids\_to\_assign](#input\_config\_aggregator\_enterprise\_account\_group\_ids\_to\_assign) | A list of enterprise account group IDs to assign the trusted profile template to in order for the accounts to be scanned. Supports passing the string 'all' in the list to assign to all account groups. Only applies if `enable_config_aggregator` is true and a value is being passed for `config_aggregator_enterprise_id`. | `list(string)` | <pre>[<br/> "all"<br/>]</pre> | no |
113+
| <a name="input_config_aggregator_enterprise_id"></a> [config\_aggregator\_enterprise\_id](#input\_config\_aggregator\_enterprise\_id) | If the account is an enterprise account, this value should be set to the enterprise ID (NOTE: This is different to the account ID). | `string` | `null` | no |
114+
| <a name="input_config_aggregator_enterprise_trusted_profile_name"></a> [config\_aggregator\_enterprise\_trusted\_profile\_name](#input\_config\_aggregator\_enterprise\_trusted\_profile\_name) | The name to give the enterprise viewer trusted profile with that will be created if `enable_config_aggregator` is set to `true` and a value is passed for `config_aggregator_enterprise_id`. | `string` | `"config-aggregator-enterprise-trusted-profile"` | no |
115+
| <a name="input_config_aggregator_enterprise_trusted_profile_template_name"></a> [config\_aggregator\_enterprise\_trusted\_profile\_template\_name](#input\_config\_aggregator\_enterprise\_trusted\_profile\_template\_name) | The name to give the trusted profile template that will be created if `enable_config_aggregator` is set to `true` and a value is passed for `config_aggregator_enterprise_id`. | `string` | `"config-aggregator-trusted-profile-template"` | no |
116+
| <a name="input_config_aggregator_resource_collection_regions"></a> [config\_aggregator\_resource\_collection\_regions](#input\_config\_aggregator\_resource\_collection\_regions) | From which region do you want to collect configuration data? Only applies if `enable_config_aggregator` is set to true. | `list(string)` | <pre>[<br/> "all"<br/>]</pre> | no |
117+
| <a name="input_config_aggregator_trusted_profile_name"></a> [config\_aggregator\_trusted\_profile\_name](#input\_config\_aggregator\_trusted\_profile\_name) | The name to give the trusted profile that will be created if `enable_config_aggregator` is set to `true`. | `string` | `"config-aggregator-trusted-profile"` | no |
118+
| <a name="input_enable_config_aggregator"></a> [enable\_config\_aggregator](#input\_enable\_config\_aggregator) | Set to true to enable configuration aggregator. By setting to true a trusted profile will be created with the required access to record configuration data from all resources across regions in your account. [Learn more](https://cloud.ibm.com/docs/app-configuration?topic=app-configuration-ac-configuration-aggregator). | `bool` | `false` | no |
107119
| <a name="input_region"></a> [region](#input\_region) | The region to provision the App Configuration service, valid regions are us-south, us-east, eu-gb, and au-syd. | `string` | `"us-south"` | no |
108120
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where resources will be provisioned. | `string` | n/a | yes |
109121

@@ -116,6 +128,9 @@ For more information on access and permissions, see <https://cloud.ibm.com/docs/
116128
| <a name="output_app_config_crn"></a> [app\_config\_crn](#output\_app\_config\_crn) | CRN of the App Configuration instance |
117129
| <a name="output_app_config_guid"></a> [app\_config\_guid](#output\_app\_config\_guid) | GUID of the App Configuration instance |
118130
| <a name="output_app_config_id"></a> [app\_config\_id](#output\_app\_config\_id) | ID of the App Configuration instance |
131+
| <a name="output_config_aggregator_enterprise_trusted_profile_id"></a> [config\_aggregator\_enterprise\_trusted\_profile\_id](#output\_config\_aggregator\_enterprise\_trusted\_profile\_id) | ID of the config aggregator trusted profile for enterprise access |
132+
| <a name="output_config_aggregator_enterprise_trusted_profile_template_id"></a> [config\_aggregator\_enterprise\_trusted\_profile\_template\_id](#output\_config\_aggregator\_enterprise\_trusted\_profile\_template\_id) | ID of the config aggregator trusted profile enterprise template ID |
133+
| <a name="output_config_aggregator_trusted_profile_id"></a> [config\_aggregator\_trusted\_profile\_id](#output\_config\_aggregator\_trusted\_profile\_id) | ID of the config aggregator trusted profile |
119134
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
120135

121136
<!-- Leave this section as is so that your module has a link to local development environment set up steps for contributors to follow -->

cra-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# More info about this file at https://github.com/terraform-ibm-modules/common-pipeline-assets/blob/main/.github/workflows/terraform-test-pipeline.md#cra-config-yaml
22
version: "v1"
33
CRA_TARGETS:
4-
- CRA_TARGET: "examples/complete" # Target directory for CRA scan. If not provided, the CRA Scan will not be run.
4+
- CRA_TARGET: "examples/advanced" # Target directory for CRA scan. If not provided, the CRA Scan will not be run.
55
CRA_IGNORE_RULES_FILE: "cra-tf-validate-ignore-rules.json" # CRA Ignore file to use. If not provided, it checks the repo root directory for `cra-tf-validate-ignore-rules.json`
66
PROFILE_ID: "fe96bd4d-9b37-40f2-b39f-a62760e326a3" # SCC profile ID (currently set to 'IBM Cloud Framework for Financial Services' '1.7.0' profile).

examples/advanced/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Advanced example
2+
3+
<!-- There is a pre-commit hook that will take the title of each example add include it in the repos main README.md -->
4+
<!-- Add text below should describe exactly what resources are provisioned / configured by the example -->
5+
6+
An end-to-end example that will provision the following:
7+
8+
- A new resource group if one is not passed in.
9+
- A new App Configuration instance.
10+
- A new collection within the App Configuration instance.
11+
- Configuration aggregator ([learn more](https://cloud.ibm.com/docs/app-configuration?topic=app-configuration-ac-configuration-aggregator))
12+
- A simple VPC
13+
- A CBR zone for the VPC
14+
- A CBR rule to only allow the App Configuration instance to be accessed from within the VPC zone over private endpoint

examples/complete/main.tf renamed to examples/advanced/main.tf

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
##############################################################################
2-
# Complete example
3-
##############################################################################
4-
51
########################################################################################################################
62
# Resource group
73
########################################################################################################################
@@ -33,6 +29,7 @@ resource "ibm_is_vpc" "example_vpc" {
3329
##############################################################################
3430
# Create CBR Zone
3531
##############################################################################
32+
3633
module "cbr_zone" {
3734
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
3835
version = "1.28.0"
@@ -50,20 +47,19 @@ module "cbr_zone" {
5047
########################################################################################################################
5148

5249
module "app_config" {
53-
source = "../.."
54-
resource_group_id = module.resource_group.resource_group_id
55-
region = var.region
56-
app_config_name = "${var.prefix}-app-config"
57-
app_config_tags = var.resource_tags
58-
50+
source = "../.."
51+
resource_group_id = module.resource_group.resource_group_id
52+
region = var.region
53+
app_config_name = "${var.prefix}-app-config"
54+
app_config_tags = var.resource_tags
55+
enable_config_aggregator = true # See https://cloud.ibm.com/docs/app-configuration?topic=app-configuration-ac-configuration-aggregator
5956
app_config_collections = [
6057
{
6158
name = "${var.prefix}-collection",
6259
collection_id = "${var.prefix}-collection"
6360
description = "Collection for ${var.prefix}"
6461
}
6562
]
66-
6763
cbr_rules = [
6864
{
6965
description = "${var.prefix}-APP-CONF access only from vpc"
File renamed without changes.
File renamed without changes.

examples/complete/variables.tf renamed to examples/advanced/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ variable "region" {
1313
variable "prefix" {
1414
type = string
1515
description = "Prefix to append to all resources created by this example"
16-
default = "complete"
16+
default = "advanced"
1717
}
1818

1919
variable "resource_group" {

examples/complete/version.tf renamed to examples/advanced/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = ">= 1.65.0, < 2.0.0"
9+
version = ">= 1.76.1, < 2.0.0"
1010
}
1111
}
1212
}

examples/basic/version.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = "1.65.0"
9+
version = "1.76.1"
1010
}
1111
}
1212
}

examples/complete/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

main.tf

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ resource "ibm_resource_instance" "app_config" {
1212
tags = var.app_config_tags
1313
}
1414

15+
##############################################################################
16+
# Collections
17+
##############################################################################
18+
1519
locals {
1620
collections_map = {
1721
for obj in var.app_config_collections :
@@ -28,9 +32,161 @@ resource "ibm_app_config_collection" "collections" {
2832
tags = each.value.tags
2933
}
3034

35+
##############################################################################
36+
# Configuration aggregator
37+
##############################################################################
38+
39+
# Create the required Trusted Profile
40+
module "config_aggregator_trusted_profile" {
41+
count = var.enable_config_aggregator ? 1 : 0
42+
source = "terraform-ibm-modules/trusted-profile/ibm"
43+
version = "2.1.1"
44+
trusted_profile_name = var.config_aggregator_trusted_profile_name
45+
trusted_profile_description = "Trusted Profile for App Configuration instance ${ibm_resource_instance.app_config.guid} with required access for configuration aggregator"
46+
trusted_profile_identity = {
47+
identifier = ibm_resource_instance.app_config.crn
48+
identity_type = "crn"
49+
}
50+
trusted_profile_policies = [
51+
{
52+
roles = ["Viewer", "Service Configuration Reader"]
53+
account_management = true
54+
description = "All Account Management Services"
55+
},
56+
{
57+
roles = ["Viewer", "Service Configuration Reader", "Reader"]
58+
resource_attributes = [{
59+
name = "serviceType"
60+
value = "service"
61+
operator = "stringEquals"
62+
}]
63+
description = "All Identity and Access enabled services"
64+
}
65+
]
66+
trusted_profile_links = [{
67+
cr_type = "VSI"
68+
links = [{
69+
crn = ibm_resource_instance.app_config.crn
70+
}]
71+
}]
72+
}
73+
74+
# If enterprise account, create custom role "Template Assignment Reader"
75+
# This role is used in the trusted profile to grant permission to read IAM template assignments.
76+
# It is required by the App Config enterprise-level trusted profile to manage IAM templates."
77+
locals {
78+
custom_role = "Template Assignment Reader"
79+
}
80+
resource "ibm_iam_custom_role" "template_assignment_reader" {
81+
count = var.enable_config_aggregator && var.config_aggregator_enterprise_id != null ? 1 : 0
82+
name = "TemplateAssignmentReader"
83+
service = "iam-identity"
84+
display_name = local.custom_role
85+
description = "Custom role to allow reading IAM template assignments"
86+
actions = ["iam-identity.profile-assignment.read"]
87+
}
88+
89+
# If enterprise account, create trusted profile for App Config enterprise-level permissions
90+
module "config_aggregator_trusted_profile_enterprise" {
91+
count = var.enable_config_aggregator && var.config_aggregator_enterprise_id != null ? 1 : 0
92+
source = "terraform-ibm-modules/trusted-profile/ibm"
93+
version = "2.1.1"
94+
trusted_profile_name = var.config_aggregator_enterprise_trusted_profile_name
95+
trusted_profile_description = "Trusted Profile for App Configuration instance ${ibm_resource_instance.app_config.guid} with required access for configuration aggregator for enterprise accounts"
96+
97+
trusted_profile_identity = {
98+
identifier = ibm_resource_instance.app_config.crn
99+
identity_type = "crn"
100+
}
101+
102+
trusted_profile_policies = [
103+
{
104+
roles = ["Viewer", local.custom_role]
105+
resource_attributes = [{
106+
name = "service_group_id"
107+
value = "IAM"
108+
operator = "stringEquals"
109+
}]
110+
description = "IAM access with custom role"
111+
},
112+
{
113+
roles = ["Viewer"]
114+
resources = [{
115+
service = "enterprise"
116+
}]
117+
description = "Enterprise viewer and template reader access"
118+
}
119+
]
120+
121+
trusted_profile_links = [{
122+
cr_type = "VSI"
123+
links = [{
124+
crn = ibm_resource_instance.app_config.crn
125+
}]
126+
}]
127+
}
128+
129+
# If enterprise account, create trusted profile template
130+
module "config_aggregator_trusted_profile_template" {
131+
count = var.enable_config_aggregator && var.config_aggregator_enterprise_id != null ? 1 : 0
132+
source = "terraform-ibm-modules/trusted-profile/ibm//modules/trusted-profile-template"
133+
version = "2.2.0"
134+
template_name = var.config_aggregator_enterprise_trusted_profile_template_name
135+
template_description = "Trusted Profile template for App Configuration instance ${ibm_resource_instance.app_config.guid} with required access for configuration aggregator"
136+
profile_name = var.config_aggregator_trusted_profile_name
137+
profile_description = "Trusted Profile for App Configuration instance ${ibm_resource_instance.app_config.guid} with required access for configuration aggregator"
138+
identity_crn = ibm_resource_instance.app_config.crn
139+
account_group_ids_to_assign = var.config_aggregator_enterprise_account_group_ids_to_assign
140+
policy_templates = [
141+
{
142+
name = "identity-access"
143+
description = "Policy template for identity services"
144+
roles = ["Viewer", "Reader"]
145+
attributes = [{
146+
key = "serviceType"
147+
value = "service" # assigns access to All Identity and Access enabled services
148+
operator = "stringEquals"
149+
}]
150+
},
151+
{
152+
name = "platform-access"
153+
description = "Policy template for platform services"
154+
roles = ["Viewer", "Service Configuration Reader"]
155+
attributes = [{
156+
key = "serviceType"
157+
value = "platform_service" # assigns access to All Account Management services
158+
operator = "stringEquals"
159+
}]
160+
}
161+
]
162+
}
163+
164+
# Define an aggregation
165+
resource "ibm_config_aggregator_settings" "config_aggregator_settings" {
166+
count = var.enable_config_aggregator ? 1 : 0
167+
instance_id = ibm_resource_instance.app_config.guid
168+
region = ibm_resource_instance.app_config.location
169+
resource_collection_regions = var.config_aggregator_resource_collection_regions
170+
resource_collection_enabled = true
171+
trusted_profile_id = module.config_aggregator_trusted_profile[0].profile_id
172+
173+
dynamic "additional_scope" {
174+
for_each = var.enable_config_aggregator && var.config_aggregator_enterprise_id != null ? [1] : []
175+
content {
176+
type = "Enterprise"
177+
enterprise_id = var.config_aggregator_enterprise_id
178+
profile_template {
179+
id = module.config_aggregator_trusted_profile_template[0].trusted_profile_template_id
180+
trusted_profile_id = module.config_aggregator_trusted_profile_enterprise[0].profile_id
181+
}
182+
}
183+
}
184+
}
185+
31186
##############################################################################
32187
# Context Based Restrictions
33188
##############################################################################
189+
34190
module "cbr_rule" {
35191
count = length(var.cbr_rules) > 0 ? length(var.cbr_rules) : 0
36192
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-rule-module"

0 commit comments

Comments
 (0)