|
| 1 | +######################################################################################################################## |
| 2 | +# Resource group |
| 3 | +######################################################################################################################## |
| 4 | + |
| 5 | +module "resource_group" { |
| 6 | + source = "terraform-ibm-modules/resource-group/ibm" |
| 7 | + version = "1.1.6" |
| 8 | + resource_group_name = var.resource_group == null ? "${var.prefix}-rg" : null |
| 9 | + existing_resource_group_name = var.resource_group |
| 10 | +} |
| 11 | + |
| 12 | +######################################################################################################################## |
| 13 | +# SCC Workload Protection |
| 14 | +######################################################################################################################## |
| 15 | + |
| 16 | +# Create SCC Workload Protection instance |
| 17 | +module "scc_wp" { |
| 18 | + source = "../.." |
| 19 | + name = var.prefix |
| 20 | + region = var.region |
| 21 | + resource_group_id = module.resource_group.resource_group_id |
| 22 | + resource_tags = var.resource_tags |
| 23 | + access_tags = var.access_tags |
| 24 | + scc_wp_service_plan = "graduated-tier" |
| 25 | +} |
| 26 | + |
| 27 | +# Create Trusted profile for SCC Workload Protection instance |
| 28 | +module "trusted_profile_scc_wp" { |
| 29 | + source = "terraform-ibm-modules/trusted-profile/ibm" |
| 30 | + version = "2.1.0" |
| 31 | + trusted_profile_name = "${var.prefix}-scc-wp-profile" |
| 32 | + trusted_profile_description = "Trusted Profile for SCC-WP to access App Config and enterprise" |
| 33 | + |
| 34 | + trusted_profile_identity = { |
| 35 | + identifier = module.scc_wp.crn |
| 36 | + identity_type = "crn" |
| 37 | + type = "crn" |
| 38 | + } |
| 39 | + |
| 40 | + trusted_profile_policies = [ |
| 41 | + { |
| 42 | + roles = ["Viewer", "Service Configuration Reader", "Manager"] |
| 43 | + resources = [{ |
| 44 | + service = "apprapp" |
| 45 | + }] |
| 46 | + description = "App Config access" |
| 47 | + }, |
| 48 | + { |
| 49 | + roles = ["Viewer", "Usage Report Viewer"] |
| 50 | + resources = [{ |
| 51 | + service = "enterprise" |
| 52 | + }] |
| 53 | + description = "Enterprise access" |
| 54 | + } |
| 55 | + ] |
| 56 | + |
| 57 | + trusted_profile_links = [{ |
| 58 | + cr_type = "VSI" |
| 59 | + links = [{ |
| 60 | + crn = module.scc_wp.crn |
| 61 | + }] |
| 62 | + }] |
| 63 | +} |
| 64 | + |
| 65 | +######################################################################################################################## |
| 66 | +# App Config |
| 67 | +######################################################################################################################## |
| 68 | + |
| 69 | +# Create new App Config instance |
| 70 | +module "app_config" { |
| 71 | + source = "terraform-ibm-modules/app-configuration/ibm" |
| 72 | + version = "1.3.0" |
| 73 | + region = var.region |
| 74 | + resource_group_id = module.resource_group.resource_group_id |
| 75 | + app_config_name = "${var.prefix}-app-config" |
| 76 | + app_config_tags = var.resource_tags |
| 77 | +} |
| 78 | + |
| 79 | +# Create trusted profile for App Config instance |
| 80 | +module "trusted_profile_app_config_general" { |
| 81 | + source = "terraform-ibm-modules/trusted-profile/ibm" |
| 82 | + version = "2.1.0" |
| 83 | + trusted_profile_name = "${var.prefix}-app-config-general-profile" |
| 84 | + trusted_profile_description = "Trusted Profile for App Config general permissions" |
| 85 | + |
| 86 | + trusted_profile_identity = { |
| 87 | + identifier = module.app_config.app_config_crn |
| 88 | + identity_type = "crn" |
| 89 | + type = "crn" |
| 90 | + } |
| 91 | + |
| 92 | + trusted_profile_policies = [ |
| 93 | + { |
| 94 | + roles = ["Viewer", "Service Configuration Reader"] |
| 95 | + account_management = true |
| 96 | + description = "All Account Management Services" |
| 97 | + }, |
| 98 | + { |
| 99 | + roles = ["Viewer", "Service Configuration Reader", "Reader"] |
| 100 | + resource_attributes = [{ |
| 101 | + name = "serviceType" |
| 102 | + value = "service" |
| 103 | + operator = "stringEquals" |
| 104 | + }] |
| 105 | + description = "All Identity and Access enabled services" |
| 106 | + } |
| 107 | + ] |
| 108 | + |
| 109 | + trusted_profile_links = [{ |
| 110 | + cr_type = "VSI" |
| 111 | + links = [{ |
| 112 | + crn = module.app_config.app_config_crn |
| 113 | + }] |
| 114 | + }] |
| 115 | +} |
| 116 | + |
| 117 | +# Creates the custom role inline |
| 118 | +# This role, "Template Assignment Reader", is used in the trusted profile |
| 119 | +# to grant permission to read IAM template assignments. It is required |
| 120 | +# by the App Config enterprise-level trusted profile to manage IAM templates. |
| 121 | +resource "ibm_iam_custom_role" "template_assignment_reader" { |
| 122 | + name = "TemplateAssignmentReader" |
| 123 | + service = "iam-identity" |
| 124 | + display_name = "Template Assignment Reader" |
| 125 | + description = "Custom role to allow reading template assignments" |
| 126 | + actions = ["iam-identity.profile-assignment.read"] |
| 127 | +} |
| 128 | + |
| 129 | +# Trusted Profile for App Config enterprise-level permissions |
| 130 | +module "trusted_profile_app_config_enterprise" { |
| 131 | + source = "terraform-ibm-modules/trusted-profile/ibm" |
| 132 | + version = "2.1.0" |
| 133 | + trusted_profile_name = "app-config-enterprise-profile" |
| 134 | + trusted_profile_description = "Trusted Profile for App Config to manage IAM templates" |
| 135 | + |
| 136 | + trusted_profile_identity = { |
| 137 | + identifier = module.app_config.app_config_crn |
| 138 | + identity_type = "crn" |
| 139 | + type = "crn" |
| 140 | + } |
| 141 | + |
| 142 | + trusted_profile_policies = [ |
| 143 | + { |
| 144 | + roles = ["Viewer", "Template Assignment Reader"] |
| 145 | + resource_attributes = [{ |
| 146 | + name = "service_group_id" |
| 147 | + value = "IAM" |
| 148 | + operator = "stringEquals" |
| 149 | + }] |
| 150 | + description = "IAM access with custom role" |
| 151 | + }, |
| 152 | + { |
| 153 | + roles = ["Viewer"] |
| 154 | + resources = [{ |
| 155 | + service = "enterprise" |
| 156 | + }] |
| 157 | + description = "Enterprise access" |
| 158 | + } |
| 159 | + ] |
| 160 | + |
| 161 | + trusted_profile_links = [{ |
| 162 | + cr_type = "VSI" |
| 163 | + links = [{ |
| 164 | + crn = module.app_config.app_config_crn |
| 165 | + }] |
| 166 | + }] |
| 167 | +} |
| 168 | + |
| 169 | +# Enable the config aggregator |
| 170 | +resource "ibm_config_aggregator_settings" "scc_wp_aggregator" { |
| 171 | + instance_id = module.app_config.app_config_guid |
| 172 | + region = var.region |
| 173 | + resource_collection_enabled = true |
| 174 | + resource_collection_regions = ["all"] |
| 175 | + trusted_profile_id = module.trusted_profile_app_config_general.profile_id |
| 176 | + |
| 177 | + additional_scope { |
| 178 | + type = "Enterprise" |
| 179 | + enterprise_id = var.enterprise_id |
| 180 | + |
| 181 | + profile_template { |
| 182 | + id = module.trusted_profile_template.trusted_profile_template_id |
| 183 | + trusted_profile_id = module.trusted_profile_app_config_enterprise.profile_id |
| 184 | + } |
| 185 | + } |
| 186 | +} |
| 187 | + |
| 188 | +######################################################################################################################## |
| 189 | +# Trusted profile template |
| 190 | +######################################################################################################################## |
| 191 | + |
| 192 | +module "trusted_profile_template" { |
| 193 | + source = "terraform-ibm-modules/trusted-profile/ibm//modules/trusted-profile-template" |
| 194 | + version = "2.1.0" |
| 195 | + template_name = "Trusted Profile Template for SCC-WP-${var.prefix}" |
| 196 | + template_description = "IAM trusted profile template to onboard accounts for CSPM" |
| 197 | + profile_name = "Trusted Profile for IBM Cloud CSPM in SCC-WP" |
| 198 | + profile_description = "Template profile used to onboard child accounts" |
| 199 | + identity_crn = module.app_config.app_config_crn |
| 200 | + onboard_all_account_groups = true |
| 201 | + |
| 202 | + policy_templates = [ |
| 203 | + { |
| 204 | + name = "identity-access" |
| 205 | + description = "Policy template for identity services" |
| 206 | + roles = ["Viewer", "Reader"] |
| 207 | + service = "service" |
| 208 | + }, |
| 209 | + { |
| 210 | + name = "platform-access" |
| 211 | + description = "Policy template for platform services" |
| 212 | + roles = ["Viewer", "Service Configuration Reader"] |
| 213 | + service = "platform_service" |
| 214 | + } |
| 215 | + ] |
| 216 | +} |
0 commit comments