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_image" gets recreated with every run #234

Closed
hashibot opened this issue Aug 10, 2017 · 10 comments · Fixed by #1443
Closed

"azurerm_image" gets recreated with every run #234

hashibot opened this issue Aug 10, 2017 · 10 comments · Fixed by #1443
Assignees
Milestone

Comments

@hashibot
Copy link

This issue was originally opened by @spbreed as hashicorp/terraform#15773. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.10.0

Terraform Configuration Files

resource "azurerm_image" "test" {
  name = "acctest"
  location = "East US 2"
  resource_group_name = "${azurerm_resource_group.test.name}"
  os_disk {
    os_type = "Linux"
    os_state = "Generalized"
    blob_uri = "https://pcsnonprodimages.blob.core.windows.net/system/Microsoft.Compute/Images/images/pcsnonprod-ubuntuv01-osDisk.6a65bac6-bc69-4785-948b-a419820c76f0.vhd"
    # size_gb = 30
  }
}

Debug Output

terraform apply

azurerm_resource_group.test: Creating...
  location: "" => "eastus2"
  name:     "" => "acctestrg"
  tags.%:   "" => "<computed>"
azurerm_resource_group.test: Creation complete (ID: /subscriptions/9bc818d2-70ea-4c3a-9677-0d312a2e5b65/resourceGroups/acctestrg)
azurerm_image.test: Creating...
  location:                           "" => "eastus2"
  name:                               "" => "acctest"
  os_disk.#:                          "" => "1"
  os_disk.3156744706.blob_uri:        "" => "https://pcsnonprodimages.blob.core.windows.net/system/Microsoft.Compute/Images/images/pcsnonprod-ubuntuv01-osDisk.6a65bac6-bc69-4785-948b-a419820c76f0.vhd"
  os_disk.3156744706.managed_disk_id: "" => "<computed>"
  os_disk.3156744706.os_state:        "" => "Generalized"
  os_disk.3156744706.os_type:         "" => "Linux"
  os_disk.3156744706.size_gb:         "" => "<computed>"
  resource_group_name:                "" => "acctestrg"
  tags.%:                             "" => "<computed>"
azurerm_image.test: Still creating... (10s elapsed)
azurerm_image.test: Still creating... (20s elapsed)
azurerm_image.test: Still creating... (30s elapsed)
azurerm_image.test: Still creating... (40s elapsed)
azurerm_image.test: Still creating... (50s elapsed)
azurerm_image.test: Still creating... (1m0s elapsed)
azurerm_image.test: Creation complete (ID: /subscriptions/9bc818d2-70ea-4c3a-9677-...iders/Microsoft.Compute/images/acctest)

terraform plan

Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

azurerm_resource_group.test: Refreshing state... (ID: /subscriptions/9bc818d2-70ea-4c3a-9677-0d312a2e5b65/resourceGroups/acctestrg)
azurerm_image.test: Refreshing state... (ID: /subscriptions/9bc818d2-70ea-4c3a-9677-...iders/Microsoft.Compute/images/acctest)
The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

-/+ azurerm_image.test (new resource required)
      location:                           "eastus2" => "eastus2"
      name:                               "acctest" => "acctest"
      os_disk.#:                          "1" => "1"
      os_disk.2453480131.os_state:        "Generalized" => ""
      os_disk.2453480131.os_type:         "Linux" => ""
      os_disk.3156744706.blob_uri:        "" => "https://pcsnonprodimages.blob.core.windows.net/system/Microsoft.Compute/Images/images/pcsnonprod-ubuntuv01-osDisk.6a65bac6-bc69-4785-948b-a419820c76f0.vhd" (forces new resource)
      os_disk.3156744706.managed_disk_id: "" => "<computed>"
      os_disk.3156744706.os_state:        "" => "Generalized"
      os_disk.3156744706.os_type:         "" => "Linux"
      os_disk.3156744706.size_gb:         "" => "<computed>"
      resource_group_name:                "acctestrg" => "acctestrg"
      tags.%:                             "0" => "<computed>"


Plan: 1 to add, 0 to change, 1 to destroy.

TF state file

"primary": {
                        "id": "/subscriptions/9bc818d2-70ea-4c3a-9677-0d312a2e5b65/resourceGroups/acctestrg/providers/Microsoft.Compute/images/acctest",
                        "attributes": {
                            "data_disk.#": "0",
                            "id": "/subscriptions/9bc818d2-70ea-4c3a-9677-0d312a2e5b65/resourceGroups/acctestrg/providers/Microsoft.Compute/images/acctest",
                            "location": "eastus2",
                            "name": "acctest",
                            "os_disk.#": "1",
                            "os_disk.2453480131.blob_uri": "https://pcsnonprodimages.blob.core.windows.net/system/Microsoft.Compute/Images/images/pcsnonprod-ubuntuv01-osDisk.6a65bac6-bc69-4785-948b-a419820c76f0.vhd",
                            "os_disk.2453480131.caching": "None",
                            "os_disk.2453480131.managed_disk_id": "",
                            "os_disk.2453480131.os_state": "Generalized",
                            "os_disk.2453480131.os_type": "Linux",
                            "os_disk.2453480131.size_gb": "0",
                            "resource_group_name": "acctestrg",
                            "tags.%": "0"
                        },
                        "meta": {},
                        "tainted": false
                    },

Panic Output

Expected Behavior

Terraform plan should not recreate the resource

Actual Behavior

with every run image is deleted and recreated. refer "Debug Output" section

Steps to Reproduce

  1. terraform apply (to create iy for the first time)
  2. terraform plan or terraform apply -> recreates the image again

This in turn recreates the VM as Image_ID is referenced storage_image_reference

@echuvyrov
Copy link
Contributor

I think this is a duplicate of #224, I am looking into the issue (unable to reproduce, requested additional info).

@rcarun rcarun added this to the M1 milestone Oct 11, 2017
@rcarun
Copy link

rcarun commented Oct 12, 2017

Seems to be fixed #224. Requires validation

@rcarun rcarun added the msft label Oct 12, 2017
@JunyiYi
Copy link

JunyiYi commented Oct 17, 2017

I'm still able to reproduce this issue. Here is my image.tf file:

resource "azurerm_image" "test" {
  name = "myimgname"
  location = "West US"
  resource_group_name = "myresourcegroup"
  os_disk {
    os_type = "Linux"
    os_state = "Generalized"
    blob_uri = "https://myblobaccount.blob.core.windows.net/osimage/xenial-server-cloudimg-amd64-disk1.vhd"
  }
}

And here is the output. First create a new resource:

$ terraform apply
azurerm_image.test: Creating...
  location:                           "" => "westus"
  name:                               "" => "myimgname"
  os_disk.#:                          "" => "1"
  os_disk.1842404614.blob_uri:        "" => "https://myblobaccount.blob.core.windows.net/osimage/xenial-server-cloudimg-amd64-disk1.vhd"
  os_disk.1842404614.caching:         "" => "None"
  os_disk.1842404614.managed_disk_id: "" => "<computed>"
  os_disk.1842404614.os_state:        "" => "Generalized"
  os_disk.1842404614.os_type:         "" => "Linux"
  os_disk.1842404614.size_gb:         "" => "<computed>"
  resource_group_name:                "" => "myresourcegroup"
  tags.%:                             "" => "<computed>"
azurerm_image.test: Still creating... (10s elapsed)
azurerm_image.test: Still creating... (20s elapsed)
azurerm_image.test: Still creating... (30s elapsed)
azurerm_image.test: Still creating... (40s elapsed)
azurerm_image.test: Still creating... (50s elapsed)
azurerm_image.test: Still creating... (1m0s elapsed)
azurerm_image.test: Creation complete after 1m7s (ID: /subscriptions/2085065b-00f8-4cba-9675-...crosoft.Compute/images/myimgname)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Then run the plan command:

$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

azurerm_image.test: Refreshing state... (ID: /subscriptions/2085065b-00f8-4cba-9675-...crosoft.Compute/images/myimgname)

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
-/+ destroy and then create replacement

Terraform will perform the following actions:

-/+ azurerm_image.test (new resource required)
      id:                                 "/subscriptions/2085065b-00f8-4cba-9675-ba15f4d4ab66/resourceGroups/junyiacctestRG/providers/Microsoft.Compute/images/myimgname" => <computed> (forces new resource)
      location:                           "westus" => "westus"
      name:                               "myimgname" => "myimgname"
      os_disk.#:                          "1" => "1"
      os_disk.1807029459.caching:         "None" => ""
      os_disk.1807029459.os_state:        "Generalized" => ""
      os_disk.1807029459.os_type:         "Linux" => ""
      os_disk.1842404614.blob_uri:        "" => "https://myblobaccount.blob.core.windows.net/osimage/xenial-server-cloudimg-amd64-disk1.vhd" (forces new resource)
      os_disk.1842404614.caching:         "" => "None"
      os_disk.1842404614.managed_disk_id: "" => <computed>
      os_disk.1842404614.os_state:        "" => "Generalized"
      os_disk.1842404614.os_type:         "" => "Linux"
      os_disk.1842404614.size_gb:         "" => <computed>
      resource_group_name:                "myresourcegroup" => "myresourcegroup"
      tags.%:                             "0" => <computed>


Plan: 1 to add, 0 to change, 1 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

And my terraform version is:

$ terraform --version
Terraform v0.10.8-dev (5fb1fe9de8ca3c4655ddd25098c7e486caae9a2a)

@VaijanathB VaijanathB self-assigned this Oct 20, 2017
@VaijanathB
Copy link
Contributor

Hey,

This issue can now be addressed with using datasource for azurerm_image. Here is the example that shows how to use the new data source.

Using the data source for Resource

data "azurerm_resource_group" "image" {
name = "myResourceGroup"
}

Using the data source for Image.

data "azurerm_image" "image" {
name = "myPackerImage"
resource_group_name = "${data.azurerm_resource_group.image.name}"
}

By using data source you can reference existing images that need not be recreated every time.

@VaijanathB
Copy link
Contributor

@spbreed, Does this solve your issue?

@pmarques
Copy link

pmarques commented Nov 6, 2017

@VaijanathB How can we stop the resource "azurerm_image" "test" creating the new image with this? I need an idempotent plan.

@VaijanathB
Copy link
Contributor

Hello Pmarques,

Can you please provide the tf script that you are trying out. Ideally you use data source if you already have an image and do not want to create the resource in your tf script. Having said that, once you have an azurerm_image resource, it should be idempotent provided all the properties evaluate the same. If you have an example where this is not happening, please update this thread with your tf script.

Thanks,
VaijanathB

@pmarques
Copy link

@VaijanathB My script just an example from Terraform, you can pick the most simple example for azurerm_image, the resource is not idempotent unless you set the ignore_changes #224 (comment). However this issue seems to be "fixed" #224

@tombuildsstuff tombuildsstuff added this to the Temp/To Be Sorted milestone Apr 17, 2018
@achandmsft achandmsft modified the milestones: Temp/To Be Sorted, 1.4.0 Apr 19, 2018
@tombuildsstuff tombuildsstuff modified the milestones: 1.4.0, 1.5.0 Apr 25, 2018
@tombuildsstuff tombuildsstuff modified the milestones: 1.5.0, 1.6.0 May 8, 2018
@binlan
Copy link

binlan commented May 16, 2018

i can confirm that i still have this problem.
`Terraform v0.11.3

  • provider.azurerm v1.5.0
  • provider.random v1.2.0`

@katbyte katbyte removed M1 labels May 17, 2018
@katbyte katbyte self-assigned this May 17, 2018
@tombuildsstuff tombuildsstuff modified the milestones: 1.6.0, 1.7.0 May 21, 2018
@katbyte katbyte modified the milestones: 1.7.0, Soon Jun 12, 2018
@katbyte katbyte modified the milestones: Soon, 1.8.0, 1.9.0 Jun 26, 2018
@ghost
Copy link

ghost commented Mar 30, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

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

Successfully merging a pull request may close this issue.

10 participants