Skip to content

Commit ad8b8c9

Browse files
Merge pull request #24 from htc-demo-00/cleanup
chore: tflint and cleanup
2 parents 60e55c7 + 4a91ec3 commit ad8b8c9

File tree

16 files changed

+199
-319
lines changed

16 files changed

+199
-319
lines changed

.github/workflows/ci.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install terraform-docs
2121
run: |
2222
WORK_DIR=$(mktemp -d)
23-
curl -Lo ${WORK_DIR}/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-$(uname)-amd64.tar.gz
23+
curl -Lo ${WORK_DIR}/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.18.0/terraform-docs-v0.18.0-$(uname)-amd64.tar.gz
2424
cd ${WORK_DIR}
2525
tar -xzf terraform-docs.tar.gz
2626
chmod +x terraform-docs
@@ -31,11 +31,14 @@ jobs:
3131
- name: Check git diff is clean (all files generated should be committed)
3232
run: git diff --exit-code
3333

34-
- name: Terraform Format Check
35-
run: make fmt-check
34+
- uses: terraform-linters/setup-tflint@v4
35+
with:
36+
tflint_version: v0.51.1
37+
- name: Terraform Lint
38+
run: make lint
3639

3740
- name: Stub GitHub App credentials (required for validation)
38-
run: cd ./examples/with-backstage && STUB_FILE=1 node create-gh-app/index.js
41+
run: cd ./examples/with-backstage && docker run --rm -e STUB_FILE=1 -v $(pwd):/pwd ghcr.io/humanitec-architecture/create-gh-app
3942

4043
- name: Terraform Validate
4144
run: make validate

.tflint.hcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugin "terraform" {
2+
enabled = true
3+
preset = "recommended"
4+
}
5+
6+
plugin "aws" {
7+
enabled = true
8+
version = "0.31.0"
9+
source = "github.com/terraform-linters/tflint-ruleset-aws"
10+
}

Makefile

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
TF_DIRS = $(patsubst %/main.tf, %, $(shell find . -type d -name .terraform -prune -o -name 'main.tf' -print))
22
VALIDATE_TF_DIRS = $(addprefix validate-,$(TF_DIRS))
3+
LINT_TF_DIRS = $(addprefix lint-,$(TF_DIRS))
4+
DOCS_TF_DIRS = $(addprefix docs-,$(TF_DIRS))
5+
6+
# Generate docs for a terraform directories
7+
$(DOCS_TF_DIRS): docs-%:
8+
@echo "Docs $*"
9+
terraform-docs --config docs/.terraform-docs.yaml $*
10+
terraform-docs --config docs/.terraform-docs-example.yaml $*
311

412
# Generate docs
513
.PHONY: docs
6-
docs:
7-
terraform-docs --lockfile=false ./modules/base
8-
terraform-docs --config docs/.terraform-docs.yaml .
9-
terraform-docs --config docs/.terraform-docs-example.yaml .
10-
terraform-docs --config docs/.terraform-docs.yaml ./examples/with-backstage
11-
terraform-docs --config docs/.terraform-docs-example.yaml ./examples/with-backstage
14+
docs: $(DOCS_TF_DIRS)
15+
@echo "All docs generated"
1216

1317
# Format all terraform files
1418
fmt:
@@ -27,3 +31,16 @@ $(VALIDATE_TF_DIRS): validate-%:
2731
# Validate all terraform directories
2832
validate: $(VALIDATE_TF_DIRS)
2933
@echo "All validated"
34+
35+
# Lint a terraform directories
36+
$(LINT_TF_DIRS): lint-%:
37+
@echo "Lint $*"
38+
tflint --config "$(PWD)/.tflint.hcl" --chdir="$*"
39+
40+
# Initialize tflint
41+
lint-init:
42+
tflint --init
43+
44+
# Lint all terraform directories
45+
lint: lint-init $(LINT_TF_DIRS) fmt-check
46+
@echo "All linted"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ Once you are finished with the reference architecture, you can remove all provis
184184
|------|---------|
185185
| terraform | >= 1.3.0 |
186186
| aws | ~> 5.17 |
187+
| helm | ~> 2.12 |
187188
| humanitec | ~> 1.0 |
189+
| kubernetes | ~> 2.25 |
188190

189191
### Modules
190192

examples/with-backstage/README.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,30 @@ Provisions the AWS reference architecture connected to Humanitec and installs Ba
55
## Prerequisites
66

77
* The same prerequisites as the [base reference architecture](../../README.md#prerequisites), plus the following items.
8-
* A GitHub organization and permission to create new repositories in it. Go to https://github.com/account/organizations/new to create a new org (the "Free" option is fine). Note: is has to be an organization, a free account is not sufficient.
8+
* A GitHub organization and permission to create new repositories in it. Go to <https://github.com/account/organizations/new> to create a new org (the "Free" option is fine). Note: is has to be an organization, a free account is not sufficient.
99
* Create a classic github personal access token with `repo`, `workflow`, `delete_repo` and `admin:org` scope [here](https://github.com/settings/tokens).
1010
* Set the `GITHUB_TOKEN` environment variable to your token.
11-
```
11+
12+
```bash
1213
export GITHUB_TOKEN="my-github-token"
1314
```
15+
1416
* Set the `GITHUB_ORG_ID` environment variable to your GitHub organization ID.
15-
```
17+
18+
```bash
1619
export GITHUB_ORG_ID="my-github-org-id"
1720
```
21+
1822
* [Node.js](https://nodejs.org) installed locally.
19-
* Install the GitHub App for Backstage into your GitHub organization using `node create-gh-app/index.js`. Follow the instructions.
20-
* “All repositories” ~> Install
21-
* “Okay, [] was installed on the [] account.” ~> You can close the window and server.
23+
* Install the GitHub App for Backstage into your GitHub organization
24+
* Run `docker run --rm -it -e GITHUB_ORG_ID -v $(pwd):/pwd -p 127.0.0.1:3000:3000 ghcr.io/humanitec-architecture/create-gh-app` ([image source](https://github.com/humanitec-architecture/create-gh-app/)) and follow the instructions:
25+
* “All repositories” ~> Install
26+
* “Okay, [] was installed on the [] account.” ~> You can close the window and server.
2227

2328
## Usage
2429

2530
Follow the same steps as for the [base layer](../../README.md#usage), applying these modifications:
31+
2632
* Execute `cd ./examples/with-backstage` after cloning the repo. Execute all subsequent commands in this directory.
2733
* In particular, use the `./examples/with-backstage/terraform.tfvars.example` file as the basis for your `terraform.tfvars` file. It defines additional variables needed to setup and configure Backstage.
2834

@@ -32,31 +38,38 @@ Check for the existence of key elements of the backstage module. This is a subse
3238

3339
1. Perform the [verification steps of the base installation](../../README.md) if you have not already done so.
3440
2. Verify the existence of the Backstage Application in your Humanitec Organization:
41+
3542
```
3643
curl -s https://api.humanitec.io/orgs/${HUMANITEC_ORG}/apps/backstage \
3744
--header "Authorization: Bearer ${HUMANITEC_TOKEN}"
3845
```
46+
3947
This should output a JSON formatted representation of the Application like so:
48+
4049
```
4150
{"id":"backstage","name":"backstage","created_at":"2023-10-02T13:44:27Z","created_by":"s-d3e94a0e-8b53-29f9-b666-27548b7e06e0","envs":[{"id":"development","name":"Development","type":"development"}]}
4251
```
52+
4353
You can also check for the Application in the [Humanitec Platform Orchestrator UI](https://app.humanitec.io).
4454

4555
3. Connect to your EKS cluster via `kubectl`. See the [AWS documentation](https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html) or use this command:
56+
4657
```
4758
aws eks update-kubeconfig --region <my-aws-region> --name ref-arch
4859
```
60+
4961
4. Get the elements in the newly created Kubernetes namespace:
62+
5063
```
5164
kubectl get all -n backstage-development
5265
```
66+
5367
You should see
54-
- a `deployment`, `replicaset`, running `pod`, and `service` for Backstage
55-
- a `statefulset`, running `pod`, and `service` for PostgreSQL database used by Backstage.
68+
* a `deployment`, `replicaset`, running `pod`, and `service` for Backstage
69+
* a `statefulset`, running `pod`, and `service` for PostgreSQL database used by Backstage.
5670

5771
Note: it may take up to ten minutes after the `terraform apply` completed until you actually see those resources. The Backstage application needs to built and deployed via a GitHub action out of the newly created repository in your GitHub organization.
5872

59-
6073
## Cleaning up
6174

6275
Once you are finished with the reference architecture, you can remove all provisioned infrastrcuture and the resource definitions created in Humanitec with the following:
@@ -75,7 +88,9 @@ Once you are finished with the reference architecture, you can remove all provis
7588
| terraform | >= 1.3.0 |
7689
| aws | ~> 5.17 |
7790
| github | ~> 5.38 |
91+
| helm | ~> 2.12 |
7892
| humanitec | ~> 1.0 |
93+
| kubernetes | ~> 2.25 |
7994
| random | ~> 3.5 |
8095

8196
### Providers
@@ -92,12 +107,8 @@ Once you are finished with the reference architecture, you can remove all provis
92107
| Name | Source | Version |
93108
|------|--------|---------|
94109
| backstage\_ecr | terraform-aws-modules/ecr/aws | ~> 1.6 |
95-
| backstage\_iam\_policy\_ecr\_create\_repository | git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/iam-policy/ecr-create-repository | n/a |
96-
| backstage\_iam\_role\_service\_account | git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/iam-role/service-account | n/a |
97-
| backstage\_k8s\_service\_account | git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/k8s/service-account | n/a |
98-
| backstage\_mysql | git::https://github.com/humanitec-architecture/resource-packs-in-cluster.git//humanitec-resource-defs/mysql/basic | n/a |
99-
| backstage\_postgres | git::https://github.com/humanitec-architecture/resource-packs-in-cluster.git//humanitec-resource-defs/postgres/basic | n/a |
100-
| backstage\_workload | git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/workload/service-account | n/a |
110+
| backstage\_mysql | github.com/humanitec-architecture/resource-packs-in-cluster | v2024-06-05//humanitec-resource-defs/mysql/basic |
111+
| backstage\_postgres | github.com/humanitec-architecture/resource-packs-in-cluster | v2024-06-05//humanitec-resource-defs/postgres/basic |
101112
| base | ../../modules/base | n/a |
102113
| iam\_github\_oidc\_provider | terraform-aws-modules/iam/aws//modules/iam-github-oidc-provider | ~> 5.30 |
103114
| iam\_github\_oidc\_role | terraform-aws-modules/iam/aws//modules/iam-github-oidc-role | ~> 5.30 |
@@ -114,12 +125,8 @@ Once you are finished with the reference architecture, you can remove all provis
114125
| [github_actions_organization_variable.backstage_humanitec_org_id](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/actions_organization_variable) | resource |
115126
| [github_repository.backstage](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository) | resource |
116127
| [humanitec_application.backstage](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource |
117-
| [humanitec_resource_definition_criteria.backstage_iam_policy_ecr_create_repository](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
118-
| [humanitec_resource_definition_criteria.backstage_iam_role_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
119-
| [humanitec_resource_definition_criteria.backstage_k8s_service_account](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
120128
| [humanitec_resource_definition_criteria.backstage_mysql](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
121129
| [humanitec_resource_definition_criteria.backstage_postgres](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
122-
| [humanitec_resource_definition_criteria.backstage_workload](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource |
123130
| [humanitec_value.app_config_backend_auth_keys](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
124131
| [humanitec_value.aws_default_region](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
125132
| [humanitec_value.backstage_cloud_provider](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/value) | resource |
@@ -144,5 +151,4 @@ Once you are finished with the reference architecture, you can remove all provis
144151
| humanitec\_org\_id | Humanitec Organization ID | `string` | n/a | yes |
145152
| disk\_size | Disk size in GB to use for EKS nodes | `number` | `20` | no |
146153
| instance\_types | List of EC2 instances types to use for EKS nodes | `list(string)` | <pre>[<br> "t3.large"<br>]</pre> | no |
147-
| resource\_packs\_aws\_rev | Revision of the resource-packs-aws repository to use | `string` | `"refs/heads/main"` | no |
148154
<!-- END_TF_DOCS -->

examples/with-backstage/backstage-humanitec.tf

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ locals {
108108
# in-cluster postgres
109109

110110
module "backstage_postgres" {
111-
source = "git::https://github.com/humanitec-architecture/resource-packs-in-cluster.git//humanitec-resource-defs/postgres/basic"
111+
source = "github.com/humanitec-architecture/resource-packs-in-cluster?ref=v2024-06-05//humanitec-resource-defs/postgres/basic"
112112

113113
prefix = local.res_def_prefix
114114
}
@@ -120,84 +120,12 @@ resource "humanitec_resource_definition_criteria" "backstage_postgres" {
120120
force_delete = true
121121
}
122122

123-
# k8s service account (to assume an AWS role)
124-
125-
module "backstage_k8s_service_account" {
126-
source = "git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/k8s/service-account"
127-
128-
prefix = local.res_def_prefix
129-
}
130-
131-
resource "humanitec_resource_definition_criteria" "backstage_k8s_service_account" {
132-
resource_definition_id = module.backstage_k8s_service_account.id
133-
app_id = humanitec_application.backstage.id
134-
135-
force_delete = true
136-
}
137-
138-
# AWS policy to create ECR repositories (required to scaffold apps)
139-
140-
module "backstage_iam_policy_ecr_create_repository" {
141-
source = "git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/iam-policy/ecr-create-repository"
142-
143-
driver_account = module.base.humanitec_resource_account_id
144-
resource_packs_aws_rev = var.resource_packs_aws_rev
145-
region = var.aws_region
146-
147-
prefix = local.res_def_prefix
148-
}
149-
150-
resource "humanitec_resource_definition_criteria" "backstage_iam_policy_ecr_create_repository" {
151-
resource_definition_id = module.backstage_iam_policy_ecr_create_repository.id
152-
app_id = humanitec_application.backstage.id
153-
154-
force_delete = true
155-
}
156-
157-
# AWS role assumable by the k8s service account
158-
159-
module "backstage_iam_role_service_account" {
160-
source = "git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/iam-role/service-account"
161-
162-
driver_account = module.base.humanitec_resource_account_id
163-
resource_packs_aws_rev = var.resource_packs_aws_rev
164-
region = var.aws_region
165-
166-
policy_classes = ["default"]
167-
168-
cluster_name = module.base.eks_cluster_name
169-
prefix = local.res_def_prefix
170-
}
171-
172-
resource "humanitec_resource_definition_criteria" "backstage_iam_role_service_account" {
173-
resource_definition_id = module.backstage_iam_role_service_account.id
174-
app_id = humanitec_application.backstage.id
175-
176-
force_delete = true
177-
}
178-
179-
# Workload resource that sets the service account
180-
181-
module "backstage_workload" {
182-
source = "git::https://github.com/humanitec-architecture/resource-packs-aws.git//humanitec-resource-defs/workload/service-account"
183-
184-
prefix = local.res_def_prefix
185-
}
186-
187-
resource "humanitec_resource_definition_criteria" "backstage_workload" {
188-
resource_definition_id = module.backstage_workload.id
189-
app_id = humanitec_application.backstage.id
190-
191-
force_delete = true
192-
}
193-
194-
195123
# Configure required resources for scaffolded apps
196124

197125
# in-cluster mysql
198126

199127
module "backstage_mysql" {
200-
source = "git::https://github.com/humanitec-architecture/resource-packs-in-cluster.git//humanitec-resource-defs/mysql/basic"
128+
source = "github.com/humanitec-architecture/resource-packs-in-cluster?ref=v2024-06-05//humanitec-resource-defs/mysql/basic"
201129

202130
prefix = local.res_def_prefix
203131
}

0 commit comments

Comments
 (0)