Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created July 16, 2023 17:34
Show Gist options
  • Save webgtx/72e138115c69459e6f0b87525e01437f to your computer and use it in GitHub Desktop.
Save webgtx/72e138115c69459e6f0b87525e01437f to your computer and use it in GitHub Desktop.
Sample resources for instance in terraform declared only by resources
data "template_file" "user_data" {
template = file("cloudinit/addpubkey.yml")
}
resource "aws_vpc" "mainvpc" {
cidr_block = "10.1.0.0/16"
}
resource "aws_internet_gateway" "gw" {
vpc_id = aws_vpc.mainvpc.id
}
resource "aws_subnet" "default" {
vpc_id = aws_vpc.mainvpc.id
cidr_block = "10.1.0.0/24"
}
resource "aws_route_table" "main_rt" {
vpc_id = aws_vpc.mainvpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.gw.id
}
}
resource "aws_security_group" "main_sg" {
vpc_id = aws_vpc.mainvpc.id
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_key_pair" "deployer" {
key_name = "deployer-key"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDE3DT9SJHDT7XNHSwpk3Z2pXDcImAJxTZDboe2ZRcxB3XywFFURwwJtHtZi80IIBTwVyfxt+ArKv4ImYw8Lm5nnhFg032Dmz7nZxqSlgeTTv3acePOPoBeS74SOVCtBqJYkQWgKFGfCFiXlGZb+b1udQ1PvgOfswvCKQYnryq5uZ+LMK268f6Wk4QwJeHwrddMuibR9Iy1FitRf2KnhDwg08VzEj7PBXxW0DbRbEfZxkj8f/3nhrNHQjBLciMLDaiLVNBTNNN9kWLazA8odoCX+Mwi9x8ARhCEA6g13KuIu60Em47/YzysqbXY6xuIFvwG7NtExklIBvtjXp9GtBrZm163ISKadGfeeL7i0HS7e6l65lcOOJXdoh06dZm5DtnD/NrFnjIWA7OiXVo6RthqrD5tunGnqQj9RRXCL69l1JopRxNTFqNwCzHj2QFI/DAaoQP5W2efjdXjLaXf1FIQQlvfZcfzv6n+xrR2upkfqDoWjOPXU8hsyRku/liSCi8= dxv1d@fedora"
}
resource "aws_instance" "registry" {
ami = "ami-0d4702e961515ac94"
instance_type = "t2.micro"
associate_public_ip_address = true
subnet_id = aws_subnet.default.id
key_name = aws_key_pair.deployer.key_name
# user_data = data.template_file.user_data.rendered
vpc_security_group_ids = [aws_security_group.main_sg.id]
# security_groups = ["anything"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment