From fe2de94023c74c0f95c4b64da46d838ded9bbfa6 Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:32:56 -0800 Subject: [PATCH 1/9] Some repo management fixes 1. Update the README 2. update generaterootmod so it programmatically gets the required provider version 3. remove the broken pre-commit-config in favor of `make ready` 4. fix the broken make ready command --- .pre-commit-config.yaml | 5 ++-- Makefile | 2 +- go.mod | 3 +++ tools/generaterootmod.go | 50 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 go.mod diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c79eaa9..aff23c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,9 @@ repos: - repo: https://github.com/gruntwork-io/pre-commit - rev: v0.1.10 + rev: v0.1.23 hooks: - id: terraform-fmt - id: gofmt - id: tflint args: - - "--module" - - "--config=.tflint.hcl" \ No newline at end of file + - --minimum-failure-severity=error \ No newline at end of file diff --git a/Makefile b/Makefile index 0414fc9..be7e8bc 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ fmt: check: terraform fmt -check -recursive - tflint --config .tflint.hcl --recursive --minimum-failure-severity=error + tflint --recursive --minimum-failure-severity=error clean: rm -rf .terraform* diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..31743ab --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module terraform-lightstep-aws-dashboards + +go 1.21.5 diff --git a/tools/generaterootmod.go b/tools/generaterootmod.go index 0e4c904..e913d5c 100644 --- a/tools/generaterootmod.go +++ b/tools/generaterootmod.go @@ -13,11 +13,16 @@ import ( ) func writeMainHead(w io.Writer) { - fmt.Fprint(w, `terraform { + const subModulesDirectoryPath = "modules" + requiredProviderVersion, err := getRequiredProvidersVersion(subModulesDirectoryPath) + if err != nil { + log.Fatal(err) + } + fmt.Fprintf(w, `terraform { required_providers { lightstep = { source = "lightstep/lightstep" - version = "~> 1.86.1" + %s } } required_version = ">= v1.0.11" @@ -28,7 +33,46 @@ provider "lightstep" { organization = var.lightstep_organization environment = var.lightstep_env } -`) +`, requiredProviderVersion) +} + +func getRequiredProvidersVersion(dirPath string) (string, error) { + files, err := os.ReadDir(dirPath) + if err != nil { + return "", err + } + + for _, file := range files { + if file.IsDir() { + dirPath = filepath.Join(dirPath, file.Name()) + break + } + } + + file, err := os.Open(filepath.Join(dirPath, "main.tf")) + if err != nil { + return "", err + } + defer file.Close() + + var buf bytes.Buffer + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + match, err := regexp.MatchString(`^\s*version\s*= `, line) + if err != nil { + return "", err + } + if match { + buf.WriteString(line) + } + } + + if err := scanner.Err(); err != nil { + log.Fatal(err) + } + + return buf.String(), nil } func writeMainModuleBlocks(w io.Writer, dirPath string) error { From ad59751a0aafd33b0bff36b6585126afabb03ec8 Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:59:31 -0800 Subject: [PATCH 2/9] testing the linters and precommit --- modules/amplify-dashboard/variables.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/amplify-dashboard/variables.tf b/modules/amplify-dashboard/variables.tf index 9a74482..ee3602f 100644 --- a/modules/amplify-dashboard/variables.tf +++ b/modules/amplify-dashboard/variables.tf @@ -2,3 +2,8 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string } + +variable "lightstep_test" { + description = "Testing Linters" + type = string +} \ No newline at end of file From bb35d75edce6f376ef41bd484cbef6c85930f33b Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:00:23 -0800 Subject: [PATCH 3/9] reverting linter and pre-commit test --- modules/amplify-dashboard/variables.tf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/amplify-dashboard/variables.tf b/modules/amplify-dashboard/variables.tf index ee3602f..b80463d 100644 --- a/modules/amplify-dashboard/variables.tf +++ b/modules/amplify-dashboard/variables.tf @@ -1,9 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} - -variable "lightstep_test" { - description = "Testing Linters" - type = string } \ No newline at end of file From 78ebce0cf792c9734599ef21fcc39c48d678d15c Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 08:45:32 -0800 Subject: [PATCH 4/9] Revert "reverting linter and pre-commit test" This reverts commit bb35d75edce6f376ef41bd484cbef6c85930f33b. --- modules/amplify-dashboard/variables.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/amplify-dashboard/variables.tf b/modules/amplify-dashboard/variables.tf index b80463d..ee3602f 100644 --- a/modules/amplify-dashboard/variables.tf +++ b/modules/amplify-dashboard/variables.tf @@ -1,4 +1,9 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string +} + +variable "lightstep_test" { + description = "Testing Linters" + type = string } \ No newline at end of file From 181751717c4be7b9690482163ecff9e9d300755e Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 08:45:37 -0800 Subject: [PATCH 5/9] Revert "Revert "reverting linter and pre-commit test"" This reverts commit 78ebce0cf792c9734599ef21fcc39c48d678d15c. --- modules/amplify-dashboard/variables.tf | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/amplify-dashboard/variables.tf b/modules/amplify-dashboard/variables.tf index ee3602f..b80463d 100644 --- a/modules/amplify-dashboard/variables.tf +++ b/modules/amplify-dashboard/variables.tf @@ -1,9 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} - -variable "lightstep_test" { - description = "Testing Linters" - type = string } \ No newline at end of file From 9e5f3577ca6d20b3dbfcfefe88f2db2c0a6830c9 Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 08:48:31 -0800 Subject: [PATCH 6/9] update readme and makefile --- Makefile | 1 + README.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index be7e8bc..987df03 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ ready: gen fmt check # generates the root module main.tf, variables.tf, outputs.tf and README.md gen: + terraform init -upgrade go run tools/generaterootmod.go fmt: diff --git a/README.md b/README.md index e15530f..6885277 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,12 @@ To deploy create Cloud Observability dashboards for production using this repo: ## Development -This repository uses `pre-commit` to format and lint HCL code. +This repository uses `pre-commit` and `tflint` to format and lint HCL code. To install: ``` + $ brew install 'tflint' $ brew install pre-commit $ pre-commit install ``` From b1eba14c47c3d1f352e2f4f7a2b72366dd9aa4bb Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:06:27 -0800 Subject: [PATCH 7/9] remove unnecessary quotes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6885277..a487bc9 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ This repository uses `pre-commit` and `tflint` to format and lint HCL code. To install: ``` - $ brew install 'tflint' + $ brew install tflint $ brew install pre-commit $ pre-commit install ``` From fc299177b99530b0d227b6cd37c1cc2e8232672f Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:45:28 -0800 Subject: [PATCH 8/9] readd newline --- modules/amplify-dashboard/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/amplify-dashboard/variables.tf b/modules/amplify-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/amplify-dashboard/variables.tf +++ b/modules/amplify-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} From adb5407c1e7aed42fe66e7a71b5bd91baf432fa2 Mon Sep 17 00:00:00 2001 From: adil-sultan <87725682+adil-sultan@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:50:11 -0800 Subject: [PATCH 9/9] add missing newlines across this file for consistency --- modules/apigateway-dashboard/variables.tf | 2 +- modules/aurora-dashboard/variables.tf | 2 +- modules/backup-dashboard/variables.tf | 2 +- modules/chatbot-dashboard/variables.tf | 2 +- modules/dynamodb-dashboard/variables.tf | 2 +- modules/ecs-dashboard/variables.tf | 2 +- modules/elasticache-redis-dashboard/variables.tf | 2 +- modules/kinesis-dashboard/variables.tf | 2 +- modules/lambda-dashboard/variables.tf | 2 +- modules/rds-dashboard/variables.tf | 2 +- modules/redshift-dashboard/variables.tf | 2 +- modules/route53-dashboard/variables.tf | 2 +- modules/s3-dashboard/variables.tf | 2 +- modules/sns-dashboard/variables.tf | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/apigateway-dashboard/variables.tf b/modules/apigateway-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/apigateway-dashboard/variables.tf +++ b/modules/apigateway-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/aurora-dashboard/variables.tf b/modules/aurora-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/aurora-dashboard/variables.tf +++ b/modules/aurora-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/backup-dashboard/variables.tf b/modules/backup-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/backup-dashboard/variables.tf +++ b/modules/backup-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/chatbot-dashboard/variables.tf b/modules/chatbot-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/chatbot-dashboard/variables.tf +++ b/modules/chatbot-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/dynamodb-dashboard/variables.tf b/modules/dynamodb-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/dynamodb-dashboard/variables.tf +++ b/modules/dynamodb-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/ecs-dashboard/variables.tf b/modules/ecs-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/ecs-dashboard/variables.tf +++ b/modules/ecs-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/elasticache-redis-dashboard/variables.tf b/modules/elasticache-redis-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/elasticache-redis-dashboard/variables.tf +++ b/modules/elasticache-redis-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/kinesis-dashboard/variables.tf b/modules/kinesis-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/kinesis-dashboard/variables.tf +++ b/modules/kinesis-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/lambda-dashboard/variables.tf b/modules/lambda-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/lambda-dashboard/variables.tf +++ b/modules/lambda-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/rds-dashboard/variables.tf b/modules/rds-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/rds-dashboard/variables.tf +++ b/modules/rds-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/redshift-dashboard/variables.tf b/modules/redshift-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/redshift-dashboard/variables.tf +++ b/modules/redshift-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/route53-dashboard/variables.tf b/modules/route53-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/route53-dashboard/variables.tf +++ b/modules/route53-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/s3-dashboard/variables.tf b/modules/s3-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/s3-dashboard/variables.tf +++ b/modules/s3-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +} diff --git a/modules/sns-dashboard/variables.tf b/modules/sns-dashboard/variables.tf index b80463d..9a74482 100644 --- a/modules/sns-dashboard/variables.tf +++ b/modules/sns-dashboard/variables.tf @@ -1,4 +1,4 @@ variable "lightstep_project" { description = "Name of Cloud Observability project" type = string -} \ No newline at end of file +}