From 2c7fbb51901c455c4d2ede1e5433bf66816a18a6 Mon Sep 17 00:00:00 2001 From: gregory hendrickson Date: Mon, 27 Nov 2023 10:07:03 -0800 Subject: [PATCH] new file ubuntu-init.yaml & new file ubuntu-instance.tf ``` --- ubuntu-init.yaml | 28 ++++++++++++++++++++++++++++ ubuntu-instance.tf | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 ubuntu-init.yaml create mode 100644 ubuntu-instance.tf diff --git a/ubuntu-init.yaml b/ubuntu-init.yaml new file mode 100644 index 0000000..48f5416 --- /dev/null +++ b/ubuntu-init.yaml @@ -0,0 +1,28 @@ +# BEGIN: cloud-init.yaml +#cloud-config +package_update: true +package_upgrade: true +packages: + - git + - amazon-efs-utils + - vim-nox + - neofetch + - htop + - tmux + - curl + - wget + +users: + - name: greg + sudo: ALL=(ALL) NOPASSWD:ALL + groups: sudo + shell: /bin/bash + ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCdOF80z0piQEnYzNCu2OGvOJdm7+3wfDuiC+Jzi8VbSC5VW4iJAQXOuDNGLzyqNi6uMjI77xpEL6Xzn29uJiQti6Y/LxhOZwNNIQiGUpFco1wkBYeBFbtgHQxsMLwumrxQGEj2fyCiSrACAPyy/l1fP4mlN7abBGD5aozBrYKxXPS/kfwO5nsWmw27RgTzfHJzie2dUU3ew/kd7td3wEdWrRXq8wNbu+yvAyiog54huUUWmYZwY3QVwXr6R1wsVudawM6BEl45QFq+hdB4t83azHG94XLy2NCAncohdU7zP40nsbvIDyh+4wIKeU90z6TLrXfHUYuBT6/ky7qOFm/Ym1QG4zCDz3jin8Qoa31PGaObzj/zoMJXgOXKcp16W0j9SZAenvnSfuWUEfBR1yBRR0T5Wg5v1vi7KGBTATaz8el802uliL+yZbGtMbNpAPGR5nK5C4yorf8yVYvIgo/LJaWCDND2O1e2mdut1WyRmvIwMnq7PFZT8zAsgGXfhDM= greg@ligma + +runcmd: + - INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) + AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) + HOSTNAME="$INSTANCE_ID-$AVAILABILITY_ZONE" + hostnamectl set-hostname $HOSTNAME +# END: cloud-init.yaml diff --git a/ubuntu-instance.tf b/ubuntu-instance.tf new file mode 100644 index 0000000..b372340 --- /dev/null +++ b/ubuntu-instance.tf @@ -0,0 +1,41 @@ + +provider "aws" { + region = "us-east-1" +} + +resource "aws_instance" "example" { + ami = "ami-0c94855ba95c71c99" # Ubuntu 20.04 LTS + instance_type = "t2.micro" + associate_public_ip_address = true + + root_block_device { + volume_size = 50 + volume_type = "gp2" + } + + user_data = file("${path.module}/ubuntu-init.yaml") + + tags = { + Name = "cloud-init-example" + } +} + +resource "aws_security_group" "example_sg" { + name = "example_sg" + description = "Example security group" + + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } +} + +resource "aws_security_group" "example_sg" { + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + } +} \ No newline at end of file