|
| 1 | +############################################################################## |
| 2 | +# Resource Group |
| 3 | +############################################################################## |
| 4 | + |
| 5 | +module "resource_group" { |
| 6 | + source = "terraform-ibm-modules/resource-group/ibm" |
| 7 | + version = "1.1.4" |
| 8 | + # if an existing resource group is not set (null) create a new one using prefix |
| 9 | + resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null |
| 10 | + existing_resource_group_name = var.resource_group |
| 11 | +} |
| 12 | + |
| 13 | +############################################################################## |
| 14 | +# Get Cloud Account ID |
| 15 | +############################################################################## |
| 16 | + |
| 17 | +data "ibm_iam_account_settings" "iam_account_settings" { |
| 18 | +} |
| 19 | + |
| 20 | +############################################################################## |
| 21 | +# VPC |
| 22 | +############################################################################## |
| 23 | +resource "ibm_is_vpc" "example_vpc" { |
| 24 | + name = "${var.prefix}-vpc" |
| 25 | + resource_group = module.resource_group.resource_group_id |
| 26 | + tags = var.resource_tags |
| 27 | +} |
| 28 | + |
| 29 | +resource "ibm_is_subnet" "testacc_subnet" { |
| 30 | + name = "${var.prefix}-subnet" |
| 31 | + vpc = ibm_is_vpc.example_vpc.id |
| 32 | + zone = "${var.region}-1" |
| 33 | + total_ipv4_address_count = 256 |
| 34 | + resource_group = module.resource_group.resource_group_id |
| 35 | +} |
| 36 | + |
| 37 | +############################################################################## |
| 38 | +# Create CBR Zone |
| 39 | +############################################################################## |
| 40 | +module "cbr_zone" { |
| 41 | + source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module" |
| 42 | + version = "1.17.1" |
| 43 | + name = "${var.prefix}-VPC-network-zone" |
| 44 | + zone_description = "CBR Network zone containing VPC" |
| 45 | + account_id = data.ibm_iam_account_settings.iam_account_settings.account_id |
| 46 | + addresses = [{ |
| 47 | + type = "vpc", # to bind a specific vpc to the zone |
| 48 | + value = ibm_is_vpc.example_vpc.crn, |
| 49 | + }] |
| 50 | +} |
| 51 | + |
| 52 | +############################################################################## |
| 53 | +# ICD elasticsearch database |
| 54 | +############################################################################## |
| 55 | + |
| 56 | +module "elasticsearch" { |
| 57 | + source = "../../modules/fscloud" |
| 58 | + resource_group_id = module.resource_group.resource_group_id |
| 59 | + name = "${var.prefix}-elasticsearch" |
| 60 | + region = var.region |
| 61 | + tags = var.resource_tags |
| 62 | + access_tags = var.access_tags |
| 63 | + kms_key_crn = var.kms_key_crn |
| 64 | + existing_kms_instance_guid = var.existing_kms_instance_guid |
| 65 | + elasticsearch_version = var.elasticsearch_version |
| 66 | + service_credential_names = var.service_credential_names |
| 67 | + auto_scaling = var.auto_scaling |
| 68 | + cbr_rules = [ |
| 69 | + { |
| 70 | + description = "${var.prefix}-elasticsearch access only from vpc" |
| 71 | + enforcement_mode = "enabled" |
| 72 | + account_id = data.ibm_iam_account_settings.iam_account_settings.account_id |
| 73 | + rule_contexts = [{ |
| 74 | + attributes = [ |
| 75 | + { |
| 76 | + "name" : "endpointType", |
| 77 | + "value" : "private" |
| 78 | + }, |
| 79 | + { |
| 80 | + name = "networkZoneId" |
| 81 | + value = module.cbr_zone.zone_id |
| 82 | + }] |
| 83 | + }] |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
0 commit comments