From 8e1165eb95127353e60e3e96bbf683ed4b0aa1e7 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 27 Sep 2022 12:39:01 -0500 Subject: [PATCH] terraform: Begin AWS configuration The `terraform` directory contains the resource descriptions for all AWS services that need to be configured in order for the dynamic K8s provisioner to work. Specifically, it defines the EventBridge rule and SNS topic/subscriptions that instruct AWS to send EC2 instance state change notifications to the *dynk8s-provisioner*'s HTTP interface. --- terraform/.gitattributes | 2 + terraform/.gitignore | 2 + terraform/.terraform.lock.hcl | 22 +++ terraform/README.md | 20 +++ terraform/eventbridge.tf | 16 ++ terraform/iam-policy.json | 49 ++++++ terraform/main.tf | 19 +++ terraform/sns.tf | 61 ++++++++ terraform/terraform.tfstate | 275 ++++++++++++++++++++++++++++++++++ terraform/variables.tf | 11 ++ 10 files changed, 477 insertions(+) create mode 100644 terraform/.gitattributes create mode 100644 terraform/.gitignore create mode 100644 terraform/.terraform.lock.hcl create mode 100644 terraform/README.md create mode 100644 terraform/eventbridge.tf create mode 100644 terraform/iam-policy.json create mode 100644 terraform/main.tf create mode 100644 terraform/sns.tf create mode 100644 terraform/terraform.tfstate create mode 100644 terraform/variables.tf diff --git a/terraform/.gitattributes b/terraform/.gitattributes new file mode 100644 index 0000000..349fd2e --- /dev/null +++ b/terraform/.gitattributes @@ -0,0 +1,2 @@ +.terraform.lock.hcl -diff +terraform.tfstate -diff diff --git a/terraform/.gitignore b/terraform/.gitignore new file mode 100644 index 0000000..b0b2918 --- /dev/null +++ b/terraform/.gitignore @@ -0,0 +1,2 @@ +.terraform/ +terraform.tfstate.backup diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl new file mode 100644 index 0000000..0316665 --- /dev/null +++ b/terraform/.terraform.lock.hcl @@ -0,0 +1,22 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "4.30.0" + constraints = "~> 4.16" + hashes = [ + "h1:BFfhRf8my/aa0+YOSJv0xfjLQkToF475TJTMhTZfYec=", + "zh:08213f3ba960621448754211f148730edb59194919ee476b0231b769a5355028", + "zh:29c90d6f8bdae0e1469417ade28fa79c74c2af49593c1e2f24f07bacbca9e2c9", + "zh:5c6e9fab64ad68de6cd4ec6cbb20b0f75ba1e51a8efaeda3fe65419f096a06cb", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:9bf42718580e8c5097227df34e1bfa0a10a23eac9f527d97c2819c163087b402", + "zh:9f87e42e0f3d145fb0ad4aaff7ddded5720a64f9303956b33bd274c6dd05c05b", + "zh:bf0519ed9615bc408b72a0aebe1cc075d4c2042325590ba13dd264cd264907ea", + "zh:c3ac9e1cbd0935614f5a3c9cdb4cf9c6a1045937fe38e61da7c5c0fb7a069870", + "zh:d0c184476ada38c50acc068214ed1252b4fcf80b6be900fc1aed32cbb49f8ff6", + "zh:d4987dc7b7a69ea58f2b3ff0ea4ffc1b61a97881dbb8583c9fcf9444b753a6c2", + "zh:e8037376c81aeb98d8286dc19fba7f8eb053444d4b9484ea6a922382cffc1a85", + "zh:ecdabb44b48addc8483bca7bd683614a347367ae950ca8b6a6880679f5c12abd", + ] +} diff --git a/terraform/README.md b/terraform/README.md new file mode 100644 index 0000000..4ff06fd --- /dev/null +++ b/terraform/README.md @@ -0,0 +1,20 @@ +# Configuring AWS Using Terraform + +## Prerequisites + +The IAM user or role that runs Terraform must have the appropriate permissions. +The `iam-policy.json` file defines a policy that will allow the Terraform to +manage all of the necessary resources. Before running Terraform, create an IAM +policy and assign it to a user, group, or role. Be sure to replace the AWS +account ID in the various target resource names. + +To use an IAM role, set the `iam_role` Terraform variable when executing +`terraform plan`/`terraform apply`. + +## Create Resources + +Terraform will create all resources automatically: + +```sh +terraform apply +``` diff --git a/terraform/eventbridge.tf b/terraform/eventbridge.tf new file mode 100644 index 0000000..25d2de0 --- /dev/null +++ b/terraform/eventbridge.tf @@ -0,0 +1,16 @@ +resource "aws_cloudwatch_event_rule" "instance_state" { + name = "instance-state-events" + + event_pattern = <