Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nilgaar committed Jul 14, 2024
2 parents 79f9f93 + e65187b commit f283302
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/deploy_aws_vpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
- uses: opentofu/[email protected]
name: Setup OpenTofu

- name: Setup SSH Key using webfactory/ssh-agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: OpenTofu Setup and Validate
run: |
cd ./IaC/aws/terraform/
Expand All @@ -33,3 +38,8 @@ jobs:
run: |
cd ./IaC/aws/terraform/
tofu apply -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
- name: Destroy VPC
run: |
cd ./IaC/aws/terraform/
tofu destroy -auto-approve -var="AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" -var="AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}"
1 change: 1 addition & 0 deletions IaC/ansible/apache.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- name: Install and start Apache
hosts: all
become: yes
Expand Down
17 changes: 12 additions & 5 deletions IaC/aws/terraform/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ resource "aws_instance" "ec2example" {
associate_public_ip_address = true
key_name = aws_key_pair.ec2_key_pair.key_name

provisioner "local-exec" {
command = "ansible-playbook -i '${self.public_ip},' --private-key ${path.module}/ ansible/playbook.yml"
}

provisioner "remote-exec" {
inline = [
"echo 'Waiting for instance to be ready'"
"echo 'Waiting for instance to be fully ready...'",
"sleep 20"
]
}

provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i '${self.public_ip},' ${path.module}/../../ansible/apache.yml -u 'ubuntu'"
}

connection {
type = "ssh"
user = "ubuntu"
host = self.public_ip
}
}

0 comments on commit f283302

Please sign in to comment.