-
Notifications
You must be signed in to change notification settings - Fork 0
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
feature: GitHub component #2
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7958978
chore: adds .editorconfig + gitignore rules
gberenice 837d502
feat: adds github component
gberenice 7a4c78f
chore: adds README for github
gberenice ae0afa7
chore: move GH provider vars to variables.tf
gberenice 353d208
feat: enable trunk + GHA workflow
gberenice 632cd71
chore: removed branch_protections_v3 + make trunk happy
gberenice e874e4e
fix: grant write permisssions for checks
gberenice 94314b8
chore: formatting
gberenice 5ea8997
fix: grant write permisssions for checks
gberenice dc903db
chore: fmt
gberenice d239ead
chore: renames the component to 'github-repositories' + updates README
gberenice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 @@ | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
quote_type = double | ||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false |
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,8 @@ | ||
## Info | ||
|
||
- Describe high-level what changed as a result of these commits and why you made these changes. Be descriptive as pull requests are a common source of historical information when looking at past changes to the code. | ||
- Use bullet points to be concise and to the point. | ||
|
||
## References | ||
|
||
- Include any links to tickets, Teams or Slack threads, documentation, or online articles that help understand these changes and why they were made. |
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,21 @@ | ||
name: Lint | ||
|
||
on: pull_request | ||
|
||
permissions: | ||
actions: read | ||
checks: write | ||
contents: read | ||
pull-requests: read | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v4 | ||
- name: Trunk Check | ||
uses: trunk-io/trunk-action@v1 | ||
- name: Set up Terraform CLI | ||
uses: hashicorp/setup-terraform@v2 | ||
- run: terraform fmt -check -recursive |
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,4 @@ | ||
# This is a Markdownlint configuration file to ignore the acceptable issues for all files. | ||
MD041: false # First line in file should be a top level header. | ||
MD013: false # Line length. | ||
MD033: false # Inline HTML. |
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,6 @@ | ||
repos: | ||
- repo: https://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.83.5 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases | ||
hooks: | ||
- id: terraform_fmt | ||
- id: terraform_docs |
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,8 @@ | ||
*out | ||
*logs | ||
*actions | ||
*notifications | ||
*tools | ||
plugins | ||
user_trunk.yaml | ||
user.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,10 @@ | ||
# Autoformatter friendly markdownlint config (all formatting rules disabled) | ||
default: true | ||
blank_lines: false | ||
bullet: false | ||
html: false | ||
indentation: false | ||
line_length: false | ||
spaces: false | ||
url: false | ||
whitespace: false |
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,10 @@ | ||
rules: | ||
quoted-strings: | ||
required: only-when-needed | ||
extra-allowed: ["{|}"] | ||
empty-values: | ||
forbid-in-block-mappings: true | ||
forbid-in-flow-mappings: true | ||
key-duplicates: {} | ||
octal-values: | ||
forbid-implicit-octal: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file controls the behavior of Trunk: https://docs.trunk.io/cli | ||
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
version: 0.1 | ||
cli: | ||
version: 1.17.0 | ||
plugins: | ||
sources: | ||
- id: trunk | ||
ref: v1.2.5 | ||
uri: https://github.com/trunk-io/plugins | ||
runtimes: | ||
enabled: | ||
- node@18.12.1 | ||
- python@3.10.8 | ||
lint: | ||
enabled: | ||
- checkov@2.5.9 | ||
- git-diff-check | ||
- markdownlint@0.37.0 | ||
- prettier@3.0.3 | ||
- tflint@0.48.0 | ||
- trivy@0.46.0 | ||
- trufflehog@3.60.0 | ||
- yamllint@1.32.0 | ||
actions: | ||
enabled: | ||
- trunk-announce | ||
- trunk-check-pre-push | ||
- trunk-fmt-pre-commit | ||
- trunk-upgrade-available |
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,2 +1,29 @@ | ||
# terraform-components | ||
The Masterpoint reusable and sharable Terraform Root Modules (Components) | ||
[![Masterpoint Logo](https://i.imgur.com/RDLnuQO.png)](https://masterpoint.io) | ||
|
||
# terraform-components [![Latest Release](https://img.shields.io/github/release/masterpointio/terraform-components.svg)](https://github.com/masterpointio/terraform-components/releases/latest) | ||
|
||
This is a Masterpoint's reusable and sharable collection of Terraform Root Modules (Components). Each Component is a set of Terraform modules, resources, data sources and local expressions that represent an higher abstraction layer of infrastructure comparing to an average community child module. It can be easily integrated into the architecture and removed if needed. | ||
|
||
It's Open Source and licensed under the [APACHE2](LICENSE). | ||
|
||
## Components | ||
|
||
- [GitHub Repositories](./github-repositories/README.md): responsible for managing GitHub repositories, including permissions, webhooks, pages, etc. | ||
|
||
## Trunk Linter | ||
|
||
To maintain code quality we use a collection of linters, all managed by [Trunk](https://trunk.io). | ||
|
||
To install trunk on your machine you can use brew: `brew install trunk-io`. You can also install trunk via the [official instructions](https://docs.trunk.io/docs/install). | ||
|
||
### Usage | ||
|
||
To run the linters, simply run `trunk check` from the root of the project. This will check any files that you have changed in your current branch. | ||
|
||
To automatically apply formatting changes, run `trunk fmt`. | ||
|
||
## Automating Trunk | ||
|
||
Trunk can manage git hooks, and is configured to run `fmt` on pre-commit and `check` on pre-push. This should help to prevent code being kicked-back by CI. | ||
|
||
Trunk is automated in CI using GitHub Actions, and PRs will be blocked if the linters fail. |
Large diffs are not rendered by default.
Oops, something went wrong.
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,84 @@ | ||
module "repos" { | ||
# checkov:skip=CKV_TF_1: For now we use Terraform registry source, not git. If switching to git, we should use a commit hash. | ||
source = "mineiros-io/repository/github" | ||
version = "0.18.0" | ||
|
||
for_each = var.repos | ||
|
||
# Main Resource Configuration | ||
allow_auto_merge = each.value.allow_auto_merge | ||
allow_merge_commit = each.value.allow_merge_commit | ||
allow_rebase_merge = each.value.allow_rebase_merge | ||
allow_squash_merge = each.value.allow_squash_merge | ||
archive_on_destroy = each.value.archive_on_destroy | ||
archived = each.value.archived | ||
# NOTE: The configured branch must exist in the repository. | ||
# If the branch doesn't exist yet, or if you are creating a new repository, | ||
# please add the desired default branch to the `branches` variable, which will cause Terraform to create it for you. | ||
default_branch = each.value.default_branch | ||
description = each.value.description | ||
extra_topics = each.value.extra_topics | ||
has_downloads = each.value.has_downloads | ||
has_issues = each.value.has_issues | ||
has_projects = each.value.has_projects | ||
has_wiki = each.value.has_wiki | ||
homepage_url = each.value.homepage_url | ||
is_template = each.value.is_template | ||
name = each.key | ||
pages = each.value.pages | ||
topics = each.value.topics | ||
visibility = each.value.visibility | ||
vulnerability_alerts = each.value.vulnerability_alerts | ||
|
||
# Extended Resource Configuration | ||
auto_init = each.value.auto_init | ||
gitignore_template = each.value.gitignore_template | ||
license_template = each.value.license_template | ||
template = each.value.template | ||
|
||
# Teams Configuration | ||
admin_teams = each.value.admin_teams | ||
maintain_teams = each.value.maintain_teams | ||
pull_teams = each.value.pull_teams | ||
push_teams = each.value.push_teams | ||
triage_teams = each.value.triage_teams | ||
|
||
# Collaborator Configuration | ||
admin_collaborators = each.value.admin_collaborators | ||
maintain_collaborators = each.value.maintain_collaborators | ||
pull_collaborators = each.value.pull_collaborators | ||
push_collaborators = each.value.push_collaborators | ||
triage_collaborators = each.value.triage_collaborators | ||
|
||
# Branches Configuration | ||
branches = each.value.branches | ||
|
||
# Deploy Keys Configuration | ||
deploy_keys = each.value.deploy_keys | ||
deploy_keys_computed = each.value.deploy_keys_computed | ||
|
||
# Branch Protections v4 Configuration | ||
branch_protections_v4 = each.value.branch_protections_v4 | ||
|
||
# Issue Labels Configuration | ||
issue_labels = each.value.issue_labels | ||
issue_labels_create = each.value.issue_labels_create | ||
|
||
issue_labels_merge_with_github_labels = each.value.issue_labels_merge_with_github_labels | ||
|
||
# Projects Configuration | ||
projects = each.value.projects | ||
|
||
# Webhooks Configuration | ||
webhooks = each.value.webhooks | ||
|
||
# Secrets Configuration | ||
plaintext_secrets = each.value.plaintext_secrets | ||
encrypted_secrets = each.value.encrypted_secrets | ||
|
||
# Autolink References Configuration | ||
autolink_references = each.value.autolink_references | ||
|
||
# App Installations | ||
app_installations = each.value.app_installations | ||
} |
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,32 @@ | ||
locals { | ||
gh_token = try(local.secrets[var.gh_token_secret_name], "") | ||
gh_token_enabled = length(local.gh_token) > 0 ? true : false | ||
|
||
gh_app_auth_id_enabled = length(var.gh_app_auth_id) > 0 ? true : false | ||
gh_app_auth_installation_id_enabled = length(var.gh_app_auth_installation_id) > 0 ? true : false | ||
gh_app_auth_pem_file = try(local.secrets[var.gh_app_auth_pem_file_secret_name], "") | ||
gh_app_auth_pem_file_enabled = length(local.gh_app_auth_pem_file) > 0 ? true : false | ||
gh_app_auth_enabled = alltrue([local.gh_app_auth_id_enabled, local.gh_app_auth_installation_id_enabled, local.gh_app_auth_pem_file_enabled]) | ||
} | ||
|
||
# The GitHub provider offers multiple ways to authenticate with GitHub API: | ||
# - GitHub CLI | ||
# - OAuth / Personal Access Token | ||
# - GitHub App Installation | ||
# | ||
# When none configuration is provided, the provider can only access resources available anonymously. | ||
provider "github" { | ||
base_url = var.gh_base_url | ||
owner = var.gh_owner | ||
|
||
token = local.gh_token_enabled ? local.gh_token : null | ||
|
||
dynamic "app_auth" { | ||
for_each = local.gh_app_auth_enabled ? ["app_auth"] : [] | ||
content { | ||
id = var.gh_app_auth_id | ||
installation_id = var.gh_app_auth_installation_id | ||
pem_file = local.gh_app_auth_pem_file | ||
} | ||
} | ||
} |
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,26 @@ | ||
module "secrets" { | ||
# checkov:skip=CKV_TF_1: For now we use Terraform registry source, not git. If switching to git, we should use a commit hash. | ||
source = "masterpointio/helper/secrets" | ||
version = "0.2.0" | ||
secret_mapping = var.secret_mapping | ||
} | ||
|
||
variable "secret_mapping" { | ||
type = list(object({ | ||
name = string | ||
type = string | ||
path = optional(string, null) | ||
file = string | ||
})) | ||
default = [] | ||
description = <<-EOT | ||
The list of secret mappings the application will need. | ||
This creates secret values for the component to consume at `local.secrets[name]`. | ||
EOT | ||
} | ||
|
||
# Reference your secrets using the module output | ||
locals { | ||
# tflint-ignore: terraform_unused_declarations | ||
secrets = module.secrets.all | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should include
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The components are intended to be used as child modules, and the root module should have it's own lock file anyway. What's the reason we might want to keep it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this component is already at root module level for a consumer. The most we would do is just copy it into
sts-devops
, no? to wrap it an additional time and write anothervariable = var.variable ...
block seems like too muchThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionally I see no opinions online that lockfiles should not be included in child modules and don't see a reason not to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just not used by Terraform, no
init
is run on this level.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Let's discuss on a call.