diff --git a/.github/workflows/apply.yml b/.github/workflows/apply.yml index 3e8cf19..84200dc 100644 --- a/.github/workflows/apply.yml +++ b/.github/workflows/apply.yml @@ -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 diff --git a/terraform/main.tf b/terraform/main.tf index 0531b4e..6e691a0 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -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" { @@ -57,7 +48,7 @@ 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 @@ -65,7 +56,3 @@ resource "aws_security_group" "web-sg" { cidr_blocks = ["0.0.0.0/0"] } } - -output "web-address" { - value = "${aws_instance.web.public_dns}:8080" -}