Skip to content

Commit 60b8a6f

Browse files
tanmay-dbmgyucht
andauthored
[Fix] Set ID for online table resource if creation succeeds but it isn't available yet (#4072)
## Changes <!-- Summary of your changes that are easy to understand --> We should set the id right after creation and before waiting for online table to be available. This is because in case when online table isn't available, we still should have that resource in the state. Also the timeout has been increased to 2x (I am going to following up with online tables team for suitable timeout but since we have to do a release, going ahead with small time increase should be good) Note: We should add setting id right after creation for similar resources to CONTRIBUTING guide (which I will do in a separate PR) ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> Added unit test to check that pathway, id is set (which wasn't the case before) - [ ] `make test` run locally - [ ] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [ ] relevant acceptance tests are passing - [ ] using Go SDK --------- Co-authored-by: Miles Yucht <[email protected]>
1 parent 7d0491f commit 60b8a6f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

catalog/resource_online_table.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1515
)
1616

17-
const onlineTableDefaultProvisionTimeout = 45 * time.Minute
17+
const onlineTableDefaultProvisionTimeout = 90 * time.Minute
1818

1919
func waitForOnlineTableCreation(w *databricks.WorkspaceClient, ctx context.Context, onlineTableName string) error {
2020
return retry.RetryContext(ctx, onlineTableDefaultProvisionTimeout, func() *retry.RetryError {
@@ -80,13 +80,14 @@ func ResourceOnlineTable() common.Resource {
8080
if err != nil {
8181
return err
8282
}
83+
// Note: We should set the id right after creation and before waiting for online table to be available.
84+
// If the resource creation timeout is exceeded while waiting for the online table to be ready, this ensures the online table is persisted in the state.
85+
d.SetId(res.Name)
8386
// this should be specified in the API Spec - filed a ticket to add it
8487
err = waitForOnlineTableCreation(w, ctx, res.Name)
8588
if err != nil {
86-
8789
return err
8890
}
89-
d.SetId(res.Name)
9091
return nil
9192
},
9293
Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {

catalog/resource_online_table_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/databricks/databricks-sdk-go/service/catalog"
1010
"github.com/databricks/terraform-provider-databricks/qa"
1111

12+
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/mock"
1314
)
1415

@@ -108,7 +109,7 @@ func TestOnlineTableCreate_ErrorInWait(t *testing.T) {
108109
},
109110
Status: &catalog.OnlineTableStatus{DetailedState: catalog.OnlineTableStateOfflineFailed},
110111
}
111-
qa.ResourceFixture{
112+
d, err := qa.ResourceFixture{
112113
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
113114
e := w.GetMockOnlineTablesAPI().EXPECT()
114115
e.Create(mock.Anything, catalog.CreateOnlineTableRequest{
@@ -124,7 +125,9 @@ func TestOnlineTableCreate_ErrorInWait(t *testing.T) {
124125
Resource: ResourceOnlineTable(),
125126
HCL: onlineTableHcl,
126127
Create: true,
127-
}.ExpectError(t, "online table status returned OFFLINE_FAILED for online table: main.default.online_table")
128+
}.Apply(t)
129+
qa.AssertErrorStartsWith(t, err, "online table status returned OFFLINE_FAILED for online table: main.default.online_table")
130+
assert.Equal(t, "main.default.online_table", d.Id())
128131
}
129132

130133
func TestOnlineTableRead(t *testing.T) {

0 commit comments

Comments
 (0)