https://github.com/phsaurav/terrasample
A multi-layred production ready terraform backend infra architecture sample
https://github.com/phsaurav/terrasample
production-ready terraform terraform-aws terraform-module terraform-workspace
Last synced: about 2 months ago
JSON representation
A multi-layred production ready terraform backend infra architecture sample
- Host: GitHub
- URL: https://github.com/phsaurav/terrasample
- Owner: phsaurav
- License: mit
- Created: 2025-01-23T15:02:00.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-23T18:50:43.000Z (about 2 months ago)
- Last Synced: 2025-03-23T19:35:34.913Z (about 2 months ago)
- Topics: production-ready, terraform, terraform-aws, terraform-module, terraform-workspace
- Language: HCL
- Homepage: https://medium.com/aws-tip/managing-multiple-shadow-cloud-architectures-across-development-staging-and-production-17ff55390828
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TerraSample
TerraSample is a generic portfolio project demonstrating a modular approach to infrastructure management using Terraform. This project serves as a template for showcasing best practices and standard module organization for a two tier cloud infrastructure.
## Project Structure
```
.
├── README.md
├── main.tf
├── variables.tf
├── outputs.tf
├── modules/
│ ├── moduleA/
│ │ ├── README.md
│ │ ├── variables.tf
│ │ ├── main.tf
│ │ ├── outputs.tf
│ ├── moduleB/
│ └── ...
```## Getting Started
### Prerequisites
### Setup AWS Credentials:
As a prerequisite first, we have to set AWS credentials for both our development and production AWS accounts
IAM configuration to `~/.aws/credentials`(For Mac) consisting of proper IAM permissions. For temporary credentials also
add the session key.
```
[dev]
aws_access_key_id =
aws_secret_access_key =[prod]
aws_access_key_id =
aws_secret_access_key =
aws_session_token=
```### Remote Backend & Variables
1.Backend Infra setup for example for s3+dynamodb:
`backend.tf`
```tf
terraform {
backend "s3" {
bucket = ""
encrypt = true
key = "path/terraform.tfstate"
region = ""
dynamodb_table = ""
}
}
```2. Key value .tfvars configuration file example with sensetive data:
`dev.tfvars`
```tfvars
# Generic variables
project = "terrasample"
aws_region = ""
profile = "terrasample-dev"
environment = "dev"
```### Initialize the Project
```bash
terraform init
```### Basic Terraform Commands
## Basic Terraform Commands
### Changing Environment in Terraform:
Select development environment:
```bash
terraform workspace select dev
```Select production environment:
```bash
terraform workspace select prod
```#### Plan:
```bash
# For Development Environment
terraform workspace select dev && terraform plan -var-file="dev.tfvars"
# For Production Environment
terraform workspace select dev && terraform plan -var-file="prod.tfvars"
```#### Apply:
```bash
# For Development Environment
terraform workspace select dev && terraform apply -var-file="dev.tfvars"
# For Production Environment
terraform workspace select dev && terraform apply -var-file="prod.tfvars"
```