From 4c287c7db002e9a1182442129867807bd127ab44 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 12:50:43 +0100 Subject: [PATCH 01/12] added private key options --- .github/workflows/linux_benchmark_testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux_benchmark_testing.yml b/.github/workflows/linux_benchmark_testing.yml index 03f9d4e..45c6777 100644 --- a/.github/workflows/linux_benchmark_testing.yml +++ b/.github/workflows/linux_benchmark_testing.yml @@ -87,7 +87,7 @@ jobs: working-directory: .github/workflows id: test_os run: >- - ansible all -i hosts.yml -m wait_for -a "port=22 connect_timeout=10 delay=10 timeout=300 sleep=5" + ansible all -i hosts.yml -m wait_for -a "port=22 connect_timeout=10 delay=10 timeout=300 sleep=5" --private-key=.ssh/github_actions.pem # Run the ansible playbook - name: Run_Ansible_Playbook From c24f0a3a714a0496bde25c82d9907c65c5f6b7b5 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 13:27:11 +0100 Subject: [PATCH 02/12] added user --- .github/workflows/linux_benchmark_testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux_benchmark_testing.yml b/.github/workflows/linux_benchmark_testing.yml index 45c6777..0cbc360 100644 --- a/.github/workflows/linux_benchmark_testing.yml +++ b/.github/workflows/linux_benchmark_testing.yml @@ -87,7 +87,7 @@ jobs: working-directory: .github/workflows id: test_os run: >- - ansible all -i hosts.yml -m wait_for -a "port=22 connect_timeout=10 delay=10 timeout=300 sleep=5" --private-key=.ssh/github_actions.pem + ansible all -i hosts.yml -m wait_for -a "port=22 delay=10 timeout=600" --private-key=.ssh/github_actions.pem -u ec2-user # Run the ansible playbook - name: Run_Ansible_Playbook From 32ce7b569f6a5d8b562fa772cc0bd1effa2ccd7a Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 13:59:10 +0100 Subject: [PATCH 03/12] add debug --- .github/workflows/linux_benchmark_testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux_benchmark_testing.yml b/.github/workflows/linux_benchmark_testing.yml index 0cbc360..6e846f3 100644 --- a/.github/workflows/linux_benchmark_testing.yml +++ b/.github/workflows/linux_benchmark_testing.yml @@ -87,7 +87,7 @@ jobs: working-directory: .github/workflows id: test_os run: >- - ansible all -i hosts.yml -m wait_for -a "port=22 delay=10 timeout=600" --private-key=.ssh/github_actions.pem -u ec2-user + ansible all -i hosts.yml -m wait_for -a "port=22 delay=10 timeout=600" --private-key=.ssh/github_actions.pem -u ec2-user -vvv # Run the ansible playbook - name: Run_Ansible_Playbook From 78116ee73840fa9ad42258430a3e0fd88b9aab5a Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:30:45 +0100 Subject: [PATCH 04/12] added new ssh connection --- .github/workflows/main.tf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/main.tf b/.github/workflows/main.tf index 29fd6f3..4123d04 100644 --- a/.github/workflows/main.tf +++ b/.github/workflows/main.tf @@ -59,6 +59,20 @@ resource "aws_instance" "testing_vm" { root_block_device { delete_on_termination = true } + # SSH into instance - will ensure server is up before next step in workflows + connection { + # Host name + host = self.public_ip + # The default username for our AMI + user = var.ami_username + # Private key for connection + private_key = "${file(var.private_key)}" + # Type of connection + type = "ssh" + } + provisioner "remote-exec" { + inline = [ "echo hello_world"] + } } // generate inventory file From d99ab69928c60987f6f0961632dcb3ac55f40fae Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:31:16 +0100 Subject: [PATCH 05/12] Added private key var --- .github/workflows/github_vars.tfvars | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github_vars.tfvars b/.github/workflows/github_vars.tfvars index 4d40f72..59d5d14 100644 --- a/.github/workflows/github_vars.tfvars +++ b/.github/workflows/github_vars.tfvars @@ -7,6 +7,7 @@ namespace = "github_actions" // Matching pair name found in AWS for keypairs PEM key ami_key_pair_name = "github_actions" +private_key = ".ssh/github_actions.pem" main_vpc_cidr = "172.22.0.0/24" public_subnets = "172.22.0.128/26" -private_subnets = "172.22.0.192/26" \ No newline at end of file +private_subnets = "172.22.0.192/26" From 8178261ea7ec84ff6d5ad3a21275965801aab548 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:32:11 +0100 Subject: [PATCH 06/12] added private key var --- .github/workflows/variables.tf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/variables.tf b/.github/workflows/variables.tf index 58544fc..752ee88 100644 --- a/.github/workflows/variables.tf +++ b/.github/workflows/variables.tf @@ -22,6 +22,11 @@ variable "ami_key_pair_name" { type = string } +variable "private_key" { + description = "path to private key for ssh" + type = string +} + variable "ami_os" { description = "AMI OS Type" type = string @@ -62,4 +67,4 @@ variable "public_subnets" { variable "private_subnets" { description = "private subnet cidr block" type = string -} \ No newline at end of file +} From dbd3ab706de5bbe55d186665a28b18066e7db2cd Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:39:06 +0100 Subject: [PATCH 07/12] updated remote-exec --- .github/workflows/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.tf b/.github/workflows/main.tf index 4123d04..ea3af84 100644 --- a/.github/workflows/main.tf +++ b/.github/workflows/main.tf @@ -71,7 +71,7 @@ resource "aws_instance" "testing_vm" { type = "ssh" } provisioner "remote-exec" { - inline = [ "echo hello_world"] + command = "echo 'hello world'" } } From b1daec8c244f36ddff60abd4b223699d1ef46585 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:47:53 +0100 Subject: [PATCH 08/12] updated remote-exec --- .github/workflows/main.tf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.tf b/.github/workflows/main.tf index ea3af84..59fcc52 100644 --- a/.github/workflows/main.tf +++ b/.github/workflows/main.tf @@ -71,7 +71,9 @@ resource "aws_instance" "testing_vm" { type = "ssh" } provisioner "remote-exec" { - command = "echo 'hello world'" + inline = [ + "echo 'hello_world'", + ] } } From 5a2da89394327ba55d84e2a8b2c03108e6a62c16 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:17:36 +0100 Subject: [PATCH 09/12] quoted private_key --- .github/workflows/github_vars.tfvars | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github_vars.tfvars b/.github/workflows/github_vars.tfvars index 59d5d14..c3ac76b 100644 --- a/.github/workflows/github_vars.tfvars +++ b/.github/workflows/github_vars.tfvars @@ -7,7 +7,7 @@ namespace = "github_actions" // Matching pair name found in AWS for keypairs PEM key ami_key_pair_name = "github_actions" -private_key = ".ssh/github_actions.pem" +private_key = "'.ssh/github_actions.pem'" main_vpc_cidr = "172.22.0.0/24" public_subnets = "172.22.0.128/26" private_subnets = "172.22.0.192/26" From 78c5e4661f1f9ed7ca44f0440e64ef21268cde1f Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:20:20 +0100 Subject: [PATCH 10/12] hardcode private_key path --- .github/workflows/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.tf b/.github/workflows/main.tf index 59fcc52..adfaea0 100644 --- a/.github/workflows/main.tf +++ b/.github/workflows/main.tf @@ -66,7 +66,7 @@ resource "aws_instance" "testing_vm" { # The default username for our AMI user = var.ami_username # Private key for connection - private_key = "${file(var.private_key)}" + private_key = "${file(.ssh/github_actions.pem)}" # Type of connection type = "ssh" } From 08bb6b553fce203db7e616b6ae09ec176516fa99 Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:27:57 +0100 Subject: [PATCH 11/12] try private_key path again --- .github/workflows/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.tf b/.github/workflows/main.tf index adfaea0..b284d24 100644 --- a/.github/workflows/main.tf +++ b/.github/workflows/main.tf @@ -66,7 +66,7 @@ resource "aws_instance" "testing_vm" { # The default username for our AMI user = var.ami_username # Private key for connection - private_key = "${file(.ssh/github_actions.pem)}" + private_key = file(".ssh/github_actions.pem") # Type of connection type = "ssh" } From df2d812e6a15a5330198cd77a57fbc2019ea040e Mon Sep 17 00:00:00 2001 From: uk-bolly <69214557+uk-bolly@users.noreply.github.com> Date: Tue, 26 Jul 2022 17:31:02 +0100 Subject: [PATCH 12/12] added debug --- .github/workflows/linux_benchmark_testing.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux_benchmark_testing.yml b/.github/workflows/linux_benchmark_testing.yml index 6e846f3..08b0217 100644 --- a/.github/workflows/linux_benchmark_testing.yml +++ b/.github/workflows/linux_benchmark_testing.yml @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-latest env: - ENABLE_DEBUG: false + ENABLE_DEBUG: true # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -67,7 +67,12 @@ jobs: - name: Terraform_Validate working-directory: .github/workflows run: terraform validate - + + - name: validate path contents + if: env.ENABLE_DEBUG == 'true' + working-directory: .github/workflows + run: pwd && ls -laR + - name: Terraform_Apply working-directory: .github/workflows env: