Skip to content

Commit 627548e

Browse files
authored
Improve examples (#19)
* Improve examples * Fix docs * Improve CI * Fix CI
1 parent 21d2d3f commit 627548e

File tree

13 files changed

+74
-38
lines changed

13 files changed

+74
-38
lines changed

.github/workflows/master.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ jobs:
1919

2020
- name: "make test"
2121
run: |
22-
make test ARGS="-var aws_account_id_hub=${TF_VAR_aws_account_id_hub} -var aws_account_id_satellite=[${TF_VAR_aws_account_id_satellite}]"
22+
make test ARGS="-var role_to_assume_hub=${TF_VAR_role_to_assume} -var aws_account_id_hub=${TF_VAR_aws_account_id_hub} -var role_to_assume_satellite=${TF_VAR_role_to_assume} -var aws_account_id_satellite=[${TF_VAR_aws_account_id_satellite}]"
2323
env:
2424
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
2525
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
2626
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27-
TF_VAR_aws_account_id_hub: ${{ secrets.aws_account_id_hub }}
28-
TF_VAR_aws_account_id_satellite: ${{ secrets.aws_account_id_satellite }}
27+
TF_VAR_role_to_assume: ${{ secrets.ROLE_TO_ASSUME }}
28+
TF_VAR_aws_account_id_hub: ${{ secrets.AWS_ACCOUNT_ID_HUB }}
29+
TF_VAR_aws_account_id_satellite: ${{ secrets.AWS_ACCOUNT_ID_SATELLITE }}

.github/workflows/terraform.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ jobs:
4040

4141
- name: "make test"
4242
run: |
43-
make test ARGS="-var aws_account_id_hub=${TF_VAR_aws_account_id_hub} -var aws_account_id_satellite=[${TF_VAR_aws_account_id_satellite}]"
43+
make test ARGS="-var role_to_assume_hub=${TF_VAR_role_to_assume} -var aws_account_id_hub=${TF_VAR_aws_account_id_hub} -var role_to_assume_satellite=${TF_VAR_role_to_assume} -var aws_account_id_satellite=${TF_VAR_aws_account_id_satellite}"
4444
env:
4545
AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }}
4646
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
4747
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
48-
TF_VAR_aws_account_id_hub: ${{ secrets.aws_account_id_hub }}
49-
TF_VAR_aws_account_id_satellite: ${{ secrets.aws_account_id_satellite }}
48+
TF_VAR_role_to_assume: ${{ secrets.ROLE_TO_ASSUME }}
49+
TF_VAR_aws_account_id_hub: ${{ secrets.AWS_ACCOUNT_ID_HUB }}
50+
TF_VAR_aws_account_id_satellite: ${{ secrets.AWS_ACCOUNT_ID_SATELLITE }}

Makefile

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,46 @@ test: _pull-tf
104104
fi; \
105105
echo; \
106106
echo "------------------------------------------------------------"; \
107-
echo "# Terraform plan"; \
107+
echo "# Terraform plan (1/2)"; \
108+
echo "------------------------------------------------------------"; \
109+
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
110+
plan -target 'module.tgw-satellite.data.aws_route_tables.all' \
111+
$(ARGS) \
112+
-out=tfplan \
113+
; then \
114+
echo "OK"; \
115+
else \
116+
echo "Failed"; \
117+
docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ || true; \
118+
exit 1; \
119+
fi; \
120+
echo; \
121+
echo "------------------------------------------------------------"; \
122+
echo "# Terraform apply (1/2)"; \
123+
echo "------------------------------------------------------------"; \
124+
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
125+
apply -target 'module.tgw-satellite.data.aws_route_tables.all' \
126+
-auto-approve \
127+
tfplan \
128+
; then \
129+
echo "Apply OK"; \
130+
else \
131+
echo "Apply failed"; \
132+
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
133+
destroy \
134+
-auto-approve \
135+
$(ARGS) \
136+
; then \
137+
echo "Destroy OK"; \
138+
docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" --workdir "$${DOCKER_PATH}" --entrypoint=rm hashicorp/terraform:$(TF_VERSION) -rf .terraform/ terraform.tfstate terraform.tfstate.backup || true; \
139+
else \
140+
echo "Destroy failed. You should check for dangling resources."; \
141+
exit 1; \
142+
fi; \
143+
fi; \
144+
echo; \
145+
echo "------------------------------------------------------------"; \
146+
echo "# Terraform plan (2/2)"; \
108147
echo "------------------------------------------------------------"; \
109148
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
110149
plan \
@@ -119,7 +158,7 @@ test: _pull-tf
119158
fi; \
120159
echo; \
121160
echo "------------------------------------------------------------"; \
122-
echo "# Terraform apply & destroy"; \
161+
echo "# Terraform apply (2/2) & destroy"; \
123162
echo "------------------------------------------------------------"; \
124163
if docker run $$(tty -s && echo "-it" || echo) --rm -v "$(CURRENT_DIR):/t" -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY --workdir "$${DOCKER_PATH}" hashicorp/terraform:$(TF_VERSION) \
125164
apply \
@@ -154,7 +193,6 @@ test: _pull-tf
154193
fi; \
155194
)
156195

157-
158196
# -------------------------------------------------------------------------------------------------
159197
# Helper Targets
160198
# -------------------------------------------------------------------------------------------------

examples/hub-and-satellite/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ No providers.
1212
| Name | Source | Version |
1313
|------|--------|---------|
1414
| <a name="module_tgw-hub"></a> [tgw-hub](#module\_tgw-hub) | ../../ | n/a |
15-
| <a name="module_tgw-satellite"></a> [tgw-satellite](#module\_tgw-satellite) | github.com/Flaconi/terraform-aws-transit-gateway-satellite.git | v2.5.0 |
15+
| <a name="module_tgw-satellite"></a> [tgw-satellite](#module\_tgw-satellite) | github.com/Flaconi/terraform-aws-transit-gateway-satellite.git | v2.6.0 |
1616

1717
## Resources
1818

@@ -24,7 +24,7 @@ No resources.
2424
|------|-------------|------|---------|:--------:|
2525
| <a name="input_attachment_subnet_filters"></a> [attachment\_subnet\_filters](#input\_attachment\_subnet\_filters) | List of maps selecting the subnet(s) where TGW will be attached | <pre>list(object({<br> name = string<br> values = list(string)<br> }))</pre> | n/a | yes |
2626
| <a name="input_aws_account_id_hub"></a> [aws\_account\_id\_hub](#input\_aws\_account\_id\_hub) | AWS account number containing the TGW hub | `string` | n/a | yes |
27-
| <a name="input_aws_account_id_satellite"></a> [aws\_account\_id\_satellite](#input\_aws\_account\_id\_satellite) | List of AWS account numbers representing the satellites of the TGW | `list(string)` | n/a | yes |
27+
| <a name="input_aws_account_id_satellite"></a> [aws\_account\_id\_satellite](#input\_aws\_account\_id\_satellite) | AWS account ID representing the satellites of the TGW | `string` | n/a | yes |
2828
| <a name="input_description"></a> [description](#input\_description) | Description of the Transit Gateway | `string` | n/a | yes |
2929
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | n/a | yes |
3030
| <a name="input_role_to_assume_hub"></a> [role\_to\_assume\_hub](#input\_role\_to\_assume\_hub) | IAM role name to assume in the AWS account containing the TGW hub (eg. ASSUME-ROLE-HUB) | `string` | n/a | yes |

examples/hub-and-satellite/locals.tf

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/hub-and-satellite/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module "tgw-hub" {
99
description = var.description
1010

1111
aws_account_id_hub = var.aws_account_id_hub
12-
aws_account_id_satellite = var.aws_account_id_satellite
12+
aws_account_id_satellite = [var.aws_account_id_satellite]
1313

1414
allow_external_principals = true
1515
}
1616

1717
module "tgw-satellite" {
18-
source = "github.com/Flaconi/terraform-aws-transit-gateway-satellite.git?ref=v2.5.0"
18+
source = "github.com/Flaconi/terraform-aws-transit-gateway-satellite.git?ref=v2.6.0"
1919

2020
providers = {
2121
aws.satellite = aws.satellite
@@ -25,10 +25,7 @@ module "tgw-satellite" {
2525
satellite_create = var.satellite_create
2626

2727
aws_account_id_hub = var.aws_account_id_hub
28-
aws_account_id_satellite = local.aws_account_id_satellite
29-
30-
role_to_assume_hub = var.role_to_assume_hub
31-
role_to_assume_satellite = var.role_to_assume_satellite
28+
aws_account_id_satellite = var.aws_account_id_satellite
3229

3330
vpc_name_to_attach = var.vpc_name_to_attach
3431
attachment_subnet_filters = var.attachment_subnet_filters
@@ -39,4 +36,6 @@ module "tgw-satellite" {
3936
transit_gateway_route_table_id = module.tgw-hub.transit_gateway_route_table_id
4037
transit_gateway_id = module.tgw-hub.transit_gateway_id
4138
ram_resource_association_id = module.tgw-hub.ram_resource_association_id
39+
40+
depends_on = [module.tgw-hub]
4241
}

examples/hub-and-satellite/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ provider "aws" {
22
alias = "satellite"
33
region = "eu-central-1"
44
assume_role {
5-
role_arn = "arn:aws:iam::${local.aws_account_id_satellite}:role/${var.role_to_assume_satellite}"
5+
role_arn = "arn:aws:iam::${var.aws_account_id_satellite}:role/${var.role_to_assume_satellite}"
66
session_name = "tf-tgw-module-satellite"
77
}
88
}

examples/hub-and-satellite/variables.auto.tfvars

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ description = "test-tgw"
33

44
satellite_create = true
55

6-
role_to_assume_hub = "ASSUME-ENG-CI"
7-
role_to_assume_satellite = "ASSUME-ENG-CI"
8-
96
vpc_name_to_attach = "ci-tgw"
107

118
satellite_destination_cidr_blocks = ["208.67.222.222/32", "208.67.220.220/32"]

examples/hub-and-satellite/variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ variable "aws_account_id_hub" {
1919
type = string
2020
}
2121

22-
variable "aws_account_id_satellite" {
23-
description = "List of AWS account numbers representing the satellites of the TGW"
24-
type = list(string)
25-
}
26-
2722
variable "role_to_assume_hub" {
2823
description = "IAM role name to assume in the AWS account containing the TGW hub (eg. ASSUME-ROLE-HUB)"
2924
type = string
3025
}
3126

27+
variable "aws_account_id_satellite" {
28+
description = "AWS account ID representing the satellites of the TGW"
29+
type = string
30+
}
31+
3232
variable "role_to_assume_satellite" {
3333
description = "IAM role name to assume in the AWS account containing the TGW satellite (eg. ASSUME-ROLE-SATELLITE)"
3434
type = string

examples/hub/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ No resources.
2222
| Name | Description | Type | Default | Required |
2323
|------|-------------|------|---------|:--------:|
2424
| <a name="input_aws_account_id_hub"></a> [aws\_account\_id\_hub](#input\_aws\_account\_id\_hub) | AWS account number containing the TGW hub | `string` | n/a | yes |
25-
| <a name="input_aws_account_id_satellite"></a> [aws\_account\_id\_satellite](#input\_aws\_account\_id\_satellite) | List of AWS account numbers representing the satellites of the TGW | `list(string)` | n/a | yes |
25+
| <a name="input_aws_account_id_satellite"></a> [aws\_account\_id\_satellite](#input\_aws\_account\_id\_satellite) | AWS account ID representing the satellites of the TGW | `string` | n/a | yes |
2626
| <a name="input_description"></a> [description](#input\_description) | Description of the Transit Gateway | `string` | n/a | yes |
2727
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | n/a | yes |
2828
| <a name="input_role_to_assume_hub"></a> [role\_to\_assume\_hub](#input\_role\_to\_assume\_hub) | IAM role name to assume in the AWS account containing the TGW hub (eg. ASSUME-ROLE-HUB) | `string` | n/a | yes |
29+
| <a name="input_role_to_assume_satellite"></a> [role\_to\_assume\_satellite](#input\_role\_to\_assume\_satellite) | IAM role name to assume in the AWS account containing the TGW satellite (eg. ASSUME-ROLE-SATELLITE) | `string` | `null` | no |
2930
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
3031

3132
## Outputs

0 commit comments

Comments
 (0)