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

[azurerm] Add os_type and image_uri in azurerm_virtual_machine #6553

Merged
merged 1 commit into from
May 9, 2016

Conversation

Erouan50
Copy link
Contributor

@Erouan50 Erouan50 commented May 9, 2016

Fix #6372

Partial fix of #6526

@stack72
Copy link
Contributor

stack72 commented May 9, 2016

Hi @Erouan50

This looks good - I will add a test for this later

Thanks for the hard work here!

Paul

@stack72 stack72 merged commit a105de1 into hashicorp:master May 9, 2016
@stack72 stack72 mentioned this pull request May 9, 2016
8 tasks
@Erouan50
Copy link
Contributor Author

Hi @stack72

Ok, you're welcome ! I hope it will help you.

Good luck for the next steps !

Erouan

@stack72
Copy link
Contributor

stack72 commented May 10, 2016

@Erouan50 looks like this has already worked for someone so that was good news :)

Thanks again

P.

@Erouan50 Erouan50 deleted the tf6372 branch May 11, 2016 16:16
@MattFenner
Copy link

doesn't seem to be working for me. i'm not sure if im using the field wrong:

note: i am putting in the url to the vhd, but the documentation says it should be in the form publisherName:offer:skus:version. but i dont know how you would do that for a custom made one.

here is my *.tf file

provider "azurerm" {
    # see https://www.terraform.io/docs/providers/azurerm/index.html
    # Credentials must be provided via the ARM_SUBSCRIPTION_ID, ARM_CLIENT_ID, ARM_CLIENT_SECRET and ARM_TENANT_ID environment variables
}

# Create a resource group
resource "azurerm_resource_group" "ait" {
    name     = "ait-res-group"
    location = "Australia Southeast"
}

# Create a virtual network
resource "azurerm_virtual_network" "ait" {
  name                = "ait-net"
  address_space       = ["10.0.0.0/16"]
  location            = "Australia Southeast"
  resource_group_name = "${azurerm_resource_group.ait.name}"
}

resource "azurerm_subnet" "ait" {
    name = "subnet"
    resource_group_name = "${azurerm_resource_group.ait.name}"
    virtual_network_name = "${azurerm_virtual_network.ait.name}"
    address_prefix = "10.0.1.0/24"
}

resource "azurerm_public_ip" "ait" {
    name = "aitpublicip"
    location = "Australia Southeast"
    resource_group_name = "${azurerm_resource_group.ait.name}"
    public_ip_address_allocation = "static"

    tags {
        environment = "Production"
    }
}

resource "azurerm_network_interface" "ait" {
    name = "ait-net-int"
    location = "Australia Southeast"
    resource_group_name = "${azurerm_resource_group.ait.name}"

    network_security_group_id = "${azurerm_network_security_group.ait.id}"

    ip_configuration {
        name = "ait-config"
        subnet_id = "${azurerm_subnet.ait.id}"
        private_ip_address_allocation = "dynamic"
        public_ip_address_id = "${azurerm_public_ip.ait.id}"
    }
}

resource "azurerm_network_security_group" "ait" {
    name = "ait-netsecgrp"
    location = "Australia Southeast"
    resource_group_name = "${azurerm_resource_group.ait.name}"

    security_rule {
        name = "allowtcp"
        priority = 1000
        direction = "Inbound"
        access = "Allow"
        protocol = "Tcp"
        source_port_range = "*"
        destination_port_range = "*"
        source_address_prefix = "*"
        destination_address_prefix = "*"
    }

    tags {
        environment = "Production"
    }
}

resource "azurerm_storage_account" "ait" {
    name = "aitstoragetransmax"
    resource_group_name = "${azurerm_resource_group.ait.name}"
    location = "Australia Southeast"
    account_type = "Standard_LRS"

    tags {
        environment = "ait"
    }
}

resource "azurerm_storage_container" "ait" {
    name = "vhds"
    resource_group_name = "${azurerm_resource_group.ait.name}"
    storage_account_name = "${azurerm_storage_account.ait.name}"
    container_access_type = "private"
}

# Create a VM
resource "azurerm_virtual_machine" "WS" {
    name = "ait-ws81"
    location = "Australia Southeast"
    resource_group_name = "${azurerm_resource_group.ait.name}"
    network_interface_ids = ["${azurerm_network_interface.ait.id}"]
    vm_size = "Standard_D2_V2" #2 core, 7GB RAM, 4x500IOPS

    storage_os_disk {
        name = "aitWS81disk"
        vhd_uri = "${azurerm_storage_account.ait.primary_blob_endpoint}${azurerm_storage_container.ait.name}/ait-ws81-disk.vhd"
        #base image
        image_uri = "https://aitbaseimages.blob.core.windows.net/baseimages/tmx-ait-ws-14x-win81-osDisk.XXXXXXXXXX.vhd"
        os_type = "windows"
        caching = "ReadWrite"
        create_option = "FromImage"
    }

    os_profile {
        computer_name = "ait-ws81"
        admin_username = "aituser"
        admin_password = "Password!"
    }

    os_profile_windows_config {
        enable_automatic_upgrades = true
    }

    tags {
        environment = "ait"
    }
}

the error i am getting is:

Error applying plan:

1 error(s) occurred:

* azurerm_virtual_machine.WS: autorest:DoErrorUnlessStatusCode 400 PUT https://management.azure.com/subscriptions/ab81cd
b8-10b7-490f-8fa5-bace16ec151f/resourceGroups/ait-res-group/providers/Microsoft.Compute/virtualMachines/ait-ws81?api-ver
sion=2015-06-15 failed with 400 Bad Request

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

which isnt much help

@Erouan50
Copy link
Contributor Author

Hi @MattFenner

I guess our problem comes from your custom image. It should be in the same storage account of our virtual machine's storage. I advice you to create your storage account with an other tf file and copy your image when the storage account is created.

@MattFenner
Copy link

MattFenner commented May 15, 2016

oh i didnt realise it had to be in the same storage account. i was trying to keep it separate so i didnt delete it when i went terraform destroy

@Erouan50 is there any way to get better error messages, the built in ones seem very unhelpful?

@Erouan50
Copy link
Contributor Author

Yes is not very useful... About the error messages, I guest when this issue #6526 will be close, they will be displayed correctly. Meanwhile, you can see all errors in audit log of your resource group from azure gui.

cristicalin pushed a commit to cristicalin/terraform that referenced this pull request May 24, 2016
@pearcec
Copy link
Contributor

pearcec commented Jul 22, 2016

Is that a limitation of the code in terraform or with ARM? @Erouan50

@stack72
Copy link
Contributor

stack72 commented Jul 22, 2016

Hi @pearcec

I would say it's actually both. Firstly, ARM should detect it, but secondly, TF should have supported it from the start :)

This will be fixed when 0.7 lands soon!

Paul

@pearcec
Copy link
Contributor

pearcec commented Jul 22, 2016

@stack72 Looks like this was merged into 0.6.16. I can't get it to work I get the same issue even trying to use the same storage account. Looks like it was successful for some. Anyone have a working example?

@ghost
Copy link

ghost commented Apr 24, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm - error creating vm from existing vhd - osType not supplied
4 participants