Skip to content

Commit a26bbde

Browse files
authored
Merge pull request #52 from arunlalp/master
Update .gitignore and README for improved clarity and structure
2 parents 489fe6d + 547cb82 commit a26bbde

File tree

5 files changed

+596
-576
lines changed

5 files changed

+596
-576
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ override.tf.json
2828

2929
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
3030
# example: *tfplan*
31-
.DS_Store
31+
.DS_Store
32+
33+
scripts

README.md

Lines changed: 129 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,201 @@
1-
# terraform-awsAdd commentMore actions
2-
Terraform AWS provisioning examples for beginners
1+
# terraform-aws
32

4-
## Hit the Star! ⭐
5-
If you are planning to use this Terraform repo for learning, please hit the star. Thanks!
3+
Examples for provisioning AWS with Terraform using simple environment layouts.
64

7-
## Terraform Init With s3 Backend
5+
If this repo helps you, please ⭐ it.
86

9-
```
10-
terraform init \
11-
-backend-config="key=dev/vpc.tfstate" \
12-
-backend-config="bucket=dcube-terraform-state" \
13-
-backend-config="region=us-west-2" \
14-
-backend-config="dynamodb_table=terraform-state-lock" \
15-
-var-file=../../../vars/dev/vpc.tfvars
16-
```
7+
---
178

18-
#### VPC Provisioning
9+
## Table of Contents
1910

20-
cd into the `environments/dev/vpc` directory and run the following commands:
11+
- [Prerequisites](#prerequisites)
12+
- [Init with S3 Backend](#init-with-s3-backend)
13+
- [VPC Provisioning](#vpc-provisioning)
14+
- [RDS Provisioning](#rds-provisioning)
15+
- [ALB + ASG Provisioning](#alb--asg-provisioning)
16+
- [EC2 Provisioning](#ec2-provisioning)
17+
- [AWS Organization Tag Policy](#aws-organization-tag-policy)
18+
- [Terraform Command Reference](#terraform-command-reference)
19+
- [Notes](#notes)
2120

22-
1. Init Terraform in the directory `environments/dev/vpc`
21+
---
2322

24-
```
25-
terraform init
26-
```
27-
2. To preview the changes in code
23+
## Prerequisites
2824

29-
```
30-
terraform plan -var-file=../../../vars/dev/vpc.tfvars
31-
```
32-
3. To apply the changes
25+
- Terraform installed
26+
- AWS credentials configured (e.g., `aws configure`)
27+
- S3 bucket and DynamoDB table for remote state and locking (if using the backend example)
3328

34-
```
35-
terraform apply -var-file=../../../vars/dev/vpc.tfvars
36-
```
37-
4. To destroy the resources created using the code
29+
---
3830

39-
```
40-
terraform destroy -var-file=../../../vars/dev/vpc.tfvars
4131

32+
## Init with S3 Backend
4233

43-
#### RDS Provisioning
34+
Use this when your workspace uses an S3 remote backend with DynamoDB locking.
4435

45-
cd into the `environments/dev/rds` directory and run the following commands:
36+
```sh
37+
terraform init \
38+
-backend-config="key=dev/vpc.tfstate" \
39+
-backend-config="bucket=dcube-terraform-state" \
40+
-backend-config="region=us-west-2" \
41+
-backend-config="dynamodb_table=terraform-state-lock" \
42+
-var-file=../../../vars/dev/vpc.tfvars
43+
````
4644

47-
1. Init Terraform in the directory `environments/dev/rds`
45+
> Adjust `key`, `bucket`, `region`, and `dynamodb_table` to your setup.
4846

49-
```
47+
---
48+
49+
## VPC Provisioning
50+
51+
From `environments/dev/vpc`:
52+
53+
```sh
54+
# 1) Initialize
5055
terraform init
51-
```
52-
2. To preview the changes in code
5356
54-
```
55-
terraform plan -var-file=../../../vars/dev/rds.tfvars
56-
```
57-
3. To apply the changes
57+
# 2) Preview
58+
terraform plan -var-file=../../../vars/dev/vpc.tfvars
5859
59-
```
60-
terraform apply -var-file=../../../vars/dev/rds.tfvars
61-
```
62-
4. To destroy the resources created using the code
60+
# 3) Apply
61+
terraform apply -var-file=../../../vars/dev/vpc.tfvars
6362
64-
```
65-
terraform destroy -var-file=../../../vars/dev/rds.tfvars
63+
# 4) Destroy (when needed)
64+
terraform destroy -var-file=../../../vars/dev/vpc.tfvars
6665
```
6766

68-
### ALB and ASG Provisioning
67+
---
6968

70-
cd into the `environments/dev/alb-asg` directory and run the following commands:
69+
## RDS Provisioning
7170

72-
1. Init Terraform in the directory `environments/dev/alb-asg`
71+
From `environments/dev/rds`:
7372

74-
```
73+
```sh
7574
terraform init
75+
terraform plan -var-file=../../../vars/dev/rds.tfvars
76+
terraform apply -var-file=../../../vars/dev/rds.tfvars
77+
terraform destroy -var-file=../../../vars/dev/rds.tfvars
7678
```
77-
2. To preview the changes in code
7879

79-
```
80-
terraform plan -var-file=../../../vars/dev/alb-asg.tfvars
81-
```
82-
3. To apply the changes
80+
---
8381

84-
```
85-
terraform apply -var-file=../../../vars/dev/alb-asg.tfvars
86-
```
87-
4. To destroy the resources created using the code
82+
## ALB + ASG Provisioning
8883

89-
```
84+
From `environments/dev/alb-asg`:
85+
86+
```sh
87+
terraform init
88+
terraform plan -var-file=../../../vars/dev/alb-asg.tfvars
89+
terraform apply -var-file=../../../vars/dev/alb-asg.tfvars
9090
terraform destroy -var-file=../../../vars/dev/alb-asg.tfvars
9191
```
9292

93-
## EC2 Instance Provisioning
93+
---
94+
95+
## EC2 Provisioning
9496

95-
1. Navigate to the `environment/dev` folder:
97+
From `environments/dev/ec2` (edit `vars/dev/ec2.tfvars` first):
9698

97-
```bash
98-
cd environment/dev
99+
```sh
100+
terraform init
101+
terraform plan -var-file=../../../vars/dev/ec2.tfvars
102+
terraform apply -var-file=../../../vars/dev/ec2.tfvars
103+
terraform destroy -var-file=../../../vars/dev/ec2.tfvars
99104
```
100105

101-
2. Open the `ec2.tfvars` file and modify it with your desired details. This file contains variables used in the Terraform configuration.
106+
> Always review the plan before applying.
102107

103-
### Deployment
108+
---
104109

105-
1. Initialize Terraform in the working directory:
110+
## AWS Organization Tag Policy
106111

107-
```bash
112+
From `environments/dev/tag-policy` (edit `vars/dev/tag-policy.tfvars` as needed):
113+
114+
```sh
108115
terraform init
116+
terraform plan -var-file=../../../vars/dev/tag-policy.tfvars
117+
terraform apply -var-file=../../../vars/dev/tag-policy.tfvars
118+
terraform destroy -var-file=../../../vars/dev/tag-policy.tfvars
109119
```
110120

111-
2. Create an execution plan:
121+
---
112122

113-
```bash
114-
terraform plan -var-file=../../../vars/dev/ec2.tfvars
115-
```
123+
## EKS + Karpenter Deployment
116124

117-
3. Apply the changes to create the EC2 instance:
125+
This section covers deploying an Amazon EKS cluster with Karpenter for dynamic node provisioning.
118126

119-
```bash
120-
terraform apply -var-file=../../../vars/dev/ec2.tfvars
121-
```
127+
### Prerequisites
122128

123-
4. To destroy the EC2 instance and associated resources:
129+
- AWS CLI configured with necessary permissions
130+
- `kubectl` installed
131+
- AWS IAM permissions for EKS and Karpenter operations
124132

125-
```bash
126-
terraform destroy -var-file=../../../vars/dev/ec2.tfvars
127-
```
133+
### 1. Deploy EKS Cluster
128134

129-
**Note**: Always review the execution plan (`terraform plan`) before applying changes to avoid unintended modifications.
135+
From `infra/eks-cluster`:
130136

131-
## AWS Organization Tag Policy Creation.
137+
```sh
138+
# Initialize with backend config
139+
terraform init
132140
133-
1. Navigate to the `environment/dev` folder:
141+
# Plan and review changes
142+
terraform plan -var-file=../../vars/dev/eks.tfvars
134143
135-
```bash
136-
cd environment/tag-policy
144+
# Apply the configuration
145+
terraform apply -var-file=../../vars/dev/eks.tfvars
137146
```
138147

139-
2. Open the `tag-policy.tfvars` file and modify it with your desired details. This file contains variables used in the Terraform configuration.
140-
141-
### Deployment
148+
### 2. Deploy Karpenter
142149

143-
1. Initialize Terraform in the working directory:
150+
From `infra/eks-karpenter`:
144151

145-
```bash
152+
```sh
153+
# Initialize with backend config
146154
terraform init
147-
```
148155
149-
2. Create an execution plan:
156+
# Plan and review changes
157+
terraform plan -var-file=../../vars/dev/karpenter.tfvars
150158
151-
```bash
152-
terraform plan -var-file=../../../vars/dev/tag-policy.tfvars
159+
# Apply the configuration
160+
terraform apply -var-file=../../vars/dev/karpenter.tfvars
153161
```
154162

155-
3. Apply the changes to create the Tag Policy:
163+
### 3. Verify Installation
156164

157-
```bash
158-
terraform apply -var-file=../../../vars/dev/tag-policy.tfvars
159-
```
165+
After deployment:
160166

161-
4. To destroy the Tag Policy:
167+
```sh
168+
# Update kubeconfig
169+
aws eks update-kubeconfig --region <your-region> --name <cluster-name>
162170
163-
```bash
164-
terraform destroy -var-file=../../../vars/dev/tag-policy.tfvars
171+
# Verify Karpenter pods
172+
kubectl get pods -n karpenter
165173
```
166174

167-
**Note**: Always review the execution plan (`terraform plan`) before applying changes to avoid unintended modifications.
175+
---
168176

169177
## Terraform Command Reference
170178

171-
Update all outputs:
179+
Refresh state (re-reads remote objects and updates outputs):
180+
181+
```sh
182+
terraform refresh
183+
```
184+
185+
Show current state and outputs:
186+
187+
```sh
188+
terraform show
189+
```
190+
191+
---
192+
193+
## Notes
172194

173-
<pre>terraform refresh</pre>
195+
* Run Terraform **inside** an environment folder (e.g., `environments/dev/vpc`).
196+
* Variable files live under `vars/dev/*.tfvars`.
197+
* Backend config values in examples are placeholders—change them to match your infra.
174198

175-
Show all outputs:
199+
---
176200

177-
<pre>terraform show</pre>
178201

infra/eks-karpenter/backend.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
backend "s3" {
33
bucket = "techies-terraform"
4-
key = "dev/eks/eks.tfstate"
4+
key = "dev/eks-karpenter/eks.tfstate"
55
region = "us-east-1"
66
use_lockfile = true
77
}

0 commit comments

Comments
 (0)