Skip to content
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

Kitchen test #9

Merged
merged 2 commits into from
Dec 7, 2017
Merged
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
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Compiled files
*.tfstate
*.tfstate.backup
Gemfile
Rakefile
Gemfile.lock

# Module directory
.terraform/

test

# Dependencies from microsoft/terraform-test Docker image
Gemfile
Rakefile
build/
build/
logs/
terraform.log
terraform.tfstate.d/
25 changes: 25 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
driver:
name: "terraform"
root_module_directory: "test/integration/fixtures"
parallelism: 1
variable_files:
- "test/integration/fixtures/testing.tfvars"

provisioner:
name: "terraform"

platforms:
-
name: "ubuntu"

verifier:
name: "terraform"
groups:
-
name: "local"
controls:
- "state_file"

suites:
- name: "network"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
20 changes: 10 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "azurerm_resource_group" "network" {
}

resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet_name}"
name = "${var.vnet_name}"
location = "${var.location}"
address_space = ["${var.address_space}"]
resource_group_name = "${azurerm_resource_group.network.name}"
Expand All @@ -14,19 +14,19 @@ resource "azurerm_virtual_network" "vnet" {
}

resource "azurerm_subnet" "subnet" {
name = "${var.subnet_names[count.index]}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.network.name}"
address_prefix = "${var.subnet_prefixes[count.index]}"
name = "${var.subnet_names[count.index]}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.network.name}"
address_prefix = "${var.subnet_prefixes[count.index]}"
network_security_group_id = "${azurerm_network_security_group.security_group.id}"
count = "${length(var.subnet_names)}"
count = "${length(var.subnet_names)}"
}

resource "azurerm_network_security_group" "security_group" {
name = "${var.sg_name}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.network.name}"
tags = "${var.tags}"
name = "${var.sg_name}"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.network.name}"
tags = "${var.tags}"
}

resource "azurerm_network_security_rule" "security_rule_rdp" {
Expand Down
24 changes: 12 additions & 12 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
output "vnet_id" {
description = "The id of the newly created vNet"
value = "${azurerm_virtual_network.vnet.id}"
description = "The id of the newly created vNet"
value = "${azurerm_virtual_network.vnet.id}"
}

output "vnet_name" {
description = "The Name of the newly created vNet"
value = "${azurerm_virtual_network.vnet.name}"
description = "The Name of the newly created vNet"
value = "${azurerm_virtual_network.vnet.name}"
}

output "vnet_location" {
description = "The location of the newly created vNet"
value = "${azurerm_virtual_network.vnet.location}"
description = "The location of the newly created vNet"
value = "${azurerm_virtual_network.vnet.location}"
}

output "vnet_address_space" {
description = "The address space of the newly created vNet"
value = "${azurerm_virtual_network.vnet.address_space}"
description = "The address space of the newly created vNet"
value = "${azurerm_virtual_network.vnet.address_space}"
}

output "vnet_subnets" {
description = "The ids of subnets created inside the newl vNet"
value = "${azurerm_subnet.subnet.*.id}"
description = "The ids of subnets created inside the newl vNet"
value = "${azurerm_subnet.subnet.*.id}"
}

output "security_group_id" {
description = "The id of the security group attached to subnets inside the newly created vNet. Use this id to associate additional network security rules to subnets."
value = "${azurerm_network_security_group.security_group.id}"
description = "The id of the security group attached to subnets inside the newly created vNet. Use this id to associate additional network security rules to subnets."
value = "${azurerm_network_security_group.security_group.id}"
}
18 changes: 18 additions & 0 deletions test/integration/default/controls/state_file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# More info please refer to: https://www.inspec.io/docs/

# Get path to terraform state file from attribute of kitchen-terraform.
terraform_state = attribute "terraform_state", {}

# Define how critical this control is.
control "state_file" do
# Define how critical this control is.
impact 0.6
# The actual test case.
describe "the Terraform state file" do
# Get json object of terraform state file.
subject do json(terraform_state).terraform_version end

# Validate the terraform version number field.
it "is accessible" do is_expected.to match /\d+\.\d+\.\d+/ end
end
end
3 changes: 3 additions & 0 deletions test/integration/default/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
name: network
version: 0.1.0
13 changes: 13 additions & 0 deletions test/integration/fixtures/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "network" {
source = "Azure/network/azurerm"
resource_group_name = "myapp"
location = "westus"
address_space = "10.0.0.0/16"
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
subnet_names = ["subnet1", "subnet2", "subnet3"]

tags = {
environment = "dev"
costcenter = "it"
}
}
3 changes: 3 additions & 0 deletions test/integration/fixtures/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "test_vnet_id" {
value = "${module.network.vnet_id}"
}
1 change: 1 addition & 0 deletions test/integration/fixtures/testing.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
location = "West US"
16 changes: 8 additions & 8 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
variable "vnet_name" {
description = "Name of the vnet to create"
default = "acctvnet"
default = "acctvnet"
}

variable "resource_group_name" {
description = "Default resource group name that the network will be created in."
default = "myapp-rg"
default = "myapp-rg"
}

variable "location" {
Expand Down Expand Up @@ -35,7 +35,8 @@ variable "subnet_names" {

variable "tags" {
description = "The tags to associate with your network and subnets."
type = "map"
type = "map"

default = {
tag1 = ""
tag2 = ""
Expand All @@ -44,16 +45,15 @@ variable "tags" {

variable "allow_rdp_traffic" {
description = "This optional variable, when set to true, adds a security rule allowing RDP traffic to flow through to the newly created network. The default value is false."
default = false
default = false
}

variable "allow_ssh_traffic" {
description = "This optional variable, when set to true, adds a security rule allowing SSH traffic to flow through to the newly created network. The default value is false."
default = false
default = false
}


variable "sg_name" {
description = "Give a name to security group"
default = "acctsecgrp"
}
default = "acctsecgrp"
}