From 228ae4f0e8f9781d2f55b6df342f9b987329dc7a Mon Sep 17 00:00:00 2001 From: Brennan Wilkes Date: Thu, 9 Jun 2022 20:58:31 -0700 Subject: [PATCH] DevXP: Configured Terraform --- terraform.tf | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 terraform.tf diff --git a/terraform.tf b/terraform.tf new file mode 100644 index 0000000..39f8325 --- /dev/null +++ b/terraform.tf @@ -0,0 +1,67 @@ +terraform { + backend "s3" { + bucket = "terraform-state-b8er8si0k2du2h1i5dep3xcklp0x0je0rqjpk6ljtpn32" + key = "terraform/state" + region = "us-west-2" + } +} + +provider "aws" { + region = "us-west-2" +} + +resource "aws_instance" "Instance-pkep" { + ami = data.aws_ami.ubuntu_latest.id + instance_type = "t2.micro" + lifecycle { + ignore_changes = [ami] + } +} + +resource "aws_iam_user" "Instance-pkep_iam" { + name = "Instance-pkep_iam" +} + +resource "aws_iam_user_policy_attachment" "Instance-pkep_iam_policy_attachment0" { + user = aws_iam_user.Instance-pkep_iam.name + policy_arn = aws_iam_policy.Instance-pkep_iam_policy0.arn +} + +resource "aws_iam_policy" "Instance-pkep_iam_policy0" { + name = "Instance-pkep_iam_policy0" + path = "/" + policy = data.aws_iam_policy_document.Instance-pkep_iam_policy_document.json +} + +resource "aws_iam_access_key" "Instance-pkep_iam_access_key" { + user = aws_iam_user.Instance-pkep_iam.name +} + +data "aws_iam_policy_document" "Instance-pkep_iam_policy_document" { + statement { + actions = ["ec2:RunInstances", "ec2:AssociateIamInstanceProfile", "ec2:ReplaceIamInstanceProfileAssociation"] + effect = "Allow" + resources = ["arn:aws:ec2:::*"] + } + statement { + actions = ["iam:PassRole"] + effect = "Allow" + resources = [aws_instance.Instance-pkep.arn] + } +} + +data "aws_ami" "ubuntu_latest" { + most_recent = true + owners = ["099720109477"] + filter { + name = "name" + values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64*"] + } + filter { + name = "virtualization-type" + values = ["hvm"] + } +} + + +