Skip to content

Commit

Permalink
Merge pull request #39 from companieshouse/linux-dev/updates
Browse files Browse the repository at this point in the history
added ansible and updated vars
  • Loading branch information
charris-CH authored Dec 11, 2024
2 parents 882454f + 632baea commit d568cea
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
12 changes: 12 additions & 0 deletions groups/linux-dev-01/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ data "vault_generic_secret" "sns_email" {
data "vault_generic_secret" "sns_url" {
path = "/applications/${var.aws_account}-${var.aws_region}/${var.service}/sns/"
}

data "template_file" "userdata" {
template = file("${path.module}/templates/user_data.tpl")

count = var.instance_count

vars = {
ENVIRONMENT = title(var.environment)
APPLICATION_NAME = var.service_subtype
ANSIBLE_INPUTS = jsonencode(merge(local.ansible_inputs, { hostname = format("%s-%02d", var.service_subtype) }))
}
}
39 changes: 21 additions & 18 deletions groups/linux-dev-01/instance.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ resource "aws_instance" "unix_dev_01" {
ServiceSubType = var.service_subtype
Team = var.team
Backup = true
Domain = "${var.environment}.${var.dns_zone_suffix}"
Hostname = "${var.service_subtype}"
}

root_block_device {
Expand All @@ -34,22 +36,23 @@ resource "aws_instance" "unix_dev_01" {

}

# ebs_block_device {
# device_name = var.ebs_device_name
# volume_size = var.data_volume_size_gib
# encrypted = var.encrypt_ebs_block_device
# iops = var.ebs_block_device_iops
# kms_key_id = data.aws_kms_alias.ebs.target_key_arn
# throughput = var.ebs_block_device_throughput
# volume_type = var.ebs_block_device_volume_type
# delete_on_termination = var.ebs_delete_on_termination
# tags = {
# Name = "${local.common_resource_name}-${count.index + 1}-data"
# Environment = var.environment
# Service = var.service
# ServiceSubType = var.service_subtype
# Team = var.team
# Backup = true
# }
#}
ebs_block_device {
device_name = var.ebs_device_name
volume_size = var.data_volume_size_gib
encrypted = var.encrypt_ebs_block_device
iops = var.ebs_block_device_iops
kms_key_id = data.aws_kms_alias.ebs.target_key_arn
throughput = var.ebs_block_device_throughput
volume_type = var.ebs_block_device_volume_type
delete_on_termination = var.ebs_delete_on_termination
tags = {
Name = "${local.common_resource_name}-${count.index + 1}-data"
Environment = var.environment
Service = var.service
ServiceSubType = var.service_subtype
Team = var.team
Backup = true
}
}
user_data = data.template_file.userdata[count.index].rendered
}
12 changes: 12 additions & 0 deletions groups/linux-dev-01/templates/user_data.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/bash
# Redirect the user-data output to the console logs
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

#Restart iscsid to take in the new initiator name.
systemctl restart iscsid

#Run Ansible playbook for deployment using provided inputs
cat <<EOF >inputs.json
${ANSIBLE_INPUTS}
EOF
/usr/local/bin/ansible-playbook /root/deployment.yml -e "@inputs.json"
2 changes: 1 addition & 1 deletion groups/linux-dev-01/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "instance_count" {
variable "root_volume_size" {
type = number
description = "The size of the root volume in gibibytes (GiB)."
default = 20
default = 40
}

variable "encrypt_root_block_device" {
Expand Down

0 comments on commit d568cea

Please sign in to comment.