This module will create the below resources:
- VPC
- IGW
- Public Subnets
- Private Subnets
- Route Tables
- Lambda Function (attach EIPs to Bastion hosts and update the route tables)
- SNS Topic
- Lambda SNS Subscription (for Bastion ASG event notifications)
- Lambda IAM role and associated policies (for EIP attachment and route changes)
- Bastion IAM role and associated policies (to read from S3 yum repos)
- EIPs for attachment to Bastion instances
- Bastion Launch Configuration (defaults to t2.micro)
- Bastion ASG (sends ASG events to SNS to trigger Lambda)
- Internal Bastion SG for access from the VPC
- External Bastion SG for SSH access
Resource numbers will differ based on the number of AZs passed to Terraform. If you pass three AZs you will have an ASG with three instances, three EIPs, three of each subnet and so on. If you are in a region such as eu-central-1 with only two zones then the module will handle this and only create two resources where applicable.
The module assumes you are happy with a set of Bastions per VPC. Using this
module it would be sensible to host all nonprod infrastructure in a single
VPC. If you don't do this you will have a lot of Bastions.
Call the module:
module "bastions" {
source = "/home/chris/dev/tf-aws-vpc-bastion"
name = "projectx"
envname = "dev"
envtype = "nonprod"
vpc_cidr = "172.28.0.0/21"
public_subnets = "172.28.0.0/24,172.28.1.0/24,172.28.2.0/24"
private_subnets = "172.28.3.0/24,172.28.4.0/24,172.28.5.0/24"
domain = "example.com"
ami_id = "ami-00000000"
bastion_userdata = "${file("bastion_userdata.tmpl")}"
bastion_ssh_cidrs = "88.97.72.136/32,54.76.122.23/32"
aws_zones = "eu-west-1a,eu-west-1b,eu-west-1c"
aws_region = "eu-west-1"
}
name- Used to identify your resources, the project name is sensibleenvname- You probably only want anonprodandprodVPCenvtype- usuallyprodornonprodvpc_cidr- CIDR to use for your VPCpublic_subnets- The public subnets the bastions will sit inprivate_subnets- The private subnets your infrastructure will sit indomain- The domain for your environment (this is only used in userdata)ami_id- The AWS AMI to use, should be a Linux image like CentOS or Debianbastion_userdata- The template file to use for bastion userdatabastion_ssh_cidrs- IPs allowed SSH access to Bastions from the internetaws_zones- AWS zones to useaws_region- AWS region to use
vpc_id- VPC IDvpc_cidr- VPC CIDRavailability_zones- AWS availability zones in usepublic_subnets- Comma separated list of public subnetspublic_route_tables- Comma separated list of public subnet route tablesprivate_subnets- Comma separated list of private subnetsprivate_route_tables- Comma separated list of private subnet route tablesbastion_userdata_redndered- Rendered version of bastion userdatabastion_iam_profile_id- Bastion instance IAM profile IDbastion_iam_role_id- Bastion instance IAM role IDbastion_eip_ids- Comma separated list of EIP IDs to be attached to bastionsbastion_eip- Comma separated list of EIP IPs to be attached to bastionslaunch_config_idBastion launch configuration IDasg_id- Bastion ASG IDasg_name- Bastion ASG namelambda_arn- Lambda function ARNlambda_iam_role_id- Lambda IAM role IDbastion_sns_arn- Bastion ASG notification SNS ARNbastion_sns_id- Bastion ASG notification SNS IDbastion_sns_subscription_arn- Bastion ASG notification SNS subscription ARNbastion_sns_subscription_id- Bastion ASG notification SNS subscription IDbastion_external_sg_id- Bastion external SG IDbastion_internal_sg_id- Bastion internal SG ID