Skip to content

Commit

Permalink
testing this workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudyBae committed Apr 13, 2024
1 parent 51b3bd4 commit b8eb746
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ jobs:
run: terraform init
working-directory: terraform

- name: Terraform Format
run: terraform fmt -check
working-directory: terraform

- name: Terraform Plan
id: terraform-plan
run: |
terraform plan -input=false -out=tfplan
echo ::set-output name=has_changes::$(terraform show -json tfplan | jq -r '.resource_changes | length > 0')
run: terraform plan -input=false
working-directory: terraform

- name: Conditional Terraform Apply
if: steps.terraform-plan.outputs.has_changes == 'true'
run: |
cat tfplan | terraform apply -auto-approve -
- name: Terraform Apply
run: terraform apply -auto-approve -input=false
working-directory: terraform
17 changes: 2 additions & 15 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,13 @@ data "aws_ami" "ubuntu" {
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
owners = ["099720109477"]
}

resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
vpc_security_group_ids = [aws_security_group.web-sg.id]

user_data = <<-EOF
#!/bin/bash
apt-get update
apt-get install -y apache2
sed -i -e 's/80/8080/' /etc/apache2/ports.conf
echo "Hello World" > /var/www/html/index.html
systemctl restart apache2
EOF
}

resource "aws_security_group" "web-sg" {
Expand All @@ -57,15 +48,11 @@ resource "aws_security_group" "web-sg" {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
// connectivity to ubuntu mirrors is required to run `apt-get update` and `apt-get install apache2`

egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

output "web-address" {
value = "${aws_instance.web.public_dns}:8080"
}

0 comments on commit b8eb746

Please sign in to comment.