databricks / terraform-provider-databricks

Databricks Terraform Provider
https://registry.terraform.io/providers/databricks/databricks/latest
Other
454 stars 392 forks source link

[ISSUE] Issue with conditionals and workspace creation #1518

Closed tony-farias closed 2 years ago

tony-farias commented 2 years ago

A user uses a count in databricks_mws_workspaces, so they can define a conditional in the output variable around token. The call to the token API is ok 2022-07-29T20:33:40.252Z [DEBUG] plugin.terraform-provider-databricks_v0.6.1: 200 OK {} <- GET /api/2.0/token/list: timestamp=2022-07-29T20:33:40.252Z

This line produces the issue: value = var.databricks_enable_workspace ? databricks_mws_workspaces.this[0].token[0].token_value : null

Seems like databricks_mws_workspaces.this[0] is empty, but with databricks_mws_workspaces.this.token.token_value the apply is successful. See error below.

The customer needs this to proceed. Many teams use conditionals so they can move code into prod across the team, without blocking each other. Customer comments:

""" it's a blocker to even dev, because I can't commit it into my mainline until I can shut it off per env. And since I can't do that, other peoples changes blow away my work """

Configuration

resource "databricks_mws_workspaces" "this" { provider = databricks.mws count = var.databricks_enable_workspace ? 1 : 0 account_id = var.databricks_account_id aws_region = local.region workspace_name = var.databricks_naming_prefix deployment_name = var.databricks_naming_prefix

credentials_id = databricks_mws_credentials.this[count.index].credentials_id storage_configuration_id = databricks_mws_storage_configurations.this[count.index].storage_configuration_id managed_services_customer_managed_key_id = databricks_mws_customer_managed_keys.mws_cmk[count.index].customer_managed_key_id storage_customer_managed_key_id = databricks_mws_customer_managed_keys.storage_cmk[count.index].customer_managed_key_id network_id = databricks_mws_networks.this[count.index].network_id

token {} }

provider "databricks" { alias = "created_workspace" host = var.databricks_enable_workspace ? databricks_mws_workspaces.this[0].workspace_url : null }

output "databricks_token" { value = var.databricks_enable_workspace ? databricks_mws_workspaces.this[0].token[0].token_value : null sensitive = true }

Expected Behavior

The apply should work

Actual Behavior

Error: Invalid index

 on databricks_workspace/outputs.tf line 9, in output "databricks_token": 9: value = var.databricks_enable_workspace ? databricks_mws_workspaces.this[0].token[0].token_value : null  |----------------  | databricks_mws_workspaces.this[0].token is empty list of object  The given key does not identify an element in this collection value. 

Steps to Reproduce

terraform apply on config above

Terraform and provider versions

tf v0.12.31 current provider

Debug Output

I can provide this, though the summary above should contain the necessary details.

Important Factoids

nkvuong commented 2 years ago

@tony-farias Any particular reason why they are still on tf v0.12, that is a pretty old version.

If they try with a newer tf version, do they still run into the issue?

nfx commented 2 years ago

@tony-farias can you reproduce this failure in Terraform 0.12.x and 1.1.x?

tony-farias commented 2 years ago

They experience the failure still in Terraform 0.13, the highest version they have enterprise access to. I will try TF 1.1 on my side.

On Thu, Aug 4, 2022 at 4:35 AM Serge Smertin @.***> wrote:

@tony-farias https://github.com/tony-farias can you reproduce this failure on Terraform 1.1?

— Reply to this email directly, view it on GitHub https://github.com/databricks/terraform-provider-databricks/issues/1518#issuecomment-1204942133, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVAH3M76OOYAWEIFJGZYYNLVXN6EXANCNFSM55PGY2FA . You are receiving this because you were mentioned.Message ID: @.*** com>

nfx commented 2 years ago

@tony-farias Following up - is this issue still relevant? could you attach the logs? otherwise i'll have to close this issue.

tony-farias commented 2 years ago

Yes, still relevant. I will scrub and attach logs now.