Skip to content

updated terraform #8

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/checkov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id: checkov
uses: bridgecrewio/checkov-action@master
with:
directory: .
directory: example
#file: example/tfplan.json # optional: provide the path for resource to be scanned. This will override the directory if both are provided.
#check: CKV_AWS_1 # optional: run only a specific check_id. can be comma separated list
#skip_check: CKV_AWS_2 # optional: skip a specific check_id. can be comma separated list
Expand Down
119 changes: 65 additions & 54 deletions .tfsec/custom_tfchecks.yaml
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
---
checks:
- code: rg-naming-pattern
description: Custom check to check resource group naming
impact: resource groups should be named consistently
resolution: use the pattern rg-app-env-region
requiredTypes:
- resource
requiredLabels:
- azurerm_resource_group
severity: HIGH
matchSpec:
name: name
action: regexMatches
value: "^rg-[a-zA-Z]+-[a-zA-Z]+-[a-zA-Z]+"
errorMessage: improperly named resource group
relatedLinks:
- https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming
- code: tags-resources
description: Custom check to ensure the CostCenter tag is applied to Azure Resources
impact: By not having CostCenter we can't keep track of billing
resolution: Add the CostCenter tag
requiredTypes:
- resource
requiredLabels:
- azurerm_subscription
- azurerm_resource_group
- azurerm_linux_web_app
- azurerm_windows_web_app
- azurerm_storage_account
- azurerm_service_plan
- azurerm_app_service
severity: HIGH
matchSpec:
name: tags
action: contains
value: CostCenter
errorMessage: The required CostCenter tag was missing
relatedLinks:
- https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-tagging
- code: app-service-deprecated
description: Custom check to warn on deprecated app service
impact: using deprecated app service resource instead of azurerm_linux_web_app or azurerm_windows_web_app
resolution: Use azurerm_linux_web_app or azurerm_windows_web_app
requiredTypes:
- resource
requiredLabels:
- azurerm_app_service
severity: HIGH
matchSpec:
name: azurerm_app_service
action: isPresent
errorMessage: Using a deprecated resource - azurerm_app_service
relatedLinks:
- https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service
- {
code: rg-naming-pattern,
description: "Custom check to check resource group naming",
impact: "resource groups should be named consistently",
resolution: "use the pattern rg-app-env-region",
requiredTypes: [resource],
requiredLabels: [azurerm_resource_group],
severity: HIGH,
matchSpec:
{
action: not,
predicateMatchSpec:
[
{
name: name,
action: regexMatches,
value: "^rg-[a-zA-Z]+-[a-zA-Z]+-[a-zA-Z]+",
},
],
},
errorMessage: "improperly named resource group",
relatedLinks:
[
"https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming",
],
}
- {
code: tags-resources,
description: "Custom check to ensure the CostCenter tag is applied to Azure Resources",
impact: "By not having CostCenter we can't keep track of billing",
resolution: "Add the CostCenter tag",
requiredTypes: [resource],
requiredLabels:
[
azurerm_subscription,
azurerm_resource_group,
azurerm_linux_web_app,
azurerm_windows_web_app,
azurerm_storage_account,
azurerm_service_plan,
azurerm_app_service,
],
severity: HIGH,
matchSpec: { name: tags, action: contains, value: CostCenter },
errorMessage: "The required CostCenter tag was missing",
relatedLinks:
[
"https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-tagging",
],
}
- {
code: app-service-deprecated,
description: "Custom check to warn on deprecated app service",
impact: "using deprecated app service resource instead of azurerm_linux_web_app or azurerm_windows_web_app",
resolution: "Use azurerm_linux_web_app or azurerm_windows_web_app",
requiredTypes: [resource],
requiredLabels: [azurerm_app_service],
severity: HIGH,
matchSpec: { name: azurerm_app_service, action: isPresent },
errorMessage: "Using a deprecated resource - azurerm_app_service",
relatedLinks:
[
"https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service",
],
}
11 changes: 11 additions & 0 deletions example/modules/vnet/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ data "azurerm_resource_group" "rg" {
name = var.rg_name
}

resource "azurerm_network_security_group" "nsg" {
name = "${var.prefix}-nsg"
location = azurerm_resource_group.rg.name
resource_group_name = azurerm_resource_group.rg.location
}

resource "azurerm_virtual_network" "vnet" {
name = "${var.prefix}-network"
resource_group_name = azurerm_resource_group.rg.name
Expand All @@ -14,4 +20,9 @@ resource "azurerm_subnet" "snet" {
virtual_network_name = azurerm_virtual_network.rg.name
resource_group_name = azurerm_resource_group.rg.name
address_prefixes = ["10.0.1.0/24"]
}

resource "azurerm_subnet_network_security_group_association" "example" {
subnet_id = azurerm_subnet.snet.id
network_security_group_id = azurerm_network_security_group.nsg.id
}
2 changes: 1 addition & 1 deletion example/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ resource "azurerm_resource_group" "rg" {
name = "rg-terraformdemo-${var.environment}-${var.location}"
location = var.location
tags = {
"CostCenter" = "it"
"CostCenter" = "ops"
}
}