From 13e75d2f2f45cd1cdf5f9047cab3376a4c18d5c1 Mon Sep 17 00:00:00 2001 From: John Turner Date: Fri, 8 Apr 2022 11:15:57 -0400 Subject: [PATCH] Updating with templates and updating AMI's --- onboarding/http/main.tf | 27 +---------- .../templates/http_install/http_install.tftpl | 19 ++++++++ onboarding/mysql/main.tf | 47 ++++--------------- .../mysql_install/mysql_install.tftpl | 28 +++++++++++ onboarding/sdm_gateway/main.tf | 14 +----- .../relay_install/relay_install.tftpl | 3 ++ onboarding/windows_server/main.tf | 4 +- 7 files changed, 63 insertions(+), 79 deletions(-) create mode 100644 onboarding/http/templates/http_install/http_install.tftpl create mode 100644 onboarding/mysql/templates/mysql_install/mysql_install.tftpl create mode 100644 onboarding/sdm_gateway/templates/relay_install/relay_install.tftpl diff --git a/onboarding/http/main.tf b/onboarding/http/main.tf index b9dc691..1cd074b 100644 --- a/onboarding/http/main.tf +++ b/onboarding/http/main.tf @@ -62,32 +62,7 @@ resource "aws_instance" "web_page" { vpc_security_group_ids = [aws_security_group.web_page[0].id] # Configures a simple HTTP web page - user_data = <<-EOF - #!/bin/bash -xe - - # add sdm public key - cat <" > /var/www/html/phpinfo.php - EOF - + user_data = templatefile("${path.module}/templates/http_install/http_install.tftpl", { SSH_PUB_KEY = "${var.ssh_pubkey}" }) tags = merge({ Name = "${var.prefix}-http" }, var.default_tags, var.tags) } # ---------------------------------------------------------------------------- # diff --git a/onboarding/http/templates/http_install/http_install.tftpl b/onboarding/http/templates/http_install/http_install.tftpl new file mode 100644 index 0000000..b96a422 --- /dev/null +++ b/onboarding/http/templates/http_install/http_install.tftpl @@ -0,0 +1,19 @@ +#!/bin/bash -xe + +# add sdm public key +echo "${SSH_PUB_KEY}" | tee -a /etc/ssh/sdm_ca.pub +echo "TrustedUserCAKeys /etc/ssh/sdm_ca.pub" | tee -a /etc/ssh/sshd_config +systemctl restart sshd + +# setup apache +yum update -y +amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2 +yum install -y httpd mariadb-server +systemctl start httpd +systemctl enable httpd +usermod -a -G apache ec2-user +chown -R ec2-user:apache /var/www +chmod 2775 /var/www +find /var/www -type d -exec chmod 2775 {} \; +find /var/www -type f -exec chmod 0664 {} \; +echo "" > /var/www/html/phpinfo.php \ No newline at end of file diff --git a/onboarding/mysql/main.tf b/onboarding/mysql/main.tf index 274f848..693ed2a 100644 --- a/onboarding/mysql/main.tf +++ b/onboarding/mysql/main.tf @@ -19,43 +19,6 @@ locals { mysql_pw = "strongdmpassword123!@#" database = "strongdmdb" table_name = "strongdm_table" - mysql_user_data = <<-USERDATA - #!/bin/bash - - # add sdm public key - cat <