No description
  • HCL 93.2%
  • Shell 6.8%
Find a file
oss-core-libraries-dashboard[bot] df7ec404cf
[COMPLIANCE] Update Copyright and License Headers (#3)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2026-02-20 15:27:20 +05:30
.gitignore added vpc outputs 2021-12-21 11:25:26 -05:00
backend.tf migrated workspace to remote backend with TFE vars 2021-12-21 11:43:50 -05:00
build.sh Update build.sh 2021-12-15 09:52:49 -05:00
LICENSE [COMPLIANCE] Update Copyright and License Headers (#3) 2026-02-20 15:27:20 +05:30
main.tf Moving tag for donotdelete 2022-01-13 09:11:10 -05:00
outputs.tf cidr outputs 2021-12-22 11:09:58 -05:00
providers.tf Modify DoNotDelete to false 2022-01-14 14:09:17 -05:00
README.md Rename Readme.md to README.md 2021-12-15 09:57:05 -05:00
variables.tf Check credz 2022-01-13 12:28:20 -05:00

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
}