databricks / terraform-provider-databricks

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

[ISSUE] Issue with `databricks_mws_ncc_private_endpoint_rule` resource #4138

Open emailisabu opened 3 weeks ago

emailisabu commented 3 weeks ago

Hello,

I have a problem with 'databricks_mws_ncc_private_endpoint_rule' module due to timeout, is there any way to pass timeout condition along with the module ?

Configuration

resource "databricks_mws_ncc_private_endpoint_rule" "pe_rule" {
  network_connectivity_config_id = var.ncc_id
  resource_id                    = var.resource_id
  group_id                       = var.subresource_type
  lifecycle {
    ignore_changes = [
      connection_state
    ]
  }
}

Expected Behavior

module.datalakehouse.module.storage_account_adls_services["storage7"].module.ncc_rule_blob[0].databricks_mws_ncc_private_endpoint_rule.pe_rule: Creation complete after 56s [id=bece2dd2-4d68-4a7e-g583-4908bd57cdc0/f9c40a6d-gf5r-4e96-bfd1-b62eb9d7634t]

Actual Behavior

Error: cannot create mws ncc private endpoint rule: Post "https://accounts.azuredatabricks.net/api/2.0/accounts/xxxx/network-connectivity-configs/bedw2dd2-4d68-4a7e-a983-4908bd57cdf0/private-endpoint-rules": request timed out after 1m0s of inactivity │ │ with module.datalakehouse.module.storage_account_adls_services["storage5"].module.ncc_rule_blob[0].databricks_mws_ncc_private_endpoint_rule.pe_rule, │ on .terraform/modules/datalakehouse/databricks/databricks-ncc-rule/main.tf line 1, in resource "databricks_mws_ncc_private_endpoint_rule" "pe_rule": │ 1: resource "databricks_mws_ncc_private_endpoint_rule" "pe_rule" {

Steps to Reproduce

Terraform and provider versions

1.9.4

emailisabu commented 2 weeks ago

This defaultProvisionTimeout could solve.

https://github.com/databricks/terraform-provider-databricks/blob/main/mws/resource_mws_ncc_private_endpoint_rule.go

package mws

import (
    "context"
    "time"
    "log"

    "github.com/databricks/databricks-sdk-go/service/settings"
    "github.com/databricks/terraform-provider-databricks/common"

    "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const defaultProvisionTimeout = 5 * time.Minute

func ResourceMwsNccPrivateEndpointRule() common.Resource {
    s := common.StructToSchema(settings.NccAzurePrivateEndpointRule{}, func(m map[string]*schema.Schema) map[string]*schema.Schema {
        for _, p := range []string{"network_connectivity_config_id", "group_id", "resource_id"} {
            common.CustomizeSchemaPath(m, p).SetRequired().SetForceNew()
        }
        for _, p := range []string{"rule_id", "endpoint_name", "connection_state", "creation_time", "updated_time"} {
            common.CustomizeSchemaPath(m, p).SetComputed()
        }
        return m
    })
    p := common.NewPairSeparatedID("network_connectivity_config_id", "rule_id", "/")
    return common.Resource{
        Schema: s,
        Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
            var create settings.CreatePrivateEndpointRuleRequest
            common.DataToStructPointer(d, s, &create)
            create.NetworkConnectivityConfigId = d.Get("network_connectivity_config_id").(string)
            acc, err := c.AccountClient()
            if err != nil {
                return err
            }
            rule, err := acc.NetworkConnectivity.CreatePrivateEndpointRule(ctx, create)
            if err != nil {
                return err
            }
            common.StructToData(rule, s, d)
            p.Pack(d)
            return nil
        },
        Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
            nccId, ruleId, err := p.Unpack(d)
            if err != nil {
                return err
            }
            acc, err := c.AccountClient()
            if err != nil {
                return err
            }
            rule, err := acc.NetworkConnectivity.GetPrivateEndpointRuleByNetworkConnectivityConfigIdAndPrivateEndpointRuleId(ctx, nccId, ruleId)
            if err != nil {
                return err
            }
            return common.StructToData(rule, s, d)
        },
        Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
            nccId, ruleId, err := p.Unpack(d)
            if err != nil {
                return err
            }
            acc, err := c.AccountClient()
            if err != nil {
                return err
            }
            _, err = acc.NetworkConnectivity.DeletePrivateEndpointRuleByNetworkConnectivityConfigIdAndPrivateEndpointRuleId(ctx, nccId, ruleId)
            return err
        },
        Timeouts: &schema.ResourceTimeout{
            Create: schema.DefaultTimeout(DefaultProvisionTimeout),
            Read:   schema.DefaultTimeout(DefaultProvisionTimeout),
            Delete: schema.DefaultTimeout(DefaultProvisionTimeout),
        },
    }
}