Differences
This shows you the differences between two versions of the page.
linux_wiki:terraform [2018/06/14 22:21] billdozor [File Structure] |
linux_wiki:terraform [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Terraform ====== | ||
- | |||
- | **General Information** | ||
- | |||
- | " | ||
- | |||
- | Site | ||
- | * Official Site: https:// | ||
- | * Downloads: https:// | ||
- | * Getting started: https:// | ||
- | |||
- | **Checklist** | ||
- | * AWS Account | ||
- | |||
- | ---- | ||
- | |||
- | ====== Install Terraform ====== | ||
- | |||
- | Installing Terraform on Linux. | ||
- | |||
- | * Visit downloads page: https:// | ||
- | * Copy download link | ||
- | * On Linux server, wget the link to download (example link)< | ||
- | * Unzip single binary, move into / | ||
- | |||
- | mv terraform / | ||
- | * Verify< | ||
- | |||
- | ---- | ||
- | |||
- | ====== Configure AWS Credentials for Use ====== | ||
- | |||
- | * Login to your AWS account, create access keys for CLI use and download the file. | ||
- | * Create an AWS credentials file in your home directory< | ||
- | |||
- | # AWS Credentials | ||
- | [default] | ||
- | aws_access_key_id = " | ||
- | aws_secret_access_key = " | ||
- | * The profile name is " | ||
- | |||
- | * Lock down permissions< | ||
- | |||
- | |||
- | ====== Terraform Example: 2 Tier VPC ====== | ||
- | |||
- | Creating a 2-tier VPC (public and private subnets), utilizing 3 availability zones in US-West (Oregon). | ||
- | |||
- | This will create the all of the virtual infrastructure to start creating services inside of. | ||
- | |||
- | ===== File Structure ===== | ||
- | |||
- | Files can be named anything, as long as it ends in a " | ||
- | |||
- | Example Structure | ||
- | <code bash> | ||
- | ├── main.tf | ||
- | ├── outputs.tf | ||
- | ├── site # A local defined module called " | ||
- | │ ├── nat_gateway.tf | ||
- | │ ├── outputs.tf | ||
- | │ ├── routes.tf | ||
- | │ ├── security_groups.tf | ||
- | │ ├── subnets.tf | ||
- | │ ├── variables.tf | ||
- | │ └── vpc.tf | ||
- | ├── terraform.tfstate | ||
- | ├── terraform.tfstate.backup | ||
- | └── variables.tf | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== File Contents ===== | ||
- | |||
- | Contents of the above config files. | ||
- | |||
- | ==== File Contents: Root Files ==== | ||
- | |||
- | Files in the top level directory. Ordered in a way that is easier to follow. | ||
- | |||
- | <code bash main.tf># | ||
- | # Description: | ||
- | # AWS Credentials auto loaded from ~/ | ||
- | |||
- | ## AWS Provider and Region | ||
- | provider " | ||
- | region = " | ||
- | profile = " | ||
- | } | ||
- | |||
- | ## Module: Site Infrastructure Setup | ||
- | module " | ||
- | source = " | ||
- | availability_zones = " | ||
- | public_subnet01_cidr = " | ||
- | public_subnet02_cidr = " | ||
- | public_subnet03_cidr = " | ||
- | private_subnet01_cidr = " | ||
- | private_subnet02_cidr = " | ||
- | private_subnet03_cidr = " | ||
- | vpc_cidr = " | ||
- | }</ | ||
- | |||
- | <code bash variables.tf># | ||
- | # Description: | ||
- | |||
- | ####-- Global Variables --#### | ||
- | |||
- | # AWS Region To Use | ||
- | variable " | ||
- | default = " | ||
- | } | ||
- | |||
- | # Availability Zones To Use | ||
- | variable " | ||
- | type = " | ||
- | default = [ " | ||
- | } | ||
- | |||
- | ####-- VPC Variables --#### | ||
- | |||
- | # VPC Network | ||
- | variable " | ||
- | description = "CIDR for the whole VPC" | ||
- | # /21 = 2046 IPs, 10.0.0.1 - 10.0.7.254 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Public Subnet 01 (with IGW) | ||
- | variable " | ||
- | description = "CIDR for the Public Subnet" | ||
- | # /25 = 126 IPs, 10.0.0.1 - 10.0.0.126 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Public Subnet 02 (with IGW) | ||
- | variable " | ||
- | description = "CIDR for the Public Subnet" | ||
- | # /25 = 126 IPs, 10.0.0.129 - 10.0.0.254 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Public Subnet 03 (with IGW) | ||
- | variable " | ||
- | description = "CIDR for the Public Subnet" | ||
- | # /25 = 126 IPs, 10.0.1.1 - 10.0.1.126 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Private Subnet 01 (no IGW) | ||
- | variable " | ||
- | description = "CIDR for the Private Subnet" | ||
- | # /23 = 510 IPs, 10.0.2.1 - 10.0.3.254 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Private Subnet 02 (no IGW) | ||
- | variable " | ||
- | description = "CIDR for the Private Subnet" | ||
- | # /23 = 510 IPs, 10.0.4.1 - 10.0.5.254 | ||
- | default = " | ||
- | } | ||
- | |||
- | # Private Subnet 03 (no IGW) | ||
- | variable " | ||
- | description = "CIDR for the Private Subnet" | ||
- | # /23 = 510 IPs, 10.0.6.1 - 10.0.7.254 | ||
- | default = " | ||
- | }</ | ||
- | |||
- | <code bash outputs.tf># | ||
- | # Description: | ||
- | |||
- | # Pull the VPC ID from the site module | ||
- | output " | ||
- | value = " | ||
- | }</ | ||
- | |||
- | ==== File Contents: Site Module Files ==== | ||
- | |||
- | Files in the site/ module directory. Ordered in a way that is easier to follow. | ||
- | |||
- | <code bash nat_gateway.tf></ | ||
- | |||
- | <code bash outputs.tf></ | ||
- | |||
- | <code bash routes.tf></ | ||
- | |||
- | <code bash security_groups.tf></ | ||
- | |||
- | <code bash subnets.tf></ | ||
- | |||
- | <code bash variables.tf></ | ||
- | |||
- | <code bash vpc.tf></ | ||
- | |||
- | ---- | ||