Initial Commit

This commit is contained in:
Daniel Mason 2023-04-22 12:37:30 +12:00
parent 8734e2952d
commit 1bb150d44e
Signed by: idanoo
GPG key ID: 387387CDBC02F132
7 changed files with 87 additions and 98 deletions

View file

@ -1,16 +0,0 @@
name: Your Fork
on:
pull_request_target:
types: [opened]
jobs:
close:
if: github.repository == 'hashicorp/learn-terraform-github-actions'
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Optional. Post a issue comment just before closing a pull request.
comment: "Hi! If you are following the Terraform GitHub Actions tutorial, please open the PR against [your personal fork](https://learn.hashicorp.com/tutorials/terraform/github-actions?in=terraform/automation#set-up-a-github-repository) of this repository. We will automatically close this PR, but if you intended to edit the example itself please feel free to re-open it."

23
data.tf Normal file
View file

@ -0,0 +1,23 @@
# Get current AWS Region
data "aws_region" "current" {}
# Get available AZs
data "aws_availability_zones" "available" {}
# Get latest official Ubuntu AMI
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-arm64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}

35
ec2.tf Normal file
View file

@ -0,0 +1,35 @@
# # Instance
# resource "aws_instance" "instance" {
# ami = data.aws_ami.ubuntu.id
# instance_type = "t4g.micro"
# iam_instance_profile = aws_iam_instance_profile.profile.name
# availability_zone = element(aws_subnet.subnet.*.availability_zone, 1)
# user_data = data.template_file.userdata.rendered
# subnet_id = element(aws_subnet.subnet.*.id, 1)
# key_name = var.ssh_key
# vpc_security_group_ids = [aws_security_group.sg.id]
# }
# # Elastic IP
# resource "aws_eip" "eip" {
# instance = aws_instance.instance.id
# vpc = true
# tags = var.tags
# }
# # Create a new load balancer attachment
# resource "aws_elb_attachment" "attachment" {
# elb = aws_elb.lb.id
# instance = aws_instance.instance.id
# }
# # EBS Vol for persistance
# resource "aws_ebs_volume" "instance" {
# availability_zone = element(aws_subnet.subnet.*.availability_zone, 1)
# size = "8"
# type = "gp2"
# encrypted = true
# }

82
main.tf
View file

@ -1,82 +0,0 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.52.0"
}
random = {
source = "hashicorp/random"
version = "3.4.3"
}
}
required_version = ">= 1.1.0"
cloud {
organization = "REPLACE_ME"
workspaces {
name = "learn-terraform-github-actions"
}
}
}
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
}
resource "aws_security_group" "web-sg" {
name = "${random_pet.sg.id}-sg"
ingress {
from_port = 8080
to_port = 8080
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
output.tf Normal file
View file

27
provider.tf Normal file
View file

@ -0,0 +1,27 @@
# TF state
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.52.0"
}
random = {
source = "hashicorp/random"
version = "3.4.3"
}
}
required_version = ">= 1.1.0"
cloud {
organization = "fediservices"
workspaces {
name = "aws-infra"
}
}
}
# AWS Provider
provider "aws" {
region = "ap-southeast-2"
}

2
templates/userdata.tpl Normal file
View file

@ -0,0 +1,2 @@
#!/bin/bash