/
Terraform scripts to spin up nodes
Terraform scripts to spin up nodes
These scripts spin up EC2 nodes that appropriate for running and demoing puppet
ec2-instances.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
profile = "default"
region = "eu-west-1"
}
resource "aws_security_group" "variable-demo" {
name = "puppet machines"
ingress{
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [var.cidrip]
}
ingress{
from_port = 0
to_port = 0
protocol = "tcp"
cidr_blocks = [var.cidrip]
}
# if you do not specify this outbound rule, NO outgoing comms will work
egress{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [var.cidrip]
}
}
resource "aws_key_pair" "puppet_master" {
key_name = "master-key"
public_key = file("C:/work/git/puppet-101/puppet_master_101_ppk.pub")
}
resource "aws_key_pair" "puppet_agent" {
key_name = "agent-key"
public_key = file("C:/work/git/puppet-101/puppet_agent_101_ppk.pub")
}
resource "aws_instance" "master" {
ami = var.ubuntu_18_puppet_ami
instance_type = "t3.large"
tags = {
Name = "puppet_master"
}
vpc_security_group_ids = [aws_security_group.variable-demo.id]
# use this technique if you want to use a PEM file created through AWS console
# key_name = "terraform_101"
# Use this technique if you created key pairs with "ssh-keygen -t rsa -b 2048"
key_name = aws_key_pair.puppet_master.key_name
}
resource "aws_instance" "agent" {
ami = var.ubuntu_18_puppet_ami
instance_type = "t2.micro"
tags = {
Name = "puppet_agent"
}
vpc_security_group_ids = [aws_security_group.variable-demo.id]
# use this technique if you want to use a PEM file created through AWS console
# key_name = "puppet_master_101"
# Use this technique if you created key pairs with "ssh-keygen -t rsa -b 2048"
key_name = aws_key_pair.puppet_agent.key_name
}
resource "aws_eip" "eip_master" {
vpc = true
}
resource "aws_eip_association" "eip_master_map" {
instance_id = aws_instance.master.id
allocation_id = aws_eip.eip_master.id
}
resource "aws_eip" "eip_agent" {
vpc = true
}
resource "aws_eip_association" "eip_agent_map" {
instance_id = aws_instance.agent.id
allocation_id = aws_eip.eip_agent.id
}
variables.tf
variable "cidrip" {
default = "0.0.0.0/0"
}
variable "amz_puppe_ami" {
default = "ami-09d4a659cdd8677be"
}
variable "ubuntu_puppet_ami" {
default = "ami-08edbb0e85d6a0a07"
}
variable "ubuntu_18_puppet_ami" {
default = "ami-095b735dce49535b5"
}