-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2380f63
commit 32202f8
Showing
17 changed files
with
344 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base", | ||
":semanticCommitTypeAll(chore)" | ||
], | ||
"lockFileMaintenance": { | ||
"enabled": true, | ||
"extends": [ | ||
"schedule:weekly" | ||
] | ||
}, | ||
"nix": { | ||
"enabled": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.direnv | ||
/.direnv | ||
/build-configs | ||
/result | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,3 @@ | |
issues: | ||
exclude: | ||
- Error return value of `\(github.com/go-kit/log.Logger\).Log` is not checked | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ALT-F4-LLC/build-configs/internal/templates" | ||
) | ||
|
||
const TerraformName = "terraform" | ||
|
||
type TerraformConfigRole struct { | ||
PlanARN string `json:"planArn,omitempty" yaml:"planArn,omitempty"` | ||
ApplyARN string `json:"applyArn,omitempty" yaml:"applyArn,omitempty"` | ||
} | ||
|
||
type TerraformConfig struct { | ||
Config | ||
Nix NixConfig `json:"nix,omitempty" yaml:"nix,omitempty"` | ||
Region string `json:"region,omitempty" yaml:"region,omitempty"` | ||
Role TerraformConfigRole `json:"role,omitempty" yaml:"role,omitempty"` | ||
Schedule *string `json:"schedule,omitempty" yaml:"schedule,omitempty"` | ||
Providers []string `json:"providers,omitempty" yaml:"providers,omitempty"` | ||
} | ||
|
||
func NewTerraformConfigRole(name string) TerraformConfigRole { | ||
return TerraformConfigRole{ | ||
ApplyARN: fmt.Sprintf("arn:aws:iam::677459762413:role/altf4llc-gha-%s-apply", name), | ||
PlanARN: fmt.Sprintf("arn:aws:iam::677459762413:role/altf4llc-gha-%s-plan", name), | ||
} | ||
} | ||
|
||
func NewTerraformConfig(c Config) TerraformConfig { | ||
return TerraformConfig{ | ||
Config: c, | ||
Nix: NewNixConfig(), | ||
Region: "us-west-2", | ||
Role: NewTerraformConfigRole(c.Name), | ||
Schedule: nil, | ||
} | ||
} | ||
|
||
func (c TerraformConfig) Render() error { | ||
renderMap := templates.RenderMap{ | ||
templates.AllCommonTemplates: { | ||
".envrc", | ||
".github/renovate.json", | ||
}, | ||
templates.TerraformTemplates: { | ||
".github/workflows/terraform.yaml", | ||
".gitignore", | ||
"flake.nix", | ||
"justfile", | ||
}, | ||
} | ||
|
||
files, err := templates.RenderTemplates(renderMap, c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return templates.WriteFiles(files) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
internal/templates/templates/common/all/.github__renovate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base", | ||
":semanticCommitTypeAll(chore)" | ||
], | ||
"lockFileMaintenance": { | ||
"enabled": true, | ||
"extends": [ | ||
"schedule:weekly" | ||
] | ||
}, | ||
"nix": { | ||
"enabled": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
internal/templates/templates/terraform/.github__workflows__terraform.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: terraform | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
{{- if .Schedule }} | ||
schedule: | ||
- cron: "{{ .Schedule }}" | ||
{{- end }} | ||
|
||
env: | ||
CACHIX_BINARY_CACHE: {{ .Nix.Cachix.BinaryCache }} | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- uses: cachix/cachix-action@v15 | ||
with: | ||
authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} | ||
name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} | ||
- uses: actions/checkout@v4 | ||
- run: nix develop -c just check | ||
|
||
plan: | ||
runs-on: ubuntu-latest | ||
needs: check | ||
concurrency: | ||
group: tf-lock | ||
cancel-in-progress: false | ||
permissions: | ||
contents: read | ||
id-token: write | ||
env: | ||
TF_VAR_PLATFORM_DIRECTORY_TOKEN: ${{"{{"}} secrets.TF_VAR_PLATFORM_DIRECTORY_TOKEN {{"}}"}} | ||
steps: | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- uses: cachix/cachix-action@v15 | ||
with: | ||
authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} | ||
name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} | ||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
audience: sts.amazonaws.com | ||
aws-region: us-west-2 | ||
role-to-assume: {{ .Role.PlanARN }} | ||
- run: aws sts get-caller-identity | ||
- uses: actions/checkout@v4 | ||
- run: nix develop -c just init | ||
- run: nix develop -c just validate | ||
- run: nix develop -c just plan | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: tf-plan | ||
path: terraform.tfplan | ||
|
||
apply: | ||
if: github.ref == 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
needs: plan | ||
environment: | ||
name: prod | ||
permissions: | ||
contents: read | ||
id-token: write | ||
concurrency: | ||
group: tf-lock | ||
cancel-in-progress: false | ||
env: | ||
TF_VAR_PACKER_SSH_PUBLIC_KEY: ${{"{{"}} secrets.TF_VAR_PACKER_SSH_PUBLIC_KEY {{"}}"}} | ||
steps: | ||
- uses: cachix/install-nix-action@v27 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- uses: cachix/cachix-action@v15 | ||
with: | ||
authToken: ${{"{{"}} secrets.ALTF4LLC_CACHIX_AUTH_TOKEN {{"}}"}} | ||
name: ${{"{{"}} env.CACHIX_BINARY_CACHE {{"}}"}} | ||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
audience: sts.amazonaws.com | ||
aws-region: us-west-2 | ||
role-to-assume: {{ .Role.ApplyARN }} | ||
- run: aws sts get-caller-identity | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: tf-plan | ||
- run: nix develop -c just init | ||
- run: nix develop -c just apply |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.direnv | ||
*.tfplan | ||
|
||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
.terraform.lock.hcl |
Oops, something went wrong.