Skip to content

Commit

Permalink
dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMGirard committed Jan 30, 2023
1 parent d767fd2 commit 410c59d
Show file tree
Hide file tree
Showing 34 changed files with 444 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.terraform.lock.hcl

# =========================================
/.env/
/venv/
/volume/

**/.terraform/
Expand Down
1 change: 0 additions & 1 deletion 2-features/dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
providers.tf
versions.tf
dependencies.png
32 changes: 27 additions & 5 deletions 2-features/dependencies/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
# Dependencies

- backend-app depends on mysql, redis, and vpc
- frontend-app depends on backend-app and vpc
- mysql depends on vpc
- redis depends on vpc
- vpc has no dependencies

```bash
terragrunt graph-dependencies | dot -Tpng > dependencies.png
```

![img.png](dependencies.png)

------------------------------------

## Run it

```bash
export TERRAGRUNT_PARALLELISM=4

terragrunt run-all plan
terragrunt run-all apply
terragrunt run-all destroy
```

- The module 1 has no dependency
- The module 2 depends on module 1
- The module 3 must be build after module 1 but do not need its outputs
- The module 4 depends on module 1, 2 and 3
<br/>

#### Includes backend and the ones it depends on

```bash
terragrunt run-all \
--terragrunt-include-external-dependencies \
--terragrunt-working-dir ./backend \
apply
```

<br/>

30 changes: 30 additions & 0 deletions 2-features/dependencies/backend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


variable "vpc_name" {
type = string
default = "my-vpc-1"
}
variable "redis_arn" {
type = string
}
variable "mysql_arn" {
type = string
}


resource aws_s3_bucket "main" {
bucket = join("-", [var.vpc_name, "backend"])
}

output "arn" {
value = aws_s3_bucket.main.arn
}
output "name" {
value = aws_s3_bucket.main.bucket
}
output "redis_arn" {
value = var.redis_arn
}
output "mysql_arn" {
value = var.mysql_arn
}
32 changes: 32 additions & 0 deletions 2-features/dependencies/backend/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

# ignore for now
include "root" {
path = find_in_parent_folders()
}


dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
name = ""
}
}
dependency "redis" {
config_path = "../redis"
mock_outputs = {
arn = ""
}
}
dependency "mysql" {
config_path = "../mysql"
mock_outputs = {
arn = ""
}
}

inputs = {
vpc_name = dependency.vpc.outputs.name
redis_arn = dependency.redis.outputs.arn
mysql_arn = dependency.mysql.outputs.arn
}

Binary file added 2-features/dependencies/dependencies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions 2-features/dependencies/frontend/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@




resource aws_s3_bucket "main" {
bucket = "frontend"
}

output "arn" {
value = aws_s3_bucket.main.arn
}
output "name" {
value = aws_s3_bucket.main.bucket
}
14 changes: 14 additions & 0 deletions 2-features/dependencies/frontend/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# ignore for now
include "root" {
path = find_in_parent_folders()
}

dependencies {
paths = ["../vpc", "../backend"]
}





18 changes: 18 additions & 0 deletions 2-features/dependencies/mysql/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@



variable "vpc_name" {
type = string
default = "my-vpc-1"
}

resource aws_s3_bucket "main" {
bucket = join("-", [var.vpc_name, "mysql"])
}

output "arn" {
value = aws_s3_bucket.main.arn
}
output "name" {
value = aws_s3_bucket.main.bucket
}
21 changes: 21 additions & 0 deletions 2-features/dependencies/mysql/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ignore for now
include "root" {
path = find_in_parent_folders()
}


dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
arn = ""
name = ""
}
}

inputs = {
vpc_name = dependency.vpc.outputs.name
}



17 changes: 17 additions & 0 deletions 2-features/dependencies/redis/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


variable "vpc_name" {
type = string
default = "my-vpc-1"
}

resource aws_s3_bucket "main" {
bucket = join("-", [var.vpc_name, "redis"])
}

output "arn" {
value = aws_s3_bucket.main.arn
}
output "name" {
value = aws_s3_bucket.main.bucket
}
21 changes: 21 additions & 0 deletions 2-features/dependencies/redis/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ignore for now
include "root" {
path = find_in_parent_folders()
}


dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
arn = ""
name = ""
}
}

inputs = {
vpc_name = dependency.vpc.outputs.name
}



17 changes: 17 additions & 0 deletions 2-features/dependencies/vpc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


variable "name" {
type = string
default = "my-vpc-1"
}

resource aws_s3_bucket "main" {
bucket = var.name
}

output "arn" {
value = aws_s3_bucket.main.arn
}
output "name" {
value = aws_s3_bucket.main.bucket
}
13 changes: 13 additions & 0 deletions 2-features/dependencies/vpc/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# ignore for now
include "root" {
path = find_in_parent_folders()
}


inputs = {
name = "vpc1"
}



12 changes: 12 additions & 0 deletions 2-features/inheritance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@
```bash
terragrunt run-all plan
```


<br/>

#### Includes those that include a file

```bash
# Includes the ones module-2 depends on
terragrunt run-all \
--terragrunt-modules-that-include ./prod/terragrunt.hcl \
apply
```
2 changes: 1 addition & 1 deletion 2-features/inheritance/prod/module-1/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


include "env" {
include "root" {
path = find_in_parent_folders("terragrunt.hcl")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ resource aws_s3_bucket "main" {
output "s3_bucket_arn" {
value = aws_s3_bucket.main.arn
}
output "s3_bucket_name" {
value = aws_s3_bucket.main.bucket
}
40 changes: 40 additions & 0 deletions 2-features/s3/module-1/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
provider "aws" {
access_key = "test"
secret_key = "test"
region = "us-east-1"

# only required for non virtual hosted-style endpoint use case.
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs#s3_use_path_style
s3_use_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true


endpoints {
apigateway = "http://localhost:4566"
apigatewayv2 = "http://localhost:4566"
cloudformation = "http://localhost:4566"
cloudwatch = "http://localhost:4566"
dynamodb = "http://localhost:4566"
ec2 = "http://localhost:4566"
es = "http://localhost:4566"
elasticache = "http://localhost:4566"
firehose = "http://localhost:4566"
iam = "http://localhost:4566"
kinesis = "http://localhost:4566"
lambda = "http://localhost:4566"
rds = "http://localhost:4566"
redshift = "http://localhost:4566"
route53 = "http://localhost:4566"
s3 = "http://s3.localhost.localstack.cloud:4566"
secretsmanager = "http://localhost:4566"
ses = "http://localhost:4566"
sns = "http://localhost:4566"
sqs = "http://localhost:4566"
ssm = "http://localhost:4566"
stepfunctions = "http://localhost:4566"
sts = "http://localhost:4566"
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions 2-features/s3/module-1/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
terraform {
required_version = ">= 0.12.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.52.0"
}
}
}
File renamed without changes.
40 changes: 40 additions & 0 deletions 2-features/s3/module-2/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
provider "aws" {
access_key = "test"
secret_key = "test"
region = "us-east-1"

# only required for non virtual hosted-style endpoint use case.
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs#s3_use_path_style
s3_use_path_style = true
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true


endpoints {
apigateway = "http://localhost:4566"
apigatewayv2 = "http://localhost:4566"
cloudformation = "http://localhost:4566"
cloudwatch = "http://localhost:4566"
dynamodb = "http://localhost:4566"
ec2 = "http://localhost:4566"
es = "http://localhost:4566"
elasticache = "http://localhost:4566"
firehose = "http://localhost:4566"
iam = "http://localhost:4566"
kinesis = "http://localhost:4566"
lambda = "http://localhost:4566"
rds = "http://localhost:4566"
redshift = "http://localhost:4566"
route53 = "http://localhost:4566"
s3 = "http://s3.localhost.localstack.cloud:4566"
secretsmanager = "http://localhost:4566"
ses = "http://localhost:4566"
sns = "http://localhost:4566"
sqs = "http://localhost:4566"
ssm = "http://localhost:4566"
stepfunctions = "http://localhost:4566"
sts = "http://localhost:4566"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependency "module_1" {
}

inputs = {
bucket_name = join("-", [dependency.module_1.outputs.s3_bucket_arn, "-logs"])
bucket_name = join("-", [dependency.module_1.outputs.s3_bucket_name, "logs"])
}


Expand Down
Loading

0 comments on commit 410c59d

Please sign in to comment.