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

[ISSUE] The account_id attribute is sometimes not populated when updating databricks_mws_workspaces #649

Closed
tonybaron opened this issue May 13, 2021 · 6 comments · Fixed by #734
Labels
aws Occurring on AWS cloud
Milestone

Comments

@tonybaron
Copy link

tonybaron commented May 13, 2021

Hi there,

It appears that the account_id attribute is sometimes not being populated when PATCHing databricks_mws_workspaces. The API returns MALFORMED_REQUEST: Invalid AccountId: because the account_id is an empty string on the patch request.

In my case this was related to adding customer managed key configurations.

Performing the below request manually with the REST API, but populating the account_id correctly resulted in the API returning a 200.

Terraform Version

0.13.6

Provider Version

0.3.4

Affected Resource(s)

  • databricks_mws_workspaces

Debug Output

databricks_mws_workspaces.this: Modifying... [id=<redacted>/<redacted>]
...
PATCH /accounts/<redacted>/workspaces/<redacted> {
  "account_id": "",
  "aws_region": "<redacted>",
  "credentials_id": "<redacted>",
  "deployment_name": "",
  "managed_services_customer_managed_key_id": "<redacted>",
  "network_id": "<redacted>",
  "storage_configuration_id": "<redacted>",
  "storage_customer_managed_key_id": "<redacted>",
  "workspace_name": ""
}: timestamp=2021-05-13T15:03:36.845-0400
...
2021-05-13T15:03:37.568-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: 400 Bad Request: timestamp=2021-05-13T15:03:37.568-0400
2021-05-13T15:03:37.568-0400 [WARN]  plugin.terraform-provider-databricks_v0.3.4: /api/2.0/accounts/<redacted>/workspaces/<redacted>:400 - MALFORMED_REQUEST: Invalid AccountId:: timestamp=2021-05-13T15:03:37.568-0400
2021-05-13T15:03:37.568-0400 [WARN]  plugin.terraform-provider-databricks_v0.3.4: /api/2.0/accounts/<redacted>/workspaces/<redacted>:400 - MALFORMED_REQUEST: Invalid AccountId:: timestamp=2021-05-13T15:03:37.568-0400
...
Error: MALFORMED_REQUEST: Invalid AccountId:

Expected Behavior

The workspace should be updated with new attributes.

Actual Behavior

The API returns a 400 and fails to update AND the terraform state thinks that things are successfully applied. Subsequent requests do not attempt to modify this resource.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Modify an attribute of databricks_mws_workspaces. In my case it was customer managed keys related, but I'm not sure if it is specific to that.
  2. terraform apply
@nfx
Copy link
Contributor

nfx commented May 13, 2021

@tonybaron please provide more context, including cmk & workspace resource configs. and cmk request traffic. it might be the case that some resources didn't return proper content and this happened.

@tonybaron
Copy link
Author

tonybaron commented May 17, 2021

Hi @nfx. Sorry for the delay.

CMK resource config:

resource "databricks_mws_customer_managed_keys" "this" {
  provider   = databricks.mws
  account_id = var.databricks_account_id
  aws_key_info {
    key_arn   = aws_kms_key.control_plane_key.arn
    key_alias = aws_kms_alias.control_plane_key_alias.name
  }
  use_cases = ["MANAGED_SERVICES", "STORAGE"]
}

Workspace resource config:

resource "databricks_mws_workspaces" "this" {
  provider        = databricks.mws
  account_id      = var.databricks_account_id
  aws_region      = var.region
  workspace_name  = var.workspace_name
  deployment_name = var.workspace_name

  credentials_id           = databricks_mws_credentials.this.credentials_id
  storage_configuration_id = databricks_mws_storage_configurations.this.storage_configuration_id
  network_id               = databricks_mws_networks.this.network_id
  storage_customer_managed_key_id          = databricks_mws_customer_managed_keys.this.customer_managed_key_id
}

And some more logs:

2021-05-17T12:29:16.858-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: POST /accounts/<redacted>/customer-managed-keys {
  "account_id": "<redacted>",
  "aws_key_info": {
    "key_alias": "<redacted>",
    "key_arn": "<redacted>"
  },
  "use_cases": [
    "MANAGED_SERVICES",
    "STORAGE"
  ]
}: timestamp=2021-05-17T12:29:16.858-0400
2021-05-17T12:29:19.252-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: 201 Created {
  "account_id": "<redacted>",
  "aws_key_info": {
    "key_alias": "<redacted>",
    "key_arn": "<redacted>",
    "key_region": "us-east-1",
    "reuse_key_for_cluster_volumes": true
  },
  "creation_time": 1621268959313,
  "customer_managed_key_id": "<redacted>",
  "updated_time": 1621268959313,
  "use_cases": [
    "MANAGED_SERVICES",
    "STORAGE"
  ]
} <- POST /accounts/<redacted>/customer-managed-keys: timestamp=2021-05-17T12:29:19.252-0400
2021-05-17T12:29:19.252-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: GET /accounts/<redacted>/customer-managed-keys/<redacted>: timestamp=2021-05-17T12:29:19.252-0400
2021-05-17T12:29:19.451-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: 200 OK {
  "account_id": "<redacted>",
  "aws_key_info": {
    "key_alias": "<redacted>",
    "key_arn": "<redacted>",
    "key_region": "us-east-1",
    "reuse_key_for_cluster_volumes": true
  },
  "creation_time": 1621268959313,
  "customer_managed_key_id": "<redacted>",
  "updated_time": 1621268959313,
  "use_cases": [
    "MANAGED_SERVICES",
    "STORAGE"
  ]
} <- GET /accounts/<redacted>/customer-managed-keys/<redacted>: timestamp=2021-05-17T12:29:19.451-0400
...
databricks_mws_customer_managed_keys.this: Creation complete after 2s [id=<redacted>/<redacted>]
...
...
2021-05-17T12:43:54.852-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: PATCH /accounts/<redacted>/workspaces/<redacted> {
  "account_id": "",
  "aws_region": "us-east-1",
  "credentials_id": "<redacted>",
  "deployment_name": "",
  "network_id": "<redacted>",
  "storage_configuration_id": "<redacted>",
  "storage_customer_managed_key_id": "<redacted>",
  "workspace_name": ""
}: timestamp=2021-05-17T12:43:54.852-0400
...
2021-05-17T12:43:55.544-0400 [DEBUG] plugin.terraform-provider-databricks_v0.3.4: 400 Bad Request: timestamp=2021-05-17T12:43:55.543-0400
2021-05-17T12:43:55.544-0400 [WARN]  plugin.terraform-provider-databricks_v0.3.4: /api/2.0/accounts/<redacted>/workspaces/<redacted>:400 - MALFORMED_REQUEST: Invalid AccountId:: timestamp=2021-05-17T12:43:55.544-0400
2021-05-17T12:43:55.544-0400 [WARN]  plugin.terraform-provider-databricks_v0.3.4: /api/2.0/accounts/<redacted>/workspaces/<redacted>:400 - MALFORMED_REQUEST: Invalid AccountId:: timestamp=2021-05-17T12:43:55.544-0400
2021/05/17 12:43:55 [DEBUG] databricks_mws_workspaces.this: apply errored, but we're indicating that via the Error pointer rather than returning it: MALFORMED_REQUEST: Invalid AccountId:
...
ERRO[0045] Hit multiple errors:
Hit multiple errors:
exit status 1

Edited comment to reflect that I'm trying to apply the storage CMK, not the managed services CMK as I don't believe the latter can be added to a workspace.

@tonybaron
Copy link
Author

@nfx As an aside, related to my previous comment, I see that the accounts REST API is returning a 200 when I try to add a managed services CMK. According to the documentation, that is only available when a workspace is created. This isn't reflected in the Terraform documentation at all, and led to a lot of confusion until I dug into the documentation further.

Could you route that issue to the correct party? I would expect that to return some 4xx with a clear error message.

@nfx
Copy link
Contributor

nfx commented Jun 8, 2021

@tonybaron Can you send a PR with a suggested change to docs/resources/customer_managed_key.md?..

@mbarrien
Copy link

My org is running into this issue updating a database_mws_workspaces object. I suspect a bug at https://github.com/databrickslabs/terraform-provider-databricks/blob/master/mws/resource_workspace.go#L110 since I don't see AccountID being populated in the workspace object being passed to the client.Patch method.

@nfx nfx added the aws Occurring on AWS cloud label Jul 19, 2021
@nfx
Copy link
Contributor

nfx commented Jul 20, 2021

@mbarrien Good catch! We'll look into this soon. You can accelerate this by submitting a PR

nfx added a commit that referenced this issue Jul 21, 2021
* Each time there's a workspace change diff, it's checked only for the allowed fields to be updated
* `PATCH /accounts/.../workspaces/..` only contains allowed fields
@nfx nfx added this to the v0.3.7 milestone Jul 21, 2021
nfx added a commit that referenced this issue Jul 27, 2021
* Each time there's a workspace change diff, it's checked only for the allowed fields to be updated
* `PATCH /accounts/.../workspaces/..` only contains allowed fields
nfx added a commit that referenced this issue Jul 27, 2021
* Each time there's a workspace change diff, it's checked only for the allowed fields to be updated
* `PATCH /accounts/.../workspaces/..` only contains allowed fields
@nfx nfx closed this as completed in #734 Jul 27, 2021
nfx added a commit that referenced this issue Jul 27, 2021
* Each time there's a workspace change diff, it's checked only for the allowed fields to be updated
* `PATCH /accounts/.../workspaces/..` only contains allowed fields
@nfx nfx mentioned this issue Jul 30, 2021
michael-berk pushed a commit to michael-berk/terraform-provider-databricks that referenced this issue Feb 15, 2023
* Each time there's a workspace change diff, it's checked only for the allowed fields to be updated
* `PATCH /accounts/.../workspaces/..` only contains allowed fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Occurring on AWS cloud
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants