-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: add policy ecc-azure-448-vm_stopped_instance
- Loading branch information
Showing
9 changed files
with
143 additions
and
0 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,23 @@ | ||
# Copyright (c) 2023 EPAM Systems, Inc. | ||
# | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
policies: | ||
- name: ecc-azure-448-vm_stopped_instance | ||
comment: '020002032000' | ||
description: | | ||
Stopped Azure VM instances are not removed after a specified time period | ||
resource: azure.vm | ||
filters: | ||
- type: instance-view | ||
key: statuses[].code | ||
op: in | ||
value_type: swap | ||
value: PowerState/deallocated | ||
- type: instance-view | ||
key: statuses[0].time | ||
value_type: age | ||
op: greater-than | ||
value: 30 |
12 changes: 12 additions & 0 deletions
12
terraform/ecc-azure-448-vm_stopped_instance/green/provider.tf
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,12 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~>4" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |
12 changes: 12 additions & 0 deletions
12
terraform/ecc-azure-448-vm_stopped_instance/green/random.tf
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,12 @@ | ||
resource "random_password" "this" { | ||
length = 13 | ||
special = true | ||
numeric = true | ||
override_special = "_%@" | ||
} | ||
|
||
resource "random_string" "this" { | ||
length = 8 | ||
numeric = false | ||
special = false | ||
} |
6 changes: 6 additions & 0 deletions
6
terraform/ecc-azure-448-vm_stopped_instance/green/resource_group.tf
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 @@ | ||
resource "azurerm_resource_group" "this" { | ||
name = "${var.prefix}-rg-green" | ||
location = var.location | ||
|
||
tags = var.tags | ||
} |
8 changes: 8 additions & 0 deletions
8
terraform/ecc-azure-448-vm_stopped_instance/green/terraform.tfvars
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 @@ | ||
prefix = "448" | ||
|
||
location = "eastus" | ||
|
||
tags = { | ||
CustodianRule = "ecc-azure-448-vm_stopped_instance" | ||
ComplianceStatus = "Green" | ||
} |
11 changes: 11 additions & 0 deletions
11
terraform/ecc-azure-448-vm_stopped_instance/green/variables.tf
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,11 @@ | ||
variable "prefix" { | ||
type = string | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
} | ||
|
||
variable "tags" { | ||
type = map(string) | ||
} |
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,27 @@ | ||
resource "azurerm_linux_virtual_machine" "linuxvm" { | ||
name = "${var.prefix}linuxvmgreen" | ||
resource_group_name = azurerm_resource_group.this.name | ||
location = azurerm_resource_group.this.location | ||
size = "Standard_B1ms" | ||
disable_password_authentication = false | ||
admin_username = random_string.this.result | ||
admin_password = random_password.this.result | ||
|
||
network_interface_ids = [ | ||
azurerm_network_interface.nif1.id, | ||
] | ||
|
||
os_disk { | ||
caching = "ReadWrite" | ||
storage_account_type = "Standard_LRS" | ||
} | ||
|
||
source_image_reference { | ||
publisher = "Canonical" | ||
offer = "UbuntuServer" | ||
sku = "16.04-LTS" | ||
version = "latest" | ||
} | ||
|
||
tags = var.tags | ||
} |
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,25 @@ | ||
resource "azurerm_virtual_network" "this" { | ||
name = "${var.prefix}-network-green" | ||
address_space = ["10.0.0.0/16"] | ||
location = azurerm_resource_group.this.location | ||
resource_group_name = azurerm_resource_group.this.name | ||
} | ||
|
||
resource "azurerm_subnet" "this" { | ||
name = "${var.prefix}internal-green" | ||
resource_group_name = azurerm_resource_group.this.name | ||
virtual_network_name = azurerm_virtual_network.this.name | ||
address_prefixes = ["10.0.2.0/24"] | ||
} | ||
|
||
resource "azurerm_network_interface" "nif1" { | ||
name = "${var.prefix}first-green" | ||
location = azurerm_resource_group.this.location | ||
resource_group_name = azurerm_resource_group.this.name | ||
|
||
ip_configuration { | ||
name = "internal" | ||
subnet_id = azurerm_subnet.this.id | ||
private_ip_address_allocation = "Dynamic" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
terraform/ecc-azure-448-vm_stopped_instance/iam/ecc-azure-448-vm_stopped_instance.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,19 @@ | ||
{ | ||
"properties": { | ||
"roleName": "Custodian-ecc-azure-448-vm_stopped_instance", | ||
"description": "", | ||
"assignableScopes": [ | ||
"/subscriptions/{subscription_id}" | ||
], | ||
"permissions": [ | ||
{ | ||
"actions": [ | ||
"Microsoft.Compute/virtualMachines/read" | ||
], | ||
"notActions": [], | ||
"dataActions": [], | ||
"notDataActions": [] | ||
} | ||
] | ||
} | ||
} |