hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Databricks managed resource group fails to autogenerate when using modules #25090

Open TravBricks opened 8 months ago

TravBricks commented 8 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.5.7

AzureRM Provider Version

2.99.0

Affected Resource(s)/Data Source(s)

azurerm_databricks_workspace

Terraform Configuration Files

## main.tf
data "azurerm_resource_group" "workspace_rg" {
  name = "your_existing_rg"
}

module "workspace_1" {
  source = "./modules/databricks_workspace"
  workspace_name = "terraform_ws_1_adb"
  resource_group_name = data.azurerm_resource_group.workspace_rg.name
  resource_group_location = data.azurerm_resource_group.workspace_rg.location
}

module "workspace_2" {
  source = "./modules/databricks_workspace"
  workspace_name = "terraform_ws_2_adb"
  resource_group_name = data.azurerm_resource_group.workspace_rg.name
  resource_group_location = data.azurerm_resource_group.workspace_rg.location
}

## Module relevant
resource "azurerm_databricks_workspace" "this" {
  name                        = var.workspace_name
  resource_group_name         = var.resource_group_name
  location                    = var.resource_group_location
  sku                         = var.workspace_sku
}

Debug Output/Panic Output

Shows success, but 2nd workspace failed... subsequent terraform applies fail with this message:
Error: Invalid template interpolation value
│ 
│   on modules/databricks_workspace/output.tf line 10, in output "workspace_url":
│   10:   value       = "https://${azurerm_databricks_workspace.this.workspace_url}/"
│     ├────────────────
│     │ azurerm_databricks_workspace.this.workspace_url is null
│ 
│ The expression result is null. Cannot include a null value in a string template.

The workspaces in Azure Portal show the same MRG name for both workspaces.

Expected Behaviour

When the optional managed_resource_group_name is not included a unique MRG name should be generated and used by the workspace.

Actual Behaviour

There is a managed_resource_group_name reused for both workspaces resulting in a failed deployment for the second workspace.

Steps to Reproduce

  1. Build a simple terraform project with azurerm
  2. Create a module for creating a workspace
  3. Use the module twice creating uniquely named workspaces within the same parent resource group
  4. Init = success
  5. Plan = success
  6. Apply = reported success
  7. Azure portal shows otherwise image

Important Factoids

No response

References

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/databricks_workspace#managed_resource_group_name

rcskosir commented 8 months ago

Thanks for opening this issue. You've listed that this is an issue in the 2.x version of the provider which is no longer actively maintained. If you are able to upgrade and this is still an issue with the 3.x version of the provider please do let us know and we can reopen this issue.

TravBricks commented 8 months ago

My bad, same thing happened with v3.93.0

Error:

Error: creating/updating Workspace (Subscription: "[redact]"
│ Resource Group Name: "terraform_travislongwell-rg"
│ Workspace Name: "[redact]"): polling after CreateOrUpdate: polling failed: the Azure API returned the following error:
│ 
│ Status: "ApplianceProvisioningFailed"
│ Code: ""
│ Message: "The managed resource group '/subscriptions/[redact]/resourceGroups/databricks-rg-terraform-rg' already exists. Please specify a new non-existent managed resource group"
│ Activity Id: ""
│ 
│ ---
│ 
│ API Response:
│ 
│ ----[start]----
│ {
│   "status": "Failed",
│   "error": {
│     "code": "ApplianceProvisioningFailed",
│     "message": "The managed resource group '/subscriptions/[redact]/resourceGroups/databricks-rg-terraform-rg' already exists. Please specify a new non-existent managed resource group"
│   }
│ }
│ -----[end]-----
│ 
│ 
│   with module.workspace_2.azurerm_databricks_workspace.this,
│   on modules/databricks_workspace/workspace.tf line 1, in resource "azurerm_databricks_workspace" "this":
│    1: resource "azurerm_databricks_workspace" "this" {
│ 

TF version and azurerm provider version:

Terraform v1.5.7
on darwin_arm64
+ provider registry.terraform.io/hashicorp/azurerm v3.93.0
TravBricks commented 8 months ago

I updated to v3.9.3 and confirmed that it provides more feedback about the error, but still behaves incorrectly.

On Thu, Feb 29, 2024 at 12:33 PM Renae Kosir @.***> wrote:

Thanks for opening this issue. You've listed that this is an issue in the 2.x version of the provider which is no longer actively maintained. If you are able to upgrade and this is still an issue with the 3.x version of the provider please do let us know and we can reopen this issue.

— Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-provider-azurerm/issues/25090#issuecomment-1971627707, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZD3YSGOZGD3QIQGORAJP6DYV5S6LAVCNFSM6AAAAABD66FYR6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZRGYZDONZQG4 . You are receiving this because you authored the thread.Message ID: @.***>

rcskosir commented 8 months ago

@TravBricks Thank you for the additional information, reopening!