Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test terraform templating #934

Merged
merged 9 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions templates/templates/common/make_git_helpers.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ define "make_git_helpers" }}
SHELL := bash
soft_git_log:
@git log --pretty=format:"{ \"sha\": \"%H\" }" -1 HEAD || echo "{ \"sha\": \"unknown\" }"
soft_git_user:
@echo "{\"name\": \"$$(git config --global --get user.name)\"}" || echo "{ \"user\": \"unknown\" }"
soft_git_email:
@echo "{\"email\": \"$$(git config --global --get user.email)\"}" || echo "{ \"email\": \"unknown\" }"
soft_git_branch:
@echo "{\"branch\": \"$$(git rev-parse --abbrev-ref HEAD)\"}" || echo "{ \"branch\": \"unknown\" }"
{{ end }}
1 change: 1 addition & 0 deletions templates/templates/component/terraform/Makefile.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ template "fogg_header" }}
{{ template "make_vars" . }}
{{ template "make_help" }}
{{ template "make_git_helpers" }}
32 changes: 32 additions & 0 deletions templates/templates/component/terraform/fogg.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ variable "owner" {
default = "{{ .Owner }}"
}

data "external" "git_sha" {
program = [
"make",
"soft_git_log",
]
}

data "external" "git_user" {
program = [
"make",
"soft_git_user"
]
}

data "external" "git_email" {
program = [
"make",
"soft_git_email"
]
}

data "external" "git_branch" {
program = [
"make",
"soft_git_branch"
]
}

# tflint-ignore: terraform_unused_declarations
variable "tags" {
type = object({project: string, env: string, service: string, owner: string, managedBy: string})
Expand All @@ -130,6 +158,10 @@ variable "tags" {
terraformLastApplyTime = timestamp()
terraformWorkspaceDir = "{{ cwd }}"
gitRepository = "{{ git_origin }}"
gitSHA = data.external.git_sha.result.sha
gitUser = data.external.git_user.result.name
gitEmail = data.external.git_email.result.email
gitBranch = data.external.git_branch.result.branch
managedBy = "terraform"
}
}
Expand Down
10 changes: 10 additions & 0 deletions testdata/auth0_provider_yaml/terraform/accounts/foo/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions testdata/auth0_provider_yaml/terraform/accounts/foo/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions testdata/auth0_provider_yaml/terraform/envs/bar/bam/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions testdata/auth0_provider_yaml/terraform/envs/bar/bam/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions testdata/auth0_provider_yaml/terraform/global/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions testdata/auth0_provider_yaml/terraform/global/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions testdata/bless_provider_yaml/terraform/accounts/foo/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions testdata/bless_provider_yaml/terraform/accounts/foo/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions testdata/bless_provider_yaml/terraform/envs/bar/bam/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions testdata/bless_provider_yaml/terraform/envs/bar/bam/fogg.tf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions testdata/bless_provider_yaml/terraform/global/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading