Skip to content

Commit

Permalink
Add missing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jcieslak committed Dec 11, 2023
1 parent 858cd36 commit c5db8d6
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 12 deletions.
45 changes: 33 additions & 12 deletions pkg/resources/external_table_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ func TestAcc_ExternalTable_basic(t *testing.T) {
}
resourceName := "snowflake_external_table.test_table"

configVariables := func() config.Variables {
return map[string]config.Variable{
"name": config.StringVariable(name),
"location": config.StringVariable(bucketURL),
"aws_arn": config.StringVariable(roleName),
"database": config.StringVariable(acc.TestDatabaseName),
"schema": config.StringVariable(acc.TestSchemaName),
}
configVariables := map[string]config.Variable{
"name": config.StringVariable(name),
"location": config.StringVariable(bucketURL),
"aws_arn": config.StringVariable(roleName),
"database": config.StringVariable(acc.TestDatabaseName),
"schema": config.StringVariable(acc.TestSchemaName),
}

resource.Test(t, resource.TestCase{
Expand All @@ -53,7 +51,7 @@ func TestAcc_ExternalTable_basic(t *testing.T) {
Steps: []resource.TestStep{
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: configVariables(),
ConfigVariables: configVariables,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "database", acc.TestDatabaseName),
Expand All @@ -77,6 +75,29 @@ func TestAcc_ExternalTable_basic(t *testing.T) {
// TODO Update tags

func TestAcc_ExternalTable_TagsUpdate(t *testing.T) {
env := os.Getenv("SKIP_EXTERNAL_TABLE_TEST")
if env != "" {
t.Skip("Skipping TestAcc_ExternalTable")
}
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
bucketURL := os.Getenv("AWS_EXTERNAL_BUCKET_URL")
if bucketURL == "" {
t.Skip("Skipping TestAcc_ExternalTable")
}
roleName := os.Getenv("AWS_EXTERNAL_ROLE_NAME")
if roleName == "" {
t.Skip("Skipping TestAcc_ExternalTable")
}
resourceName := "snowflake_external_table.test_table"

configVariables := map[string]config.Variable{
"name": config.StringVariable(name),
"location": config.StringVariable(bucketURL),
"aws_arn": config.StringVariable(roleName),
"database": config.StringVariable(acc.TestDatabaseName),
"schema": config.StringVariable(acc.TestSchemaName),
}

resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acc.TestAccProtoV6ProviderFactories,
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand All @@ -86,10 +107,10 @@ func TestAcc_ExternalTable_TagsUpdate(t *testing.T) {
CheckDestroy: testAccCheckExternalTableDestroy,
Steps: []resource.TestStep{
{
ConfigDirectory: config.TestNameDirectory(),
ConfigVariables: configVariables(),
ConfigDirectory: config.TestStepDirectory(),
ConfigVariables: configVariables,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_external_table.test_table", "comment", "Terraform acceptance test"),
resource.TestCheckResourceAttr(resourceName, "comment", "Terraform acceptance test"),
),
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/resources/testdata/TestAcc_ExternalTable_TagsUpdate/1/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "snowflake_storage_integration" "i" {
name = var.name
storage_allowed_locations = [var.location]
storage_provider = "S3"
storage_aws_role_arn = var.aws_arn
}

resource "snowflake_stage" "test" {
name = var.name
url = var.location
database = var.database
schema = var.schema
storage_integration = snowflake_storage_integration.i.name
}

resource "snowflake_external_table" "test_table" {
name = var.name
database = var.database
schema = var.schema
comment = "Terraform acceptance test"
column {
name = "column1"
type = "STRING"
as = "TO_VARCHAR(TO_TIMESTAMP_NTZ(value:unix_timestamp_property::NUMBER, 3), 'yyyy-mm-dd-hh')"
}
column {
name = "column2"
type = "TIMESTAMP_NTZ(9)"
as = "($1:\"CreatedDate\"::timestamp)"
}
file_format = "TYPE = CSV"
location = "@\"${var.database}\".\"${var.schema}\".\"${snowflake_stage.test.name}\""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "name" {
type = string
}

variable "location" {
type = string
}

variable "aws_arn" {
type = string
}

variable "database" {
type = string
}

variable "schema" {
type = string
}
43 changes: 43 additions & 0 deletions pkg/resources/testdata/TestAcc_ExternalTable_TagsUpdate/2/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
resource "snowflake_storage_integration" "i" {
name = var.name
storage_allowed_locations = [var.location]
storage_provider = "S3"
storage_aws_role_arn = var.aws_arn
}

resource "snowflake_stage" "test" {
name = var.name
url = var.location
database = var.database
schema = var.schema
storage_integration = snowflake_storage_integration.i.name
}

resource "snowflake_tag" "tag" {
name = "test_tag"
database = var.database
schema = var.schema
}

resource "snowflake_external_table" "test_table" {
name = var.name
database = var.database
schema = var.schema
comment = "Terraform acceptance test"
column {
name = "column1"
type = "STRING"
as = "TO_VARCHAR(TO_TIMESTAMP_NTZ(value:unix_timestamp_property::NUMBER, 3), 'yyyy-mm-dd-hh')"
}
column {
name = "column2"
type = "TIMESTAMP_NTZ(9)"
as = "($1:\"CreatedDate\"::timestamp)"
}
file_format = "TYPE = CSV"
location = "@\"${var.database}\".\"${var.schema}\".\"${snowflake_stage.test.name}\""
tag {
name = "\"${var.database}\".\"${var.schema}\".\"test_tag\""
value = "tag_value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "name" {
type = string
}

variable "location" {
type = string
}

variable "aws_arn" {
type = string
}

variable "database" {
type = string
}

variable "schema" {
type = string
}
33 changes: 33 additions & 0 deletions pkg/resources/testdata/TestAcc_ExternalTable_TagsUpdate/3/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "snowflake_storage_integration" "i" {
name = var.name
storage_allowed_locations = [var.location]
storage_provider = "S3"
storage_aws_role_arn = var.aws_arn
}

resource "snowflake_stage" "test" {
name = var.name
url = var.location
database = var.database
schema = var.schema
storage_integration = snowflake_storage_integration.i.name
}

resource "snowflake_external_table" "test_table" {
name = var.name
database = var.database
schema = var.schema
comment = "Terraform acceptance test"
column {
name = "column1"
type = "STRING"
as = "TO_VARCHAR(TO_TIMESTAMP_NTZ(value:unix_timestamp_property::NUMBER, 3), 'yyyy-mm-dd-hh')"
}
column {
name = "column2"
type = "TIMESTAMP_NTZ(9)"
as = "($1:\"CreatedDate\"::timestamp)"
}
file_format = "TYPE = CSV"
location = "@\"${var.database}\".\"${var.schema}\".\"${snowflake_stage.test.name}\""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
variable "name" {
type = string
}

variable "location" {
type = string
}

variable "aws_arn" {
type = string
}

variable "database" {
type = string
}

variable "schema" {
type = string
}

0 comments on commit c5db8d6

Please sign in to comment.