hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.87k stars 456 forks source link

Can't able to create catalog workspace binding via CDKTF #3174

Closed KarthicPortal closed 1 year ago

KarthicPortal commented 1 year ago

Expected Behavior

Hi,

We're trying to create catalog workspace binding via CDKTF. But unable to do so. Getting following error:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # databricks_catalog_workspace_binding.catalog-mobilab-dlz-dev-catalog-dbw-binding will be created
  + resource "databricks_catalog_workspace_binding" "catalog-mobilab-dlz-dev-catalog-dbw-binding" {
      + catalog_name = "mobilab-dlz-dev-catalog"
      + id           = (known after apply)
      + workspace_id = "/subscriptions/3342***/resourceGroups/rg-mblb-dev-dmlzz-dpms-neu/providers/Microsoft.Databricks/workspaces/dbw-mblb-dev-dmlz-dpms-neu"    
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

databricks_catalog_workspace_binding.catalog-mobilab-dlz-dev-catalog-dbw-binding: Creating...
╷
│ Error: cannot create catalog workspace binding: strconv.ParseInt: parsing "/subscriptions/3342***/resourceGroups/rg-mblb-dev-dmlzz-dpms-neu/providers/Microsoft.Databricks/workspaces/dbw-mblb-dev-dmlz-dpms-neu": invalid syntax
│
│   with databricks_catalog_workspace_binding.catalog-mobilab-dlz-dev-catalog-dbw-binding,
│   on cdk.tf.json line 178, in resource.databricks_catalog_workspace_binding.catalog-mobilab-dlz-dev-catalog-dbw-binding:
│  178:       }
│
╵

This works fine when I do it via Azure Databricks UI.

Actual Behavior

It should be able to create the binding between catalog and databricks workspace successfully

Steps to Reproduce

  1. Create catalog and databricks workspace binding using CDKTF

Versions

 "dependencies": {
    "@cdktf/provider-azuread": "^10.0.0",
    "@cdktf/provider-azurerm": "^10.0.2",
    "@cdktf/provider-databricks": "^10.0.6",
    "@cdktf/provider-docker": "^9.0.0",
    "@cdktf/provider-http": "^7.0.0",
    "@cdktf/provider-random": "^9.0.0",
    "@cdktf/provider-time": "^8.0.0",
    "cdktf": "^0.18.0",
    "constructs": "^10.2.18",
    "ip-num": "^1.5.1",
    "js-yaml": "^4.1.0"
  },

Providers

───────────────────────┬──────────────────┬─────────┬────────────┬────────────────────────────┬─────────────────┐ │ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ azuread │ 2.41.0 │ ^0.18.0 │ │ @cdktf/provider-azuread │ 10.0.0 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ azurerm │ 3.72.0 │ ^0.18.0 │ │ @cdktf/provider-azurerm │ 10.0.2 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ databricks/databricks │ 1.27.0 │ ^0.18.0 │ │ @cdktf/provider-databricks │ 10.0.6 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ kreuzwerker/docker │ 3.0.2 │ ^0.18.0 │ │ @cdktf/provider-docker │ 9.0.0 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ http │ 3.4.0 │ ^0.18.0 │ │ @cdktf/provider-http │ 7.0.0 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ random │ 3.5.1 │ ^0.18.0 │ │ @cdktf/provider-random │ 9.0.0 │ ├───────────────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤ │ time │ 0.9.1 │ ^0.18.0 │ │ @cdktf/provider-time │ 8.0.0 │ └───────────────────────┴──────────────────┴─────────┴────────────┴────────────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

Community Note

ansgarm commented 1 year ago

Hi @KarthicPortal 👋

Could you share the code that you are using to create the databricks_catalog_workspace_binding resource? From the error message it seems that it is expecting an integer for the workspace_id 🤔

KarthicPortal commented 1 year ago

Hi.. Thanks for the response.

Here is our code:

code flow: main.ts --> unity-catalog.ts

main.ts
-------
import { UnityCatalog } from "../../adp/organisms/unity-catalog"
export class ADPStack extends TerraformStack {

  static readonly COMMON_CONFIG_FILE = "common-config.yaml";
  static readonly UTF8_ENCODING: "utf8";

  constructor(scope: Construct, name: string) {
    super(scope, name);
    new UnityCatalog(this, {
      unityDatabricksWorkspace: {
        name: "dbw-mblb-dev-dmlzz-dpms-neu",
        resourceGroupName: "rg-mblb-dev-dmlzz-dpms-neu"
      },
      catalogDbwBinding: ["mobilab-dlz-dev-catalog"] // Catalogs from other Databricks, not from DMLZ Databricks;
    }, naming)
  }
}

unity-catalog.ts
----------------
import { DataAzurermDatabricksWorkspace } from "@cdktf/provider-azurerm/lib/data-azurerm-databricks-workspace";
import { CatalogWorkspaceBinding } from "@cdktf/provider-databricks/lib/catalog-workspace-binding";

export interface UnityCatalogConfig extends AdpCommonConfig {
    readonly component: string,
    readonly unityStorageAccount: {
        readonly name: string,
        readonly resourceGroupName: string,
    },
    readonly unityDatabricksWorkspace: {
        readonly name: string,
        readonly resourceGroupName: string,
    },
    readonly catalogDbwBinding?: string[]

}
export class UnityCatalog {

    constructor(scope: Construct, inputConfig: UnityCatalogConfig, naming: DefaultNaming) {
        const dbw = new DataAzurermDatabricksWorkspace(scope, `data-dbw-${config.workload}-${config.component}`, {
            name: config.unityDatabricksWorkspace.name,
            resourceGroupName: config.unityDatabricksWorkspace.resourceGroupName
        })

        let dbwProvider = new DatabricksProvider(scope, `databricks-provider2-${config.workload}-${config.component}`, {
            host: dbw.workspaceUrl,
            azureWorkspaceResourceId: dbw.id,
            alias: "unityCatalog"
        })

        config.catalogDbwBinding?.forEach(bind => {
            new CatalogWorkspaceBinding(scope, `catalog-${bind}-dbw-binding`,{
                catalogName: bind,
                workspaceId: dbw.id
            })
        })
    }, naming)
}

workspaceId supposed to be string right?

ansgarm commented 1 year ago

Hi @KarthicPortal 👋

Thank you for supplying the code. Much appreciated!

workspaceId supposed to be string right?

From the error message it appears to be expecting an integer, but got "/subscriptions/3342***/resourceGroups/rg-mblb-dev-dmlzz-dpms-neu/providers/Microsoft.Databricks/workspaces/dbw-mblb-dev-dmlz-dpms-neu". You might have success trying dbw.workspaceId instead of dbw.id.

That said, this is an issue with the Databricks provider, so your best next bet would be to file an issue on the Databricks provider repository: https://github.com/databricks/terraform-provider-databricks/issues

As this error is not specific to CDKTF, I'm going to close this issue. But don't hesitate to reach out, if you run into any other problems with CDKTF!

github-actions[bot] commented 11 months 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've 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.