File tree 5 files changed +27
-3
lines changed
terraform/environments/aws-account-id
us-east-2/management/s3/terraform_state
5 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 5
5
* .tfstate
6
6
* .tfstate. *
7
7
8
+ * .terraform.lock.hcl
9
+
8
10
# Crash log files
9
11
crash.log
10
12
@@ -27,3 +29,7 @@ override.tf.json
27
29
28
30
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
29
31
# example: *tfplan*
32
+
33
+ # terragrunt
34
+ * .out
35
+ ** /.terragrunt-cache /*
Original file line number Diff line number Diff line change 1
1
# Infrastructure Example
2
2
This example was conceived as an infrastructure for one AWS account with one region and division into dev, management and prod environments.
3
+ But it can be extended for multiple regions, aws accounts and other clouds.
3
4
4
5
Current files structure:
5
6
```
@@ -19,10 +20,20 @@ terraform/modules/.gitkeep
19
20
```
20
21
21
22
Time track:
22
- - [ Filipp Frizzy] ( https://github.com/Friz-zy/ ) 11.5h
23
+ - [ Filipp Frizzy] ( https://github.com/Friz-zy/ ) 15.0h
23
24
24
25
## [ Terraform] ( https://www.terraform.io/ ) and [ Terragrunt] ( https://terragrunt.gruntwork.io )
25
26
In this setup I use terraform with terragrunt for provisioning whole infrastructure.
27
+ Terraform can store it's state in files or in remote backend via S3 or [ Terraform Cloud] ( https://cloud.hashicorp.com/products/terraform ) .
28
+ For command work we should use only remote state. In this setup I use AWS S3 ` terraform_state ` bucket + DynamoDB for locking.
29
+ This require some initial preparation:
30
+ ```
31
+ cd terraform/environments/aws-account-id/us-east-2/management/s3/terraform_state/
32
+ terraform init
33
+ terraform apply
34
+ sed -i "s/terraform_state_bucket/$(terraform output terraform_state_s3_bucket_name|sed 's/\"//g')/g" ../../../../backend.hcl
35
+ terragrunt init
36
+ ```
26
37
27
38
## [ Ansible] ( https://www.ansible.com/ )
28
39
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ remote_state {
5
5
if_exists = " overwrite_terragrunt"
6
6
}
7
7
config = {
8
- bucket = " terraform_state "
8
+ bucket = " terraform_state_bucket "
9
9
key = " ${ path_relative_to_include ()} /terraform.tfstate"
10
10
region = " us-east-2"
11
11
encrypt = true
Original file line number Diff line number Diff line change @@ -6,14 +6,17 @@ provider "aws" {
6
6
7
7
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket
8
8
resource "aws_s3_bucket" "terraform_state" {
9
- bucket_prefix = " terraform_state "
9
+ bucket_prefix = " terraform-state- "
10
10
11
11
tags = {
12
12
Name = " terraform_state"
13
13
Terraform = " terraform_state"
14
14
Environment = " management"
15
15
}
16
16
17
+ # change it for deleting bucket with all content
18
+ force_destroy = false
19
+
17
20
lifecycle {
18
21
prevent_destroy = true
19
22
}
Original file line number Diff line number Diff line change
1
+ output "terraform_state_s3_bucket_name" {
2
+ value = aws_s3_bucket. terraform_state . id
3
+ description = " The Name of the S3 bucket for terraform state"
4
+ }
You can’t perform that action at this time.
0 commit comments