hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.66k stars 9.55k forks source link

Terraform DSC does not produce Idempotent results - errors on re-run #17080

Closed sada-kubsad closed 6 years ago

sada-kubsad commented 6 years ago

Re-running a Terraform script with Azure DSC fails regardless of the DSC changes.

From looking at the DSC log files on the Azure VM, it seems that DSC is not picking up the new config changes.

It works when we deploy everything from scratch but fails when making incremental changes to DSC configs and relaunching from Terraform.

Please see below for details:

Terraform Version

0.11.1

Terraform Configuration Files

resource "azurerm_virtual_machine_extension"  "example_DSC" {
    name = "${var.customerAcronym}-${var.environment}-${var.machineAcronyms["example"]}-dsc"
    location = "${var.location}"
    resource_group_name = "${azurerm_resource_group.rg.name}"
virtual_machine_name="${var.customerAcronym}-${var.environment}-${var.machineAcronyms["example"]}"
    publisher ="Microsoft.Powershell"
    type ="DSC"
    type_handler_version = "${var.dsc_extension}"
    auto_upgrade_minor_version = true
    depends_on = ["azurerm_virtual_machine.example"]
    settings = <<SETTINGS
    {
        "configuration": {
            "url": "${var.resourceStore["fileShareUrl"]}${var.resourceStore["dscArchiveName"]}${var.azureCredentials["storageKey"]}",
            "function": "example",
            "script": "example.ps1"
        },
        "configurationArguments": {
        }
    }

    SETTINGS
    protected_settings = <<PROTECTED_SETTINGS
    {
        "configurationArguments": {
        }
    }
    PROTECTED_SETTINGS
}

Debug Output

azurerm_virtual_machine_extension.ArcGIS_Server_DSC: Still creating... (1m0s elapsed)

Error: Error applying plan:

1 error(s) occurred:

* azurerm_virtual_machine_extension.ArcGIS_Server_DSC: 1 error(s) occurred:

* azurerm_virtual_machine_extension.ArcGIS_Server_DSC: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=200 -- Original Error: Long running operation terminated with status 'Failed': Code="VMExtensionProvisioningError" Message="VM has reported a failure when processing extension 'tst-dev-ags-dsc'. Error message: \"The DSC Extension failed to install: An error occurred while executing script or module 'webgis.ps1':  At C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:77 char:2\r\n+     Import-DscResource -Name ArcGIS_Service_Account\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_Service_Account': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:78 char:5\r\n+     Import-DscResource -Name ArcGIS_License\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_License': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:79 char:5\r\n+     Import-DscResource -Name MSFT_xFirewall\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'MSFT_xFirewall': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:80 char:5\r\n+     Import-DscResource -Name MSFT_xDisk\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'MSFT_xDisk': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:81 char:2\r\n+ Import-DscResource -Name ArcGIS_Portal\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_Portal': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:82 char:2\r\n+     Import-DscResource -Name ArcGIS_DataStore\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_DataStore': Resourcenot found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:83 char:2\r\n+     Import-DscResource -Name ArcGIS_GeoEvent\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_GeoEvent': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:84 char:2\r\n+     Import-DscResource -Name ArcGIS_Server\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_Server': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:85 char:2\r\n+     Import-DscResource -Name ArcGIS_Federation\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_Federation': Resource not found.\r\n\r\nAt C:\\Packages\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0\\DSCWork\\DSC.0\\webgis.ps1:86 char:2\r\n+     Import-DscResource -Name ArcGIS_Server_TLS\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nUnable to load resource 'ArcGIS_Server_TLS': Resource not found.\r\n\r\nNot all parse errors were reported.  Correct the reported errors and try again..\nMore information about the failure can be found in the logs located under 'C:\\WindowsAzure\\Logs\\Plugins\\Microsoft.Powershell.DSC\\2.73.0.0' on the VM.\nTo retry install, please remove the extension from the VM first. \"."

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.

Crash Output

Expected Behavior

Re-running the same terraform script produces idempotent results with DSC.

Actual Behavior

Steps to Reproduce

Additional Context

References

hashibot commented 6 years ago

This issue has been automatically migrated to terraform-providers/terraform-provider-azurerm#682 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to this issue and let us know.

ghost commented 4 years ago

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.