Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Update main.yml #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
146 changes: 82 additions & 64 deletions terraform/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
# name: "Terraform Deployment"
# on:
# # Manual trigger
# workflow_dispatch:
# push:
# paths:
# - '*/**'
# pull_request:
# branches: [ main ]
# defaults:
# run:
# shell: bash
# jobs:
# terraform:
# name: ${{matrix.runner}} - ${{ matrix.environment }}
# runs-on: [ '${{ matrix.runner }}']
# strategy:
# max-parallel: 1
# matrix:
# include:
# - environment: test
# runner: ubuntu-latest
# - environment: prod
# runner: ubuntu-18.04
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS_DEFAULT_REGION: us-east-2
# steps:
# - uses: actions/checkout@v2
# - uses: hashicorp/setup-terraform@v1
# with:
# terraform_wrapper: false
# - name: Terraform Init
# id: init
# run: |
# rm -rf .terraform
# terraform init -upgrade=true -no-color -input=false
# - name: Terraform Plan
# id: plan
# run: |
# terraform plan -input=false -no-color
# - name: Terraform Apply
# if: github.ref == 'refs/heads/main'
# id: apply
# run: terraform apply -auto-approve -input=false
# - name: Terraform destroy
# if: github.ref == 'refs/heads/destroy'
# id: destroy
# run: terraform destroy -auto-approve -input=false
# comment:
# runs-on: ubuntu-latest
# needs: terraform
# if: github.event_name == 'pull_request'
# steps:
# - uses: actions/github-script@v5
# with:
# script: |
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: '👋 Thanks for reporting!'
# })
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 = "manto"

workspaces {
name = "Github"
}
}
}

provider "aws" {
region = "us-east-1"
}

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 = ["629974703195"] # 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
sudo apt-get update -y
sudo apt install docker.io -y
sudo apt install docker-compose -y

echo
git clone https://github.com/azharism/Snipe-IT-GitHub-Actions.git
cd /snipe-it/
sudo docker-compose up
EOF
}

resource "aws_security_group" "web-sg" {
name = "${random_pet.sg.id}-sg"
ingress {
from_port = 0
to_port = 6553
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_ip}:8000"
}