-
-
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
Use terraform-core-helpers
child module
#7
Changes from 3 commits
baeca95
b0e45a7
9798997
a654dbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,31 @@ variable "chart_repository" { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
default = "https://charts.jetstack.io" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "helpers_cost_center" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The cost center the resources will be billed to, must start with 'x' followed by three or four digits" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "helpers_data_classification" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The data classification of the resources can be public, internal, or confidential" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "helpers_email" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The email address of the team responsible for the resources" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add email format validation. The email variable should validate the input format. Add a validation block: variable "helpers_email" {
description = "The email address of the team responsible for the resources"
type = string
+ validation {
+ condition = can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", var.helpers_email))
+ error_message = "Please provide a valid email address."
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "helpers_repository" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The repository name (should be in the format 'owner/repo' containing only lowercase alphanumeric characters or hyphens)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "helpers_team" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The team name (should contain only lowercase alphanumeric characters and hyphens)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+42
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add format validation for repository and team variables. Both variables require specific format constraints that should be enforced. Add validation blocks: variable "helpers_repository" {
description = "The repository name (should be in the format 'owner/repo' containing only lowercase alphanumeric characters or hyphens)"
type = string
+ validation {
+ condition = can(regex("^[a-z0-9-]+/[a-z0-9-]+$", var.helpers_repository))
+ error_message = "Repository must be in format 'owner/repo' using only lowercase alphanumeric characters and hyphens."
+ }
}
variable "helpers_team" {
description = "The team name (should contain only lowercase alphanumeric characters and hyphens)"
type = string
+ validation {
+ condition = can(regex("^[a-z0-9-]+$", var.helpers_team))
+ error_message = "Team name must contain only lowercase alphanumeric characters and hyphens."
+ }
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable "resources_limits_cpu" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
description = "The CPU limit for the Istio CSR container" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
type = string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,3 +24,11 @@ run "default_regional_istio_csr" { | |||||||||||||||||||||
source = "./tests/fixtures/default/regional/istio-csr" | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
variables { | ||||||||||||||||||||||
helpers_cost_center = "mock-cost-center" | ||||||||||||||||||||||
helpers_data_classification = "mock-data-classification" | ||||||||||||||||||||||
helpers_email = "mock-team@osinfra.io" | ||||||||||||||||||||||
helpers_repository = "mock-owner/mock-repository" | ||||||||||||||||||||||
helpers_team = "mock-team" | ||||||||||||||||||||||
Comment on lines
+29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using more distinctive mock values. To prevent any potential confusion or accidental use in production, consider using more obviously fake values. - helpers_cost_center = "mock-cost-center"
- helpers_data_classification = "mock-data-classification"
- helpers_email = "mock-team@osinfra.io"
- helpers_repository = "mock-owner/mock-repository"
- helpers_team = "mock-team"
+ helpers_cost_center = "TEST-MOCK-COST-CENTER-000"
+ helpers_data_classification = "TEST-MOCK-DATA-CLASS-000"
+ helpers_email = "test-mock-team@example.com"
+ helpers_repository = "test-mock-owner/test-mock-repo"
+ helpers_team = "TEST-MOCK-TEAM-000" 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Input Variables | ||
# https://www.terraform.io/language/values/variables | ||
|
||
variable "helpers_cost_center" { | ||
type = string | ||
} | ||
|
||
variable "helpers_data_classification" { | ||
type = string | ||
} | ||
|
||
variable "helpers_email" { | ||
type = string | ||
} | ||
|
||
variable "helpers_repository" { | ||
type = string | ||
} | ||
|
||
variable "helpers_team" { | ||
type = string | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,5 +63,10 @@ data "terraform_remote_state" "regional" { | |
module "test" { | ||
source = "../../../../regional" | ||
|
||
artifact_registry = "mock-docker.pkg.dev/mock-project/mock-virtual" | ||
artifact_registry = "mock-docker.pkg.dev/mock-project/mock-virtual" | ||
helpers_cost_center = var.helpers_cost_center | ||
helpers_data_classification = var.helpers_data_classification | ||
helpers_email = var.helpers_email | ||
helpers_repository = var.helpers_repository | ||
helpers_team = var.helpers_team | ||
Comment on lines
+21
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding variable validation for helper values. While the mock values are appropriate for testing, consider adding variable validation blocks in the actual module to ensure these helper values meet your organization's standards (e.g., specific email formats, repository naming conventions). Example validation block to add in the main module: variable "helpers_email" {
description = "Contact email for the resource owner"
type = string
validation {
condition = can(regex("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", var.helpers_email))
error_message = "The helpers_email value must be a valid email address."
}
} |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Input Variables | ||
# https://www.terraform.io/language/values/variables | ||
|
||
variable "helpers_cost_center" { | ||
type = string | ||
} | ||
|
||
variable "helpers_data_classification" { | ||
type = string | ||
} | ||
|
||
variable "helpers_email" { | ||
type = string | ||
} | ||
|
||
variable "helpers_repository" { | ||
type = string | ||
} | ||
|
||
variable "helpers_team" { | ||
type = string | ||
} |
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.
💡 Codebase verification
Missing validation rules for helper variables
The variables are defined in multiple
variables.tf
files but none of them implement the validation rules specified in the README. The variables are declared only with type definitions, missing crucial validation blocks to enforce:helpers_cost_center
: pattern validation for 'x' followed by 3-4 digitshelpers_data_classification
: allowed values validation for public/internal/confidentialhelpers_repository
: format validation for owner/repo pattern and character restrictionshelpers_team
: character set validation for lowercase alphanumeric and hyphens🔗 Analysis chain
Verify validation rules implementation.
The new helper variables have clear descriptions with specific validation rules. Let's verify that these rules are properly implemented in the variables.tf file.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 86
Script:
Length of output: 6220