-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,275 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package acceptance | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/databricks/terraform-provider-databricks/internal/acceptance" | ||
"github.com/databricks/terraform-provider-databricks/qa" | ||
) | ||
|
||
func TestUcAccCreateProviderDb2Open(t *testing.T) { | ||
qa.RequireCloudEnv(t, "ucws") | ||
acceptance.Test(t, []acceptance.Step{ | ||
{ | ||
Template: ` | ||
resource "databricks_provider" "this" { | ||
name = "terraform-test-provider" | ||
comment = "made by terraform" | ||
authentication_type = "TOKEN" | ||
recipient_profile_str = jsonencode({ | ||
"shareCredentialsVersion":1, | ||
"bearerToken":"dapiabcdefghijklmonpqrstuvwxyz", | ||
"endpoint":"https://sharing.delta.io/delta-sharing/" | ||
} | ||
) | ||
}`, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package catalog | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/databricks/terraform-provider-databricks/common" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
type ProvidersAPI struct { | ||
client *common.DatabricksClient | ||
context context.Context | ||
} | ||
|
||
func NewProvidersAPI(ctx context.Context, m interface{}) ProvidersAPI { | ||
return ProvidersAPI{m.(*common.DatabricksClient), ctx} | ||
} | ||
|
||
type ProviderInfo struct { | ||
Name string `json:"name" tf:"force_new"` | ||
Comment string `json:"comment,omitempty"` | ||
AuthenticationType string `json:"authentication_type"` | ||
RecipientProfileStr string `json:"recipient_profile_str" tf:"sensitive"` | ||
} | ||
|
||
type Providers struct { | ||
Providers []ProviderInfo `json:"providers"` | ||
} | ||
|
||
func (a ProvidersAPI) createProvider(ci *ProviderInfo) error { | ||
return a.client.Post(a.context, "/unity-catalog/providers", ci, ci) | ||
} | ||
|
||
func (a ProvidersAPI) getProvider(name string) (ci ProviderInfo, err error) { | ||
err = a.client.Get(a.context, "/unity-catalog/providers/"+name, nil, &ci) | ||
return | ||
} | ||
|
||
func (a ProvidersAPI) deleteProvider(name string) error { | ||
return a.client.Delete(a.context, "/unity-catalog/providers/"+name, nil) | ||
} | ||
|
||
func (a ProvidersAPI) updateProvider(ci *ProviderInfo) error { | ||
patch := struct { | ||
Comment string `json:"comment"` | ||
}{ | ||
Comment: ci.Comment, | ||
} | ||
return a.client.Patch(a.context, "/unity-catalog/providers/"+ci.Name, patch) | ||
} | ||
|
||
func ResourceProvider() *schema.Resource { | ||
providerSchema := common.StructToSchema(ProviderInfo{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { | ||
m["authentication_type"].ValidateFunc = validation.StringInSlice([]string{"TOKEN"}, false) | ||
return m | ||
}) | ||
|
||
providerSchemaForRead := map[string]*schema.Schema{ | ||
"name": providerSchema["name"], | ||
"comment": providerSchema["comment"], | ||
"authentication_type": providerSchema["authentication_type"], | ||
} | ||
return common.Resource{ | ||
Schema: providerSchema, | ||
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { | ||
var ri ProviderInfo | ||
common.DataToStructPointer(d, providerSchema, &ri) | ||
if err := NewProvidersAPI(ctx, c).createProvider(&ri); err != nil { | ||
return err | ||
} | ||
d.SetId(ri.Name) | ||
return nil | ||
}, | ||
Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { | ||
ri, err := NewProvidersAPI(ctx, c).getProvider(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
return common.StructToData(ri, providerSchemaForRead, d) | ||
}, | ||
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { | ||
var ri ProviderInfo | ||
common.DataToStructPointer(d, providerSchema, &ri) | ||
return NewProvidersAPI(ctx, c).updateProvider(&ri) | ||
}, | ||
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { | ||
return NewProvidersAPI(ctx, c).deleteProvider(d.Id()) | ||
}, | ||
}.ToResource() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package catalog | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/databricks/terraform-provider-databricks/qa" | ||
) | ||
|
||
func TestProviderCornerCases(t *testing.T) { | ||
qa.ResourceCornerCases(t, ResourceProvider()) | ||
} | ||
|
||
func TestCreateProvider(t *testing.T) { | ||
qa.ResourceFixture{ | ||
Fixtures: []qa.HTTPFixture{ | ||
{ | ||
Method: "POST", | ||
Resource: "/api/2.0/unity-catalog/providers", | ||
ExpectedRequest: ProviderInfo{ | ||
Name: "a", | ||
Comment: "b", | ||
AuthenticationType: "TOKEN", | ||
RecipientProfileStr: "c", | ||
}, | ||
Response: ProviderInfo{ | ||
Name: "a", | ||
}, | ||
}, | ||
{ | ||
Method: "GET", | ||
Resource: "/api/2.0/unity-catalog/providers/a", | ||
Response: ProviderInfo{ | ||
Name: "a", | ||
Comment: "b", | ||
AuthenticationType: "TOKEN", | ||
RecipientProfileStr: "c", | ||
}, | ||
}, | ||
}, | ||
Resource: ResourceProvider(), | ||
Create: true, | ||
HCL: ` | ||
name = "a" | ||
comment = "b" | ||
authentication_type = "TOKEN" | ||
recipient_profile_str = "c" | ||
`, | ||
}.ApplyNoError(t) | ||
} | ||
|
||
func TestCreateProvider_InvalidAuthType(t *testing.T) { | ||
qa.ResourceFixture{ | ||
Fixtures: []qa.HTTPFixture{}, | ||
Resource: ResourceProvider(), | ||
Create: true, | ||
HCL: ` | ||
name = "a" | ||
comment = "b" | ||
authentication_type = "temp" | ||
recipient_profile_str = "{\"shareCredentialsVersion\":1,\"bearerToken\":\"a\",\"endpoint\":\"b\",\"expirationTime\":\"c\"}" | ||
`, | ||
}.ExpectError(t, "invalid config supplied. "+ | ||
"[authentication_type] expected authentication_type "+ | ||
"to be one of [TOKEN], got temp") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.