Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # resource group definitions
- resource "azurerm_resource_group" "rg" {
- name = "${var.resource_group}"
- location = "${var.location}"
- }
- resource "azurerm_storage_account" "stor" {
- name = "${var.rg_prefix}stor${count.index}"
- location = "${var.location}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- account_tier = "${var.storage_account_tier}"
- account_replication_type = "${var.storage_replication_type}"
- }
- resource "azurerm_public_ip" "pip" {
- name = "${var.rg_prefix}-ip${count.index}"
- location = "${var.location}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- public_ip_address_allocation = "dynamic"
- }
- # network definitions
- resource "azurerm_virtual_network" "vnet" {
- name = "${var.virtual_network_name}"
- location = "${var.location}"
- address_space = ["${var.address_space}"]
- resource_group_name = "${azurerm_resource_group.rg.name}"
- }
- resource "azurerm_subnet" "subnet" {
- name = "${var.rg_prefix}subnet${count.index}"
- virtual_network_name = "${azurerm_virtual_network.vnet.name}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- address_prefix = "${var.subnet_prefix}"
- }
- resource "azurerm_network_interface" "nic" {
- # name = "nic${var.rg_prefix}${count.index}"
- name = "primaryNic${count.index}"
- location = "${var.location}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- # count = 2
- ip_configuration {
- name = "ipconfig${var.rg_prefix}${count.index}"
- subnet_id = "${azurerm_subnet.subnet.id}"
- private_ip_address_allocation = "dynamic"
- public_ip_address_id = "${azurerm_public_ip.pip.id}"
- }
- tags {
- environment = "staging"
- }
- }
- resource "azurerm_virtual_machine" "vm" {
- name = "vm${count.index}"
- location = "${var.location}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- vm_size = "${var.vm_size}"
- network_interface_ids = ["${azurerm_network_interface.nic.id}"]
- delete_data_disks_on_termination = true
- delete_os_disk_on_termination = true
- count = 2
- storage_image_reference {
- publisher = "${var.image_publisher}"
- offer = "${var.image_offer}"
- sku = "${var.image_sku}"
- version = "${var.image_version}"
- }
- storage_os_disk {
- name = "${lookup(var.osdisk, count.index)}"
- create_option = "FromImage"
- }
- os_profile {
- computer_name = "${lookup(var.hostname, count.index)}"
- admin_username = "${var.admin_username}"
- admin_password = "${var.admin_password}"
- }
- os_profile_linux_config {
- disable_password_authentication = false
- }
- }
- data "azurerm_public_ip" "test" {
- name = "${azurerm_public_ip.pip.name}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- depends_on = ["azurerm_virtual_machine.vm"]
- }
- resource "null_resource" "null" {
- provisioner "remote-exec" {
- inline = [
- "echo ${var.admin_password} | sudo -S hostnamectl set-hostname nels-sample1",
- ]
- connection {
- type = "ssh"
- agent = false
- host = "${data.azurerm_public_ip.test.ip_address}"
- user = "${var.admin_username}"
- password = "${var.admin_password}"
- timeout = "10m"
- }
- }
- }
- resource "azurerm_network_security_group" "nsg" {
- name = "nsg${var.resource_group}"
- location = "${var.location}"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- security_rule {
- name = "SSH_Officea1"
- priority = 1002
- direction = "Inbound"
- access = "Allow"
- protocol = "Tcp"
- source_port_range = "*"
- destination_port_range = "22"
- source_address_prefix = "*"
- destination_address_prefix = "*"
- }
- tags {
- environment = "Public Cloud Nodes"
- }
- security_rule {
- name = "SSH_Officeb2"
- priority = 1001
- direction = "Inbound"
- access = "Allow"
- protocol = "Tcp"
- source_port_range = "*"
- destination_port_range = "22"
- source_address_prefix = "*"
- destination_address_prefix = "*"
- }
- tags {
- environment = "Public Cloud Nodes"
- }
- }
Add Comment
Please, Sign In to add comment