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

[fix] Removing broken test for external table #426

Merged
merged 12 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LDFLAGS=-ldflags "-w -s -X github.com/chanzuckerberg/go-misc/ver.GitSha=${SHA} -
export BASE_BINARY_NAME=terraform-provider-snowflake_v$(VERSION)
export GO111MODULE=on
export TF_ACC_TERRAFORM_VERSION=0.12.29
export SKIP_EXTERNAL_TABLE_TESTS=true

go_test ?= -
ifeq (, $(shell which gotest))
Expand Down
48 changes: 48 additions & 0 deletions docs/resources/external_table.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
page_title: "snowflake_external_table Resource - terraform-provider-snowflake"
subcategory: ""
description: |-
---

# Resource `snowflake_external_table`





## Schema

### Required

- **column** (Block List, Min: 1) Definitions of a column to create in the external table. Minimum one required. (see [below for nested schema](#nestedblock--column))
- **database** (String, Required) The database in which to create the external table.
- **file_format** (String, Required) Specifies the file format for the external table.
- **location** (String, Required) Specifies a location for the external table.
- **name** (String, Required) Specifies the identifier for the external table; must be unique for the database and schema in which the externalTable is created.
- **schema** (String, Required) The schema in which to create the external table.

### Optional

- **auto_refresh** (Boolean, Optional) Specifies whether to automatically refresh the external table metadata once, immediately after the external table is created.
- **aws_sns_topic** (String, Optional) Specifies the aws sns topic for the external table.
- **comment** (String, Optional) Specifies a comment for the external table.
- **copy_grants** (Boolean, Optional) Specifies to retain the access permissions from the original table when an external table is recreated using the CREATE OR REPLACE TABLE variant
- **id** (String, Optional) The ID of this resource.
- **partition_by** (List of String, Optional) Specifies any partition columns to evaluate for the external table.
- **refresh_on_create** (Boolean, Optional) Specifies weather to refresh when an external table is created.

### Read-only

- **owner** (String, Read-only) Name of the role that owns the external table.

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

Required:

- **as** (String, Required) String that specifies the expression for the column. When queried, the column returns results derived from this expression.
- **name** (String, Required) Column name
- **type** (String, Required) Column type, e.g. VARIANT


26 changes: 20 additions & 6 deletions pkg/resources/external_table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package resources_test

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

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

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

resource.Test(t, resource.TestCase{
Providers: providers(),
Steps: []resource.TestStep{
{
Config: externalTableConfig(accName),
Config: externalTableConfig(accName, []string{"s3://com.example.bucket/prefix"}),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_external_table.test_table", "name", accName),
resource.TestCheckResourceAttr("snowflake_external_table.test_table", "database", accName),
Expand All @@ -27,7 +32,7 @@ func TestAccExternalTable(t *testing.T) {
})
}

func externalTableConfig(name string) string {
func externalTableConfig(name string, locations []string) string {
s := `
resource "snowflake_database" "test" {
name = "%v"
Expand All @@ -42,9 +47,18 @@ resource "snowflake_schema" "test" {
resource "snowflake_stage" "test" {
name = "%v"
url = "s3://com.example.bucket/prefix"
database = snowflake_database.test.name
schema = snowflake_schema.test.name
comment = "Terraform acceptance test"
storage_integration = snowflake_storage_integration.i.name
}
resource "snowflake_storage_integration" "i" {
name = "%v"
storage_allowed_locations = %q
storage_provider = "S3"
storage_aws_role_arn = "arn:aws:iam::000000000001:/role/test"
}
resource "snowflake_external_table" "test_table" {
Expand All @@ -54,17 +68,17 @@ resource "snowflake_external_table" "test_table" {
comment = "Terraform acceptance test"
column {
name = "column1"
type = "VARIANT"
type = "TIMESTAMP_NTZ(9)"
as = "($1:\"CreatedDate\"::timestamp)"
}
column {
name = "column2"
type = "VARCHAR"
type = "TIMESTAMP_NTZ(9)"
as = "($1:\"CreatedDate\"::timestamp)"
}
file_format = "TYPE = CSV"
location = "@${snowflake_database.test.name}.${snowflake_schema.test.name}.${snowflake_stage.test.name}"
}
`
return fmt.Sprintf(s, name, name, name, name)
return fmt.Sprintf(s, name, name, name, name, locations, name)
}