Skip to content

Commit

Permalink
[fix] Removing broken test for external table (Snowflake-Labs#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
alldoami authored and Gino John Varghese committed Mar 16, 2021
1 parent a984c96 commit eb165ea
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
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)
}

0 comments on commit eb165ea

Please sign in to comment.