|
@@ -9,24 +9,28 @@ data "aws_kms_key" "ebs-key" {
|
|
}
|
|
}
|
|
|
|
|
|
resource "aws_network_interface" "instance" {
|
|
resource "aws_network_interface" "instance" {
|
|
- subnet_id = var.subnets[0]
|
|
|
|
|
|
+ count = var.keycloak_instance_count
|
|
|
|
+ subnet_id = var.public_subnets[count.index % 3]
|
|
security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.instance.id ]
|
|
security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.instance.id ]
|
|
- description = var.instance_name
|
|
|
|
- tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
|
|
|
+ description = "keycloak-${count.index}"
|
|
|
|
+ tags = merge(var.standard_tags, var.tags, { Name = "keycloak-${count.index}" })
|
|
}
|
|
}
|
|
|
|
|
|
resource "aws_eip" "instance" {
|
|
resource "aws_eip" "instance" {
|
|
|
|
+ count = var.keycloak_instance_count
|
|
vpc = true
|
|
vpc = true
|
|
- tags = merge(var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
|
|
|
+ tags = merge(var.standard_tags, var.tags, { Name = "keycloak-${count.index}" })
|
|
}
|
|
}
|
|
|
|
|
|
resource "aws_eip_association" "instance" {
|
|
resource "aws_eip_association" "instance" {
|
|
- network_interface_id = aws_network_interface.instance.id
|
|
|
|
- allocation_id = aws_eip.instance.id
|
|
|
|
|
|
+ count = var.keycloak_instance_count
|
|
|
|
+ network_interface_id = aws_network_interface.instance[count.index].id
|
|
|
|
+ allocation_id = aws_eip.instance[count.index].id
|
|
}
|
|
}
|
|
|
|
|
|
resource "aws_instance" "instance" {
|
|
resource "aws_instance" "instance" {
|
|
- #availability_zone = var.azs[count.index % 2]
|
|
|
|
|
|
+ count = var.keycloak_instance_count
|
|
|
|
+
|
|
tenancy = "default"
|
|
tenancy = "default"
|
|
ebs_optimized = true
|
|
ebs_optimized = true
|
|
disable_api_termination = var.instance_termination_protection
|
|
disable_api_termination = var.instance_termination_protection
|
|
@@ -73,7 +77,6 @@ resource "aws_instance" "instance" {
|
|
encrypted = true
|
|
encrypted = true
|
|
kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
kms_key_id = data.aws_kms_key.ebs-key.arn
|
|
snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdn"].ebs.snapshot_id
|
|
snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdn"].ebs.snapshot_id
|
|
-
|
|
|
|
}
|
|
}
|
|
ebs_block_device {
|
|
ebs_block_device {
|
|
# /var
|
|
# /var
|
|
@@ -123,19 +126,21 @@ resource "aws_instance" "instance" {
|
|
|
|
|
|
network_interface {
|
|
network_interface {
|
|
device_index = 0
|
|
device_index = 0
|
|
- network_interface_id = aws_network_interface.instance.id
|
|
|
|
|
|
+ network_interface_id = aws_network_interface.instance[count.index].id
|
|
}
|
|
}
|
|
|
|
|
|
- user_data = data.template_cloudinit_config.cloud_init_config.rendered
|
|
|
|
- tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
|
- volume_tags = merge( var.standard_tags, var.tags, { Name = var.instance_name })
|
|
|
|
|
|
+ user_data = data.template_cloudinit_config.cloud_init_config[count.index].rendered
|
|
|
|
+ tags = merge( var.standard_tags, var.tags, { Name = "keycloak-${count.index}" })
|
|
|
|
+ volume_tags = merge( var.standard_tags, var.tags, { Name = "keycloak-${count.index}" })
|
|
}
|
|
}
|
|
|
|
|
|
module "private_dns_record" {
|
|
module "private_dns_record" {
|
|
|
|
+ count = var.keycloak_instance_count
|
|
|
|
+
|
|
source = "../../submodules/dns/private_A_record"
|
|
source = "../../submodules/dns/private_A_record"
|
|
|
|
|
|
- name = var.instance_name
|
|
|
|
- ip_addresses = [ aws_instance.instance.private_ip ]
|
|
|
|
|
|
+ name = "keycloak-${count.index}"
|
|
|
|
+ ip_addresses = [ aws_instance.instance[count.index].private_ip ]
|
|
dns_info = var.dns_info
|
|
dns_info = var.dns_info
|
|
reverse_enabled = var.reverse_enabled
|
|
reverse_enabled = var.reverse_enabled
|
|
|
|
|
|
@@ -144,26 +149,28 @@ module "private_dns_record" {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-module "public_dns_record" {
|
|
|
|
- source = "../../submodules/dns/public_A_record"
|
|
|
|
-
|
|
|
|
- name = var.instance_name
|
|
|
|
- ip_addresses = [ aws_eip.instance.public_ip ]
|
|
|
|
- dns_info = var.dns_info
|
|
|
|
-
|
|
|
|
- providers = {
|
|
|
|
- aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+#module "public_dns_record" {
|
|
|
|
+# source = "../../submodules/dns/public_A_record"
|
|
|
|
+#
|
|
|
|
+# name = var.instance_name
|
|
|
|
+# ip_addresses = [ aws_eip.instance.public_ip ]
|
|
|
|
+# dns_info = var.dns_info
|
|
|
|
+#
|
|
|
|
+# providers = {
|
|
|
|
+# aws.mdr-common-services-commercial = aws.mdr-common-services-commercial
|
|
|
|
+# }
|
|
|
|
+#}
|
|
|
|
|
|
#The Cloud init data is to prepare the instance for use.
|
|
#The Cloud init data is to prepare the instance for use.
|
|
data "template_file" "cloud_init" {
|
|
data "template_file" "cloud_init" {
|
|
|
|
+ count = var.keycloak_instance_count
|
|
|
|
+
|
|
# Should these be in a common directory? I suspect they'd be reusable
|
|
# Should these be in a common directory? I suspect they'd be reusable
|
|
template = file("${path.module}/cloud-init/cloud-init.tpl")
|
|
template = file("${path.module}/cloud-init/cloud-init.tpl")
|
|
|
|
|
|
vars = {
|
|
vars = {
|
|
- hostname = var.instance_name
|
|
|
|
- fqdn = "${var.instance_name}.${var.dns_info["private"]["zone"]}"
|
|
|
|
|
|
+ hostname = "keycloak-${count.index}"
|
|
|
|
+ fqdn = "keycloak-${count.index}.${var.dns_info["private"]["zone"]}"
|
|
environment = var.environment
|
|
environment = var.environment
|
|
salt_master = var.salt_master
|
|
salt_master = var.salt_master
|
|
proxy = var.proxy
|
|
proxy = var.proxy
|
|
@@ -176,6 +183,7 @@ data "template_file" "cloud_init" {
|
|
# Render a multi-part cloud-init config making use of the part
|
|
# Render a multi-part cloud-init config making use of the part
|
|
# above, and other source files
|
|
# above, and other source files
|
|
data "template_cloudinit_config" "cloud_init_config" {
|
|
data "template_cloudinit_config" "cloud_init_config" {
|
|
|
|
+ count = var.keycloak_instance_count
|
|
gzip = true
|
|
gzip = true
|
|
base64_encode = true
|
|
base64_encode = true
|
|
|
|
|
|
@@ -183,6 +191,6 @@ data "template_cloudinit_config" "cloud_init_config" {
|
|
part {
|
|
part {
|
|
filename = "init.cfg"
|
|
filename = "init.cfg"
|
|
content_type = "text/cloud-config"
|
|
content_type = "text/cloud-config"
|
|
- content = data.template_file.cloud_init.rendered
|
|
|
|
|
|
+ content = data.template_file.cloud_init[count.index].rendered
|
|
}
|
|
}
|
|
}
|
|
}
|