Skip to content

Commit

Permalink
Add new 'api integration' and 'external function' resources (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
asaintsever committed Mar 24, 2021
1 parent 9291b48 commit f250b80
Show file tree
Hide file tree
Showing 21 changed files with 1,777 additions and 2 deletions.
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

0 comments on commit f250b80

Please sign in to comment.