Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.26.0"
}
random = {
source = "hashicorp/random"
version = "3.0.1"
}
}
required_version = ">= 1.1.0"

cloud {
organization = "REPLACE_ME"

workspaces {
name = "gh-actions-demo"
}
}
}

provider "aws" {
region = "us-west-2"
}

resource "random_pet" "sg" {}

data "aws_ami" "ubuntu" {
most_recent = true

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}

owners = ["099720109477"] # Canonical
}

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
}
Comment on lines +45 to +58

Check failure

Code scanning / defsec

Instance with unencrypted block device.

Root block device is not encrypted.
Comment on lines +45 to +58

Check failure

Code scanning / defsec

aws_instance should activate session tokens for Instance Metadata Service.

Instance does not require IMDS access to require a token

resource "aws_security_group" "web-sg" {
name = "${random_pet.sg.id}-sg"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["42.42.42.42/32"]
}
// 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 = ["41.41.41.41/32"]
}
}

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