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

feat: Procedures #619

Merged
merged 13 commits into from
Aug 12, 2021
86 changes: 86 additions & 0 deletions docs/resources/procedure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "snowflake_procedure Resource - terraform-provider-snowflake"
subcategory: ""
description: |-

---

# snowflake_procedure (Resource)



## Example Usage

```terraform
resource "snowflake_schema" "db" {
name = "MYDB"
data_retention_days = 1
}

resource "snowflake_schema" "schema" {
database = snowflake_database.db.name
name = "MYSCHEMA"
data_retention_days = 1
}

resource "snowflake_procedure" "proc" {
name = "SAMPLEPROC"
database = snowflake_database.db.name
schema = snowflake_schema.schema.name
arguments {
name = "arg1"
type = "varchar"
}
arguments {
name = "arg2"
type = "DATE"
}
comment = "Procedure with 2 arguments"
return_type = "VARCHAR"
execute_as = "CALLER"
return_behavior = "IMMUTABLE"
null_input_behavior = "RETURNS NULL ON NULL INPUT"
statement = <<EOT
var X=1
return X
EOT
}
```

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

### Required

- **database** (String) The database in which to create the procedure. Don't use the | character.
- **name** (String) Specifies the identifier for the procedure; does not have to be unique for the schema in which the procedure is created. Don't use the | character.
- **return_type** (String) The return type of the procedure
- **schema** (String) The schema in which to create the procedure. Don't use the | character.
- **statement** (String) Specifies the javascript code used to create the procedure.

### Optional

- **arguments** (Block List) List of the arguments for the procedure (see [below for nested schema](#nestedblock--arguments))
- **comment** (String) Specifies a comment for the procedure.
- **execute_as** (String) Sets execute context - see caller's rights and owner's rights
- **id** (String) The ID of this resource.
- **null_input_behavior** (String) Specifies the behavior of the procedure when called with null inputs.
- **return_behavior** (String) Specifies the behavior of the function when returning results

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

Required:

- **name** (String) The argument name
- **type** (String) The argument type

## Import

Import is supported using the following syntax:

```shell
# format is database name | schema name | stored procedure name | <list of arg types, separated with '-'>
terraform import snowflake_procedure.example 'dbName|schemaName|procedureName|varchar-varchar-varchar'
```
2 changes: 2 additions & 0 deletions examples/resources/snowflake_procedure/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# format is database name | schema name | stored procedure name | <list of arg types, separated with '-'>
terraform import snowflake_procedure.example 'dbName|schemaName|procedureName|varchar-varchar-varchar'
33 changes: 33 additions & 0 deletions examples/resources/snowflake_procedure/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "snowflake_schema" "db" {
name = "MYDB"
data_retention_days = 1
}

resource "snowflake_schema" "schema" {
database = snowflake_database.db.name
name = "MYSCHEMA"
data_retention_days = 1
}

resource "snowflake_procedure" "proc" {
name = "SAMPLEPROC"
database = snowflake_database.db.name
schema = snowflake_schema.schema.name
arguments {
name = "arg1"
type = "varchar"
}
arguments {
name = "arg2"
type = "DATE"
}
comment = "Procedure with 2 arguments"
return_type = "VARCHAR"
execute_as = "CALLER"
return_behavior = "IMMUTABLE"
null_input_behavior = "RETURNS NULL ON NULL INPUT"
statement = <<EOT
var X=1
return X
EOT
}
1 change: 1 addition & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func getResources() map[string]*schema.Resource {
"snowflake_network_policy_attachment": resources.NetworkPolicyAttachment(),
"snowflake_network_policy": resources.NetworkPolicy(),
"snowflake_pipe": resources.Pipe(),
"snowflake_procedure": resources.Procedure(),
"snowflake_resource_monitor": resources.ResourceMonitor(),
"snowflake_role": resources.Role(),
"snowflake_role_grants": resources.RoleGrants(),
Expand Down
8 changes: 8 additions & 0 deletions pkg/resources/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ func externalFunction(t *testing.T, id string, params map[string]interface{}) *s
return d
}

func procedure(t *testing.T, id string, params map[string]interface{}) *schema.ResourceData {
r := require.New(t)
d := schema.TestResourceDataRaw(t, resources.Procedure().Schema, params)
r.NotNil(d)
d.SetId(id)
return d
}

func storageIntegration(t *testing.T, id string, params map[string]interface{}) *schema.ResourceData {
r := require.New(t)
d := schema.TestResourceDataRaw(t, resources.StorageIntegration().Schema, params)
Expand Down
4 changes: 4 additions & 0 deletions pkg/resources/masking_policy_grant_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources_test

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -10,6 +11,9 @@ import (
)

func TestAcc_MaskingPolicyGrant(t *testing.T) {
if _, ok := os.LookupEnv("SKIP_MASKING_POLICY_TESTS"); ok {
t.Skip("Skipping TestAccMaskingPolicy")
}
accName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

resource.Test(t, resource.TestCase{
Expand Down
7 changes: 7 additions & 0 deletions pkg/resources/materialized_view_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources_test

import (
"fmt"
"os"
"strings"
"testing"

Expand All @@ -10,6 +11,9 @@ import (
)

func TestAcc_MaterializedView(t *testing.T) {
if _, ok := os.LookupEnv("SKIP_MATERIALIZED_VIEW_TESTS"); ok {
t.Skip("Skipping TestAcc_MaterializedView")
}
dbName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
schemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
tableName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
Expand All @@ -35,6 +39,9 @@ func TestAcc_MaterializedView(t *testing.T) {
}

func TestAcc_MaterializedView2(t *testing.T) {
if _, ok := os.LookupEnv("SKIP_MATERIALIZED_VIEW_TESTS"); ok {
t.Skip("Skipping TestAcc_MaterializedView2")
}
dbName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
schemaName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
tableName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
Expand Down
Loading