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

Add new 'api integration' and 'external function' resources #491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
87b9622
Add support for api integration and external function
Mar 9, 2021
aaaaf55
Merge remote-tracking branch 'upstream/main' into asaintsever/feat/ex…
Mar 9, 2021
51c3c4d
Upd
Mar 9, 2021
c66e932
Add External Function
Mar 9, 2021
b0f9349
Generate docs
Mar 9, 2021
1e82617
Linting
Mar 9, 2021
8ab525a
Add acceptance tests
Mar 10, 2021
06a6f6a
Add acceptance tests
Mar 10, 2021
486429a
Add acceptance tests
Mar 10, 2021
717d573
Add acceptance tests
Mar 10, 2021
4021881
Upd examples & docs
Mar 10, 2021
a68a71c
Improve external function read & unit test
Mar 11, 2021
cf08e13
Improve external function read & unit test
Mar 11, 2021
e557bcd
Fixes
Mar 11, 2021
6afc128
Fix doc example on api integration
Mar 11, 2021
b0a3411
Merge branch 'main' into asaintsever/feat/external_functions
asaintsever Mar 13, 2021
97cec08
Merge branch 'main' into asaintsever/feat/external_functions
asaintsever Mar 16, 2021
fa34c7e
Consistent use of id
Mar 18, 2021
85d0420
Merge branch 'asaintsever/feat/external_functions' of github.com:asai…
Mar 18, 2021
6de7d2b
Merge branch 'main' into asaintsever/feat/external_functions
asaintsever Mar 18, 2021
46803dc
Remove 'comment' from api integration as not persisted in Snowflake
Mar 18, 2021
1daa3e3
Remove useless comments
Mar 18, 2021
7e124a9
Remove 'comment' from api integration as not persisted in Snowflake
Mar 18, 2021
175fec8
Add SetRaw method, 'API_PROVIDER' value now unquoted
Mar 21, 2021
c577c1b
Lint
Mar 21, 2021
b96b73d
Merge branch 'main' into asaintsever/feat/external_functions
asaintsever Mar 21, 2021
9d05487
Fix
Mar 21, 2021
e9b3c10
Fix convert issue on max_batch_rows
Mar 22, 2021
ba8097d
Complete handling of headers and context_headers
Mar 24, 2021
ff46096
Merge branch 'main' into asaintsever/feat/external_functions
alldoami Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/resources/api_integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_api_integration Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

# snowflake_api_integration (Resource)



## Example Usage

```terraform
resource "snowflake_api_integration" "api_integration" {
name = "aws_integration"
api_provider = "aws_api_gateway"
api_aws_role_arn = "arn:aws:iam::000000000001:/role/test"
api_allowed_prefixes = ["https://123456.execute-api.us-west-2.amazonaws.com/prod/"]
enabled = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **api_allowed_prefixes** (List of String) Explicitly limits external functions that use the integration to reference one or more HTTPS proxy service endpoints and resources within those proxies.
- **api_provider** (String) Specifies the HTTPS proxy service type.
- **name** (String) Specifies the name of the API integration. This name follows the rules for Object Identifiers. The name should be unique among api integrations in your account.

### Optional

- **api_aws_role_arn** (String) ARN of a cloud platform role.
- **api_blocked_prefixes** (List of String) Lists the endpoints and resources in the HTTPS proxy service that are not allowed to be called from Snowflake.
- **azure_ad_application_id** (String) The 'Application (client) id' of the Azure AD app for your remote service.
- **azure_tenant_id** (String) Specifies the ID for your Office 365 tenant that all Azure API Management instances belong to.
- **enabled** (Boolean) Specifies whether this API integration is enabled or disabled. If the API integration is disabled, any external function that relies on it will not work.
- **id** (String) The ID of this resource.

### Read-Only

- **api_aws_external_id** (String) The external ID that Snowflake will use when assuming the AWS role.
- **api_aws_iam_user_arn** (String) The Snowflake user that will attempt to assume the AWS role.
- **azure_consent_url** (String)
- **azure_multi_tenant_app_name** (String)
- **created_on** (String) Date and time when the API integration was created.

## Import

Import is supported using the following syntax:

```shell
terraform import snowflake_api_integration.example name
```
88 changes: 88 additions & 0 deletions docs/resources/external_function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_external_function Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

# snowflake_external_function (Resource)



## Example Usage

```terraform
resource "snowflake_external_function" "test_ext_func" {
name = "my_function"
database = "my_test_db"
schema = "my_test_schema"
arg {
name = "arg1"
type = "varchar"
}
arg {
name = "arg2"
type = "varchar"
}
return_type = "varchar"
return_behavior = "IMMUTABLE"
api_integration = "api_integration_name"
url_of_proxy_and_resource = "https://123456.execute-api.us-west-2.amazonaws.com/prod/test_func"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- **api_integration** (String) The name of the API integration object that should be used to authenticate the call to the proxy service.
- **database** (String) The database in which to create the external function.
- **name** (String) Specifies the identifier for the external function. The identifier can contain the schema name and database name, as well as the function name. The function's signature (name and argument data types) must be unique within the schema.
- **return_behavior** (String) Specifies the behavior of the function when returning results
- **return_type** (String) Specifies the data type returned by the external function.
- **schema** (String) The schema in which to create the external function.
- **url_of_proxy_and_resource** (String) This is the invocation URL of the proxy service and resource through which Snowflake calls the remote service.

### Optional

- **arg** (Block List) Specifies the arguments/inputs for the external function. These should correspond to the arguments that the remote service expects. (see [below for nested schema](#nestedblock--arg))
- **comment** (String) A description of the external function.
- **compression** (String) If specified, the JSON payload is compressed when sent from Snowflake to the proxy service, and when sent back from the proxy service to Snowflake.
- **context_headers** (List of String) Binds Snowflake context function results to HTTP headers.
- **header** (Block List) Allows users to specify key-value metadata that is sent with every request as HTTP headers. (see [below for nested schema](#nestedblock--header))
- **id** (String) The ID of this resource.
- **max_batch_rows** (Number) This specifies the maximum number of rows in each batch sent to the proxy service.
- **null_input_behavior** (String) Specifies the behavior of the external function when called with null inputs.
- **return_null_allowed** (Boolean) Indicates whether the function can return NULL values or must return only NON-NULL values.

### Read-Only

- **created_on** (String) Date and time when the external function was created.

<a id="nestedblock--arg"></a>
### Nested Schema for `arg`

Required:

- **name** (String) Argument name
- **type** (String) Argument type, e.g. VARCHAR


<a id="nestedblock--header"></a>
### Nested Schema for `header`

Required:

- **name** (String) Header name
- **value** (String) Header value

## Import

Import is supported using the following syntax:

```shell
# format is database name | schema name | external function name | <list of function arg types, separated with '-'>
terraform import snowflake_external_function.example 'dbName|schemaName|externalFunctionName|varchar-varchar-varchar'
```
1 change: 1 addition & 0 deletions examples/resources/snowflake_api_integration/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import snowflake_api_integration.example name
7 changes: 7 additions & 0 deletions examples/resources/snowflake_api_integration/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "snowflake_api_integration" "api_integration" {
name = "aws_integration"
api_provider = "aws_api_gateway"
api_aws_role_arn = "arn:aws:iam::000000000001:/role/test"
api_allowed_prefixes = ["https://123456.execute-api.us-west-2.amazonaws.com/prod/"]
enabled = true
}
2 changes: 2 additions & 0 deletions examples/resources/snowflake_external_function/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format is database name | schema name | external function name | <list of function arg types, separated with '-'>
terraform import snowflake_external_function.example 'dbName|schemaName|externalFunctionName|varchar-varchar-varchar'
17 changes: 17 additions & 0 deletions examples/resources/snowflake_external_function/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "snowflake_external_function" "test_ext_func" {
name = "my_function"
database = "my_test_db"
schema = "my_test_schema"
arg {
name = "arg1"
type = "varchar"
}
arg {
name = "arg2"
type = "varchar"
}
return_type = "varchar"
return_behavior = "IMMUTABLE"
api_integration = "api_integration_name"
url_of_proxy_and_resource = "https://123456.execute-api.us-west-2.amazonaws.com/prod/test_func"
}
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,6 @@ github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/snowflakedb/gosnowflake v1.4.0 h1:tt3nMrv+qQ4DZtTjasornB6nD8siIU5VpTI+qEyK4sc=
github.com/snowflakedb/gosnowflake v1.4.0/go.mod h1:6nfka9aTXkUNha1p1cjeeyjDvcyh7jfjp0l8kGpDBok=
github.com/snowflakedb/gosnowflake v1.4.1 h1:5Yu1Pi0wh6gyebzxtwmngd63VtUIps1HvrmLwxtpAEI=
github.com/snowflakedb/gosnowflake v1.4.1/go.mod h1:6nfka9aTXkUNha1p1cjeeyjDvcyh7jfjp0l8kGpDBok=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand All @@ -671,6 +669,7 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down
2 changes: 2 additions & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func GetGrantResources() resources.TerraformGrantResources {

func getResources() map[string]*schema.Resource {
others := map[string]*schema.Resource{
"snowflake_api_integration": resources.APIIntegration(),
"snowflake_database": resources.Database(),
"snowflake_external_function": resources.ExternalFunction(),
"snowflake_managed_account": resources.ManagedAccount(),
"snowflake_masking_policy": resources.MaskingPolicy(),
"snowflake_materialized_view": resources.MaterializedView(),
Expand Down
Loading