Skip to content

hashicorp/fse-tf-atarc-aws-vpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
title tags
AWS VPC
aws vpc

aws-vpc

This code is written for a demo Instruqt course hwoever it can be utilized for creating an AWS VPC.

main.tf

The aws-vpc module can be used to quickly setup an AWS VPC. With a few variables passed in, a new VPC with associated priv/public subnets availability-zones can be created.

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "zt-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["${var.region}a", "${var.region}b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true

  tags = {
    Terraform = "true"
    Environment = "development"
  }
}

backend.tf

The backend file is to specify the location and name of the state file. Below we are storing state in the local current directory The statefile will not be created until a terraform init is run.

terraform {
  required_version = "~> 1.0.11"
  backend "local" {
    path = "./terraform.tfstate"
  }
}

providers.tf

The provider file is what Terraform Core interacts with in order to bring in different providers like AWS, Azure etc. In the following provider we are using the AWS provider. To interact with the provider for AWS, we will need credentials and region.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

provider "aws" {
  region = var.region
  access_key = var.access_key
  secret_key = var.secret_key
}

File: variables.tf

variable "region" { 
  type    = string
  description = "AWS Region"
  default = "us-east-2"
}
variable "access_key" { 
  type    = string
  description = "This is the value of AWS_ACCESS_KEY_ID"
  default = "x---"
}

variable "secret_key" { 
  type    = string
  description = "This is the value of AWS_SECRET_ACCESS_KEY"
  default = "x---"
  sensitive = true
}

File: outputs.tf

The following creates an output for the VPN Gateway

output "aws_vpn_gateway_id" {
  description = "The ID of the VPN Gateway"
  value       = module.vpc.vgw_id
}

About

Federal Solutions Engineering - ATARC Demo - Create AWS VPC with Terraform Module

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published