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

Fix existing examples. Add new examples along with changes in README and CHANGELOG #346

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixing the existing examples and adding new.
  • Loading branch information
bhati-pradeep authored and siddharth-nutanix committed Feb 15, 2022
commit 879c021fd41f71906f5500f0ae2a8a9c9cfe63fa
293 changes: 293 additions & 0 deletions examples/security_rules/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
###################################
# General
###################################

terraform {
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.3.0"
}
}
}

#define nutanix provider configuration
provider "nutanix" {
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = var.port
insecure = true
wait_timeout = 60
}

###################################
# Data input
###################################

#retrieve the cluster corresponding to the cluster name variable
data "nutanix_cluster" "cluster" {
name = var.cluster_name
}
#retrieve the network corresponding to the network name variable
data "nutanix_subnet" "subnet" {
subnet_name = var.subnet_name
}

#retrieve image details
data "nutanix_image" "image"{
image_name = "CentOS-7 Generic Cloud managed by Terraform"
}

###################################
# Categories
###################################
#create category named DEMO-DOLIBARR-TIER
resource "nutanix_category_key" "demo-dolibarr-tier" {
name = "DEMO-DOLIBARR-TIER"
description = "TIER Category Key"
}

#add category values in above created category
resource "nutanix_category_value" "LB" {
name = nutanix_category_key.demo-dolibarr-tier.id
description = "LoadBalancer Tier"
value = "LoadBalancer"
}
resource "nutanix_category_value" "WEB" {
name = nutanix_category_key.demo-dolibarr-tier.id
description = "Webserver Tier"
value = "Webserver"
}
resource "nutanix_category_value" "DB" {
name = nutanix_category_key.demo-dolibarr-tier.id
description = "Database Tier"
value = "Database"
}

###################################
# uSeg
###################################
#creating security rules

resource "nutanix_network_security_rule" "loadbalancer" {
name = "DEMO-TERRAFORM-DOLIBARR" #name of the uSeg rules
description = "DEMO-TERRAFORM-DOLIBARR"
app_rule_action = "MONITOR"


app_rule_target_group_peer_specification_type = "FILTER"
app_rule_target_group_default_internal_policy = "ALLOW_ALL"
app_rule_target_group_filter_type = "CATEGORIES_MATCH_ALL"
app_rule_target_group_filter_kind_list = [
"vm"
]

app_rule_target_group_filter_params {
name = "AppType"
values = [
"Default"
]
}

#filter with previously created category key-value
app_rule_target_group_filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"LoadBalancer"
]
}

app_rule_inbound_allow_list {
ip_subnet = "10.xx.xx.xx"
ip_subnet_prefix_length = "0"
peer_specification_type = "IP_SUBNET"
protocol = "TCP"
tcp_port_range_list {
end_port = 88
start_port = 88
}
tcp_port_range_list {
end_port = 89
start_port = 89
}
}

app_rule_outbound_allow_list {
ip_subnet = "10.xx.xx.xx"
ip_subnet_prefix_length = "0"
peer_specification_type = "IP_SUBNET"
protocol = "TCP"
tcp_port_range_list {
end_port = 88
start_port = 88
}
tcp_port_range_list {
end_port = 89
start_port = 89
}
}
}

resource "nutanix_network_security_rule" "webserver" {
name = "DEMO-TERRAFORM-DOLIBARR"
description = "DEMO-TERRAFORM-DOLIBARR"
app_rule_action = "MONITOR"


app_rule_target_group_peer_specification_type = "FILTER"
app_rule_target_group_default_internal_policy = "ALLOW_ALL"
app_rule_target_group_filter_type = "CATEGORIES_MATCH_ALL"
app_rule_target_group_filter_kind_list = [
"vm"
]

app_rule_target_group_filter_params {
name = "AppType"
values = [
"Default"
]
}
#filter with previously created category key-value
app_rule_target_group_filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"Webserver"
]
}
}

resource "nutanix_network_security_rule" "database" {
name = "DEMO-TERRAFORM-DOLIBARR"
description = "DEMO-TERRAFORM-DOLIBARR"
app_rule_action = "MONITOR"


app_rule_target_group_peer_specification_type = "FILTER"
app_rule_target_group_default_internal_policy = "ALLOW_ALL"
app_rule_target_group_filter_type = "CATEGORIES_MATCH_ALL"
app_rule_target_group_filter_kind_list = [
"vm"
]

app_rule_target_group_filter_params {
name = "AppType"
values = [
"Default"
]
}
#filter with previously created category key-value
app_rule_target_group_filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"Database"
]
}
}

resource "nutanix_network_security_rule" "loadbalancer-webserver" {
name = "DEMO-TERRAFORM-DOLIBARR"
description = "DEMO-TERRAFORM-DOLIBARR"
app_rule_action = "MONITOR"


app_rule_inbound_allow_list {
filter_type = "CATEGORIES_MATCH_ALL"
filter_params {
name = "AppType"
values = [
"Default"
]
}
#filter with previously created category key-value
filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"LoadBalancer"
]
}
filter_kind_list = ["vm"]
peer_specification_type = "FILTER"
protocol = "TCP"
tcp_port_range_list {
end_port = 88
start_port = 88
}
}


app_rule_target_group_peer_specification_type = "FILTER"
app_rule_target_group_default_internal_policy = "ALLOW_ALL"
app_rule_target_group_filter_type = "CATEGORIES_MATCH_ALL"
app_rule_target_group_filter_kind_list = [
"vm"
]

app_rule_target_group_filter_params {
name = "AppType"
values = [
"Default"
]
}
#filter with previously created category key-value
app_rule_target_group_filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"Webserver"
]
}
}

#create security rule
resource "nutanix_network_security_rule" "webserver-database" {
name = "DEMO-TERRAFORM-DOLIBARR"
description = "DEMO-TERRAFORM-DOLIBARR"
app_rule_action = "MONITOR"


app_rule_inbound_allow_list {
filter_type = "CATEGORIES_MATCH_ALL"
filter_params {
name = "AppType"
values = [
"Default"
]
}

#filter with previously created category key-value
filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"Webserver"
]
}
filter_kind_list = ["vm"]
peer_specification_type = "FILTER"
protocol = "TCP"
tcp_port_range_list {
end_port = 3333
start_port = 3333
}
}


app_rule_target_group_peer_specification_type = "FILTER"
app_rule_target_group_default_internal_policy = "ALLOW_ALL"
app_rule_target_group_filter_type = "CATEGORIES_MATCH_ALL"
app_rule_target_group_filter_kind_list = [
"vm"
]

app_rule_target_group_filter_params {
name = "AppType"
values = [
"Default"
]
}
app_rule_target_group_filter_params {
name = "DEMO-DOLIBARR-TIER"
values = [
"Database"
]
}
}
8 changes: 8 additions & 0 deletions examples/security_rules/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "Nutanix/123456"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440

subnet_name = "<subnet_name>"
cluster_name = "<cluster_name>"
19 changes: 19 additions & 0 deletions examples/security_rules/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#define the type of variables to be used in terraform file
variable "nutanix_username" {
type = string
}
variable "nutanix_password" {
type = string
}
variable "nutanix_endpoint" {
type = string
}
variable "nutanix_port" {
type = string
}
variable "cluster_name" {
type = string
}
variable "subnet_name" {
type = string
}
62 changes: 62 additions & 0 deletions examples/subnets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
terraform{
required_providers {
nutanix = {
source = "nutanix/nutanix"
version = "1.3.0"
}
}
}

#definig nutanix configuration
provider "nutanix"{
username = var.nutanix_username
password = var.nutanix_password
endpoint = var.nutanix_endpoint
port = 9440
insecure = true
}

#pull all clusters data
data "nutanix_clusters" "clusters"{}

#create local variable pointing to desired cluster
locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

#creating subnet
resource "nutanix_subnet" "vlan-112" {
# What cluster will this VLAN live on?
cluster_uuid = local.cluster1

# General Information
name = "vlan-112-managed"
vlan_id = 112
subnet_type = "VLAN"

# Managed L3 Networks
# This bit is only needed if you intend to turn on IPAM
prefix_length = 24

default_gateway_ip = "10.xx.xx.xx"
subnet_ip = "10.xx.xx.xx"

ip_config_pool_list_ranges = ["10.xx.xx.xx 10.xx.xx.xx"]

dhcp_domain_name_server_list = ["10.xx.xx.xx"]
dhcp_domain_search_list = ["nxlab.fr"]

dhcp_options = {
domain_name = "lab.fr"
tftp_server_name = "tftp.lab.fr"
boot_file_name = "pxelinux.0"
}
}

#output the subnet info
output "subnet" {
value = nutanix_subnet.vlan-112
}
5 changes: 5 additions & 0 deletions examples/subnets/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define values to the variables to be used in terraform file
nutanix_username = "admin"
nutanix_password = "Nutanix/123456"
nutanix_endpoint = "10.xx.xx.xx"
nutanix_port = 9440
Loading