commit d07e938be2639d18721b45c04bd8eb45c4be4cb5 Author: pastryer Date: Thu Mar 28 17:06:06 2024 +0000 Upload files to "/" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52f4578 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, +such as +# password, private keys, and other secrets. These should not be part of +version +# control as they are data points which are potentially sensitive and +subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources +locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using +negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform +plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/datasources.tf b/datasources.tf new file mode 100644 index 0000000..f1abf9a --- /dev/null +++ b/datasources.tf @@ -0,0 +1,9 @@ +data "aws_ami" "server_ami" { + most_recent = true + owners = ["099720109477"] + + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"] + } +} \ No newline at end of file diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..784f35a --- /dev/null +++ b/main.tf @@ -0,0 +1,90 @@ +resource "aws_vpc" "sgtm_vpc" { + cidr_block = "10.123.0.0/16" + enable_dns_hostnames = true + enable_dns_support = true + + tags = { + name = "dev" + } +} + +resource "aws_subnet" "sptm_public_subnet" { + vpc_id = aws_vpc.sgtm_vpc.id + cidr_block = "10.123.1.0/24" + map_public_ip_on_launch = true + availability_zone = "us-east-1a" + + tags = { + name = "dev-public" + } +} + +resource "aws_internet_gateway" "sgtm_internet_gateway" { + vpc_id = aws_vpc.sgtm_vpc.id + + tags = { + name = "dev-igw" + } +} + +resource "aws_route_table" "sgtm_public_rt" { + vpc_id = aws_vpc.sgtm_vpc.id + + tags = { + name = "dev_public_rt" + } +} + +resource "aws_route" "default_route" { + route_table_id = aws_route_table.sgtm_public_rt.id + destination_cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.sgtm_internet_gateway.id +} + +resource "aws_route_table_association" "sgtm_public_assoc" { + subnet_id = aws_subnet.sptm_public_subnet.id + route_table_id = aws_route_table.sgtm_public_rt.id +} + +resource "aws_security_group" "sgtm_sg" { + name = "dev-sg" + description = "dev security group" + vpc_id = aws_vpc.sgtm_vpc.id + + ingress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["172.59.221.135/32"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_key_pair" "sgtm_auth" { + key_name = "sgtmkey" + public_key = file("~/.ssh/sgtmkey.pub") +} + +resource "aws_instance" "dev_node" { + instance_type = "t2.micro" + ami = data.aws_ami.server_ami.id + key_name = aws_key_pair.sgtm_auth.id + vpc_security_group_ids = [aws_security_group.sgtm_sg.id] + subnet_id = aws_subnet.sptm_public_subnet.id + user_data = file ("userdata.tpl") + + root_block_device { + volume_size = 10 + } + + tags = { + name = "dev-node" + } + +} \ No newline at end of file diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..0a9783c --- /dev/null +++ b/providers.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + } + } +} +provider "aws" { + region = "us-east-1" + shared_credentials_files = ["~/.aws/credentials"] + profile = "vscode" +} \ No newline at end of file diff --git a/userdata.tpl b/userdata.tpl new file mode 100644 index 0000000..f56834e --- /dev/null +++ b/userdata.tpl @@ -0,0 +1,14 @@ +#!/bin/bash +sudo apt-get update -y && +sudo apt-get install -y \ +apt-trasport-https \ +ca-certificates \ +curl \ +gnupg-agent \ +software-properties-common && +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && +sudo add-apt-repository "deb [arch-amd64] https://download.docker.com/linux/ubuntu $(lsb_release -c) stable" && +sudo apt-get update -y && +sudo apt-get install docker-ce docker-ce-cli containerd.io -y && +# sudo apt install docker.io +sudo usermod -aG docker ubuntu \ No newline at end of file