Skip to content

Commit

Permalink
Merge pull request #8462 from ministryofjustice/TM-65
Browse files Browse the repository at this point in the history
TM-65 Update user data for additional dba steps
  • Loading branch information
vc13837 authored Nov 1, 2024
2 parents b65908f + 1941983 commit d62a817
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
32 changes: 23 additions & 9 deletions terraform/environments/contract-work-administration/app_servers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ sed -i 's/${local.application_data.accounts[local.environment].old_mail_server_u
sed -i 's/${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /etc/mail/sendmail.mc
/etc/init.d/sendmail restart
## Remove SSH key allowed
echo "Removing old SSH key"
sed -i '/.*-general$/d' /home/ec2-user/.ssh/authorized_keys
Expand All @@ -127,6 +126,14 @@ rm /var/cw-custom.sh
chmod 700 /var/cw-custom.sh
# This script will be ran by the cron job in /etc/cron.d/custom_cloudwatch_metrics
## Additional DBA Steps
echo "Updating CWA_cwa-app1.xml"
su - applmgr -c "cp /CWA/app/appl/admin/CWA_cwa-app1.xml /CWA/app/appl/admin/CWA_cwa-app1.xml.tf_backup"
sed -i 's/aws.${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app1.xml
sed -i 's/${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app1.xml
sed -i 's/cwa.${local.application_data.accounts[local.environment].old_domain_name}/${resource.aws_route53_record.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app1.xml
sed -i 's/[email protected]/db_admin@${resource.aws_route53_record.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app1.xml
EOF

Expand Down Expand Up @@ -181,7 +188,7 @@ resource "aws_instance" "app1" {
iam_instance_profile = aws_iam_instance_profile.cwa.id
key_name = aws_key_pair.cwa.key_name
user_data_base64 = base64encode(local.app_userdata)
user_data_replace_on_change = false
user_data_replace_on_change = true
metadata_options {
http_tokens = "optional"
}
Expand All @@ -206,17 +213,20 @@ resource "aws_instance" "app1" {
}

resource "aws_instance" "app2" {
count = contains(["development", "testing"], local.environment) ? 0 : 1
count = contains(["development2", "testing"], local.environment) ? 0 : 1
ami = local.application_data.accounts[local.environment].app_ami_id
availability_zone = "eu-west-2a"
instance_type = local.application_data.accounts[local.environment].app_instance_type
monitoring = true
vpc_security_group_ids = [aws_security_group.app.id]
subnet_id = data.aws_subnet.data_subnets_a.id
subnet_id = data.aws_subnet.private_subnets_a.id
iam_instance_profile = aws_iam_instance_profile.cwa.id
key_name = aws_key_pair.cwa.key_name
# user_data_base64 = base64encode(local.app_userdata)
# user_data_replace_on_change = true
user_data_base64 = base64encode(local.app_userdata)
user_data_replace_on_change = false
metadata_options {
http_tokens = "optional"
}

root_block_device {
tags = merge(
Expand Down Expand Up @@ -382,6 +392,9 @@ resource "aws_ebs_volume" "app1" {
snapshot_id = local.application_data.accounts[local.environment].app_snapshot_id # This is used for when data is being migrated

lifecycle {
replace_triggered_by = [
aws_instance.app1.id
]
ignore_changes = [kms_key_id]
}

Expand All @@ -398,13 +411,13 @@ resource "aws_volume_attachment" "app1" {
}

resource "aws_ebs_volume" "app2" {
count = contains(["development", "testing"], local.environment) ? 0 : 1
count = contains(["development2", "testing"], local.environment) ? 0 : 1
availability_zone = "eu-west-2a"
size = local.application_data.accounts[local.environment].ebs_app_size
type = "gp2"
encrypted = true
kms_key_id = data.aws_kms_key.ebs_shared.key_id
# snapshot_id = local.application_data.accounts[local.environment].app_snapshot_id # This is used for when data is being migrated
snapshot_id = local.application_data.accounts[local.environment].app_snapshot_id # This is used for when data is being migrated

lifecycle {
ignore_changes = [kms_key_id]
Expand All @@ -417,8 +430,9 @@ resource "aws_ebs_volume" "app2" {
}

resource "aws_volume_attachment" "app2" {
count = contains(["development", "testing"], local.environment) ? 0 : 1
count = contains(["development2", "testing"], local.environment) ? 0 : 1
device_name = "/dev/sdf"
volume_id = aws_ebs_volume.app2[0].id
instance_id = aws_instance.app2[0].id
}

Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ rm /var/cw-custom.sh
chmod 700 /var/cw-custom.sh
# This script will be ran by the cron job in /etc/cron.d/custom_cloudwatch_metrics
## Additional DBA Steps
echo "Updating CWA_cwa-app2.xml"
su - applmgr -c "cp /CWA/app/appl/admin/CWA_cwa-app2.xml /CWA/app/appl/admin/CWA_cwa-app2.xml.tf_backup"
sed -i 's/aws.${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app2.xml
sed -i 's/${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app2.xml
sed -i 's/cwa.${local.application_data.accounts[local.environment].old_domain_name}/${resource.aws_route53_record.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app2.xml
sed -i 's/[email protected]/db_admin@${resource.aws_route53_record.external.name}/g' /CWA/app/appl/admin/CWA_cwa-app2.xml
EOF

}
Expand Down Expand Up @@ -158,7 +166,7 @@ resource "aws_instance" "concurrent_manager" {
iam_instance_profile = aws_iam_instance_profile.cwa.id
key_name = aws_key_pair.cwa.key_name
user_data_base64 = base64encode(local.cm_userdata)
user_data_replace_on_change = false
user_data_replace_on_change = true
metadata_options {
http_tokens = "optional"
}
Expand Down Expand Up @@ -244,6 +252,9 @@ resource "aws_ebs_volume" "concurrent_manager" {
snapshot_id = local.application_data.accounts[local.environment].concurrent_manager_snapshot_id # This is used for when data is being migrated

lifecycle {
replace_triggered_by = [
aws_instance.concurrent_manager.id
]
ignore_changes = [kms_key_id]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ cat <<EOT > /etc/cron.d/custom_cloudwatch_metrics
*/1 * * * * root /var/cw-custom.sh > /dev/null 2>&1
EOT
## Additional DBA steps
su oracle -c "sed -i 's/aws.${local.application_data.accounts[local.environment].old_domain_name}/${data.aws_route53_zone.external.name}/g' /CWA/oracle/product/10.2.0/db_1/appsutil/CWA_cwa-db.xml"
EOF

}
Expand Down

0 comments on commit d62a817

Please sign in to comment.