Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##################################################################################
- # VARIABLES
- ##################################################################################
- #variable "aws_access_key" {}
- #variable "aws_secret_key" {}
- #variable "private_key_path" {}
- #variable "key_name" {
- # default = ""
- #}
- #IMPORTED VARIABLES
- variable "azure_msdn_client_id" {}
- variable "azure_msdn_client_secret" {}
- variable "azure_msdn_tenant_id" {}
- variable "azure_msdn_subscription_id" {}
- #LOCAL STATIC VARIABLES
- variable "prefix" {
- default = "firstrun"
- }
- ##################################################################################
- # PROVIDERS
- ##################################################################################
- #provider "aws" {
- # access_key = "${var.aws_access_key}"
- # secret_key = "${var.aws_secret_key}"
- # region = "us-east-1"
- #}
- # Configure the Azure Provider
- provider "azurerm" {
- # whilst the `version` attribute is optional, we recommend pinning to a given version of the Provider
- # version = "=1.28.0"
- # version = "=2.0.0"
- # version = "~> 1.x"
- subscription_id = "${var.azure_msdn_subscription_id}"
- client_id = "${var.azure_msdn_client_id}"
- client_secret = "${var.azure_msdn_client_secret}"
- tenant_id = "${var.azure_msdn_tenant_id}"
- }
- ##################################################################################
- # RESOURCES
- ##################################################################################
- # Create a resource group
- resource "azurerm_resource_group" "tf-rg" {
- name = "${var.prefix}-resourcegroup"
- location = "uksouth"
- }
- # Create a virtual network within the resource group
- resource "azurerm_virtual_network" "tf-vn" {
- name = "${var.prefix}-network"
- resource_group_name = "${azurerm_resource_group.tf-rg.name}"
- location = "${azurerm_resource_group.tf-rg.location}"
- address_space = ["192.168.0.0/16"]
- }
- # Create a subnet within the vnet
- resource "azurerm_subnet" "tf-sn" {
- name = "${var.prefix}-subnet"
- resource_group_name = "${azurerm_resource_group.tf-rg.name}"
- virtual_network_name = "${azurerm_virtual_network.tf-vn.name}"
- address_prefix = "192.168.254.0/24"
- }
- #Create a network interface for the VM
- resource "azurestack_network_interface" "tf-ni" {
- name = "${var.prefix}-networkinterface"
- location = "${azurerm_resource_group.tf-rg.location}"
- resource_group_name = "${azurerm_resource_group.tf-rg.name}"
- ip_configuration {
- name = "${var.prefix}-ipconfiguration1"
- subnet_id = "${azurerm_subnet.tf-sn.id}"
- private_ip_address_allocation = "dynamic"
- }
- }
- # Create a virtual machine within the subnet
- resource "azurerm_virtual_machine" "az-vm" {
- name = "${var.prefix}-virtualmachine"
- resource_group_name = "${azurerm_resource_group.tf-rg.name}"
- location = "${azurerm_resource_group.tf-rg.location}"
- vm_size = "Standard_B1ms"
- network_interface_ids = ["${azurestack_network_interface.tf-ni.id}"]
- delete_os_disk_on_termination = true
- delete_data_disks_on_termination = true
- storage_image_reference {
- publisher = "Canonical"
- offer = "UbuntuServer"
- sku = "16.04-LTS"
- version = "latest"
- }
- storage_os_disk {
- name = "myosdisk1"
- caching = "ReadWrite"
- create_option = "FromImage"
- managed_disk_type = "Standard_LRS"
- }
- os_profile {
- computer_name = "hostname"
- admin_username = "testadmin"
- admin_password = "Password1234!"
- }
- os_profile_linux_config {
- disable_password_authentication = false
- }
- tags = {
- environment = "${var.prefix}"
- }
- }
- #resource "aws_instance" "nginx" {
- # ami = "ami-c58c1dd3"
- # instance_type = "t2.micro"
- # key_name = "${var.key_name}"
- #
- # connection {
- # user = "ec2-user"
- # private_key = "${file(var.private_key_path)}"
- # }
- #
- # provisioner "remote-exec" {
- # inline = [
- # "sudo yum install nginx -y",
- # "sudo service nginx start"
- # ]
- # }
- #}
- ##################################################################################
- # OUTPUT
- ##################################################################################
- output "azurerm_virtual_instance" {
- # value = "${azurerm_virtual_machine.az-vm.private_ip}"
- value = "finished"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement