hashicorp / terraform-provider-azure-classic

Terraform Azure Classic (Service Management) provider
https://www.terraform.io/docs/providers/azure/
Mozilla Public License 2.0
3 stars 11 forks source link

I am not able to create multiple VMs which belong to the same service #6

Closed hashibot closed 6 years ago

hashibot commented 7 years ago

This issue was originally opened by @ravbaba as hashicorp/terraform#3568. It was migrated here as part of the provider split. The original body of the issue is below.


I am able to create VMs but only if each of them belong to a separate service but if I am trying the below code to create multiple VMs assigned to the same service I am not able to create anything. Is there something wrong with my code or it is a bug?

resource "azure_hosted_service" "terraform-service" {
    name = "terraform-service"
    location = "North Europe"
    ephemeral_contents = false
    description = "Hosted service created by Terraform."
    label = "tf-hs-01"
}

resource "azure_instance" "web" {
    name = "terraform-test-${count.index}"
    count = 3
    hosted_service_name = "${azure_hosted_service.terraform-service.name}"
    image = "Ubuntu Server 14.04 LTS"
    size = "Basic_A1"
    storage_service_name = "yourstorage"
    location = "West US"
    username = "terraform"
    password = "Pass!admin123"

    endpoint {
        name = "SSH"
        protocol = "tcp"
        public_port = 22
        private_port = 22
    }
}

I got the error:

* Error creating instance terraform-test-0: Error response from Azure. Code: ConflictError, Message: The specified deployment slot Production is occupied.
* Error creating instance terraform-test-2: Error response from Azure. Code: ConflictError, Message: The specified deployment slot Production is occupied.
hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-152738025. It was migrated here as part of the provider split. The original comment is below.


This is a big one. Facing the same issue. Tried a lot of different things, still getting the same issue. It appears that Azure-wise there is a solution. The last post on this thread discusses the solution from the Azure side: http://answers.flyppdevportal.com/categories/azure/azuredevelopment.aspx?ID=4d8faa0e-557c-4a97-b76b-c611ab21cec8

Agreed that the solution from Azure side is ugly, but still should work. Can someone implement the solution on the terraform side please? Thanks!

hashibot commented 7 years ago

This comment was originally opened by @coreyperkins as https://github.com/hashicorp/terraform/issues/3568#issuecomment-153164405. It was migrated here as part of the provider split. The original comment is below.


I am seeing this as well. I can make it happen two different ways.

1) Create a config with a single hosted service and a single azure instance. Plan/Apply. Then, add a second azure instance to the config and do another Plan/Apply.

2) Create a config with a single hosted service and two azure instances. Plan/Apply. End result will be that one of the instances will get created and you'll receive the error message above when it tries to create the second instance.

I think the error is getting thrown on line 355 of this file -> https://github.com/hashicorp/terraform/blob/v0.6.6/builtin/providers/azure/resource_azure_instance.go

After digging into the Azure SDK for Go I believe a call to the Add Role endpoint (https://msdn.microsoft.com/en-us/library/azure/jj157186.aspx) is simply missing. See this file -> https://github.com/Azure/azure-sdk-for-go/blob/master/management/virtualmachine/client.go

Pretty well limits what you can do with Azure atm.

hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-155676250. It was migrated here as part of the provider split. The original comment is below.


+1 To fix this problem, we have to

(1) add an AddRole function here: https://github.com/Azure/azure-sdk-for-go/blob/master/management/virtualmachine/client.go

(2) use that function in resource_azure_instance.go here: https://github.com/hashicorp/terraform/blob/master/builtin/providers/azure/resource_azure_instance.go

(in resourceAzureInstanceCreate(...) and possibly in Update/Delete as well - so that when an azure instance is created, and hosted_service_name is specified, it should call this new AddRole function and add the new VM to an existing cloud service. However, it may be tricky and error-prone, as there is already some not-so-readable logic around "has_dedicated_service", so the developer who added that piece of logic should probably do it and test it properly)

hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-156589096. It was migrated here as part of the provider split. The original comment is below.


@mitchellh @catsby @armon @phinze - Sorry to spam you, but I am assuming one or more among you have the power to assign this bug to me. I am actively working on this, and will have a fix that i can submit a pull request for soon. I have already made changes to the underlying azure-sdk-for-go code, and my changes were merged today (see https://github.com/Azure/azure-sdk-for-go/pull/234)

Thanks

hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-157726899. It was migrated here as part of the provider split. The original comment is below.


Update - this bug is fixed on my fork. Depends on some changes that needed to be made to azure-sdk-for-go. The last of such changes to azure-sdk-for-go is pending as a pull request here: https://github.com/Azure/azure-sdk-for-go/pull/238. Previous changes to azure-sdk-for-go have been accepted and merged in this pull request: https://github.com/Azure/azure-sdk-for-go/pull/234

Once azure-sdk-for-go is updated, I will submit terraform changes as a pull request.

Requesting assignment of this bug to me. Thanks.

hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-157727836. It was migrated here as part of the provider split. The original comment is below.


If anyone is interested to review the fix, it is contained to one file in terraform (resource_azure_instance.go), but it depends on some changes made to azure-sdk-for-go - they can view the changes here: https://github.com/hashicorp/terraform/compare/master...kbxkb:master

hashibot commented 7 years ago

This comment was originally opened by @kbxkb as https://github.com/hashicorp/terraform/issues/3568#issuecomment-162694587. It was migrated here as part of the provider split. The original comment is below.


Update: A fix for this bug is awaiting to be reviewed, accepted and merged: https://github.com/hashicorp/terraform/pull/4199

vancluever commented 6 years ago

Hello!

Thank you for opening this issue and participating in the discussion. Today (December 19, 2017) we’ve announced the deprecation and archival of the Azure Classic Provider. Matching Microsoft’s commitment to gradually remove access to Azure Classic (or Service Management) which is outlined in this blog post, we are closing all open PR's and Issues here. This repository will remain available here on GitHub, but in an archived state, and no longer receiving support or new releases.

The Azure (Resource Manager) Provider remains fully supported and is our recommended approach for managing Azure with Terraform. More information about this process is available in the blog post linked above.

Thanks! The Terraform Team