From 4bcf7332db8d83fb09cf4240bc97ea3fc6709792 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 16:16:57 -0700
Subject: [PATCH 1/6] Start creating db-specific config schemas
---
examples/deployments/main.tf | 172 +++++++++---------
internal/provider/deployment_resource.go | 26 +--
.../models/deployment_resource_model.go | 28 +--
.../provider/models/translate_deployment.go | 47 ++---
4 files changed, 112 insertions(+), 161 deletions(-)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index c673303..c391d25 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -10,115 +10,115 @@ provider "artie" {
endpoint = "http://0.0.0.0:8000"
}
-# import {
-# to = artie_destination.snowflake
-# id = "51b180a0-fbb9-49a2-ab45-cb46d913416d"
-# }
+import {
+ to = artie_destination.snowflake
+ id = "51b180a0-fbb9-49a2-ab45-cb46d913416d"
+}
+
+import {
+ to = artie_deployment.dev_postgres_to_snowflake
+ id = "c3dfa503-b6ae-48f3-a6b1-8491a506126d"
+}
+
+variable "snowflake_password" {
+ type = string
+ sensitive = true
+}
+variable "postgres_password" {
+ type = string
+ sensitive = true
+}
+
+resource "artie_destination" "snowflake" {
+ name = "Snowflake"
+ label = "Snowflake (Partner Account)"
+ config = {
+ snowflake_account_url = "https://znb46775.snowflakecomputing.com"
+ username = "tang8330"
+ password = var.snowflake_password
+ snowflake_virtual_dwh = "compute_wh"
+ }
+}
+
+resource "artie_deployment" "dev_postgres_to_snowflake" {
+ name = "Dev PostgreSQL > Snowflake"
+ source = {
+ name = "PostgreSQL"
+ postgres_config = {
+ host = "db-postgresql-sfo3-03243-do-user-13261354-0.c.db.ondigitalocean.com"
+ port = 25060
+ database = "prod_dump_july_2024_4cvzb"
+ user = "doadmin"
+ password = var.postgres_password
+ }
+ tables = [
+ {
+ name = "invite"
+ schema = "public"
+ }
+ ]
+ }
+ destination_uuid = artie_destination.snowflake.uuid
+ destination_config = {
+ database = "DEV_TEST"
+ schema = "PUBLIC"
+ }
+}
# import {
-# to = artie_deployment.dev_postgres_to_snowflake
-# id = "c3dfa503-b6ae-48f3-a6b1-8491a506126d"
+# to = artie_destination.bigquery
+# id = "fa7d4efc-3957-41e5-b29c-66e2d49bffde"
# }
-# variable "snowflake_password" {
+# variable "mongodb_password" {
# type = string
# sensitive = true
# }
-# variable "postgres_password" {
+
+# variable "gcp_creds" {
# type = string
# sensitive = true
# }
-# resource "artie_destination" "snowflake" {
-# name = "Snowflake"
-# label = "Snowflake (Partner Account)"
+# resource "artie_destination" "bigquery" {
+# name = "BigQuery"
+# label = "BigQuery"
# config = {
-# snowflake_account_url = "https://znb46775.snowflakecomputing.com"
-# username = "tang8330"
-# password = var.snowflake_password
-# snowflake_virtual_dwh = "compute_wh"
+# gcp_location = "us"
+# gcp_project_id = "artie-labs"
+# gcp_credentials_data = var.gcp_creds
# }
# }
-# resource "artie_deployment" "dev_postgres_to_snowflake" {
-# name = "Dev PostgreSQL > Snowflake"
+# import {
+# to = artie_deployment.example
+# id = "38d5d2db-870a-4a38-a76c-9891b0e5122d"
+# }
+
+# resource "artie_deployment" "example" {
+# name = "MongoDB ➡️ BigQuery"
# source = {
-# name = "PostgreSQL"
+# name = "MongoDB"
# config = {
-# host = "db-postgresql-sfo3-03243-do-user-13261354-0.c.db.ondigitalocean.com"
-# port = 25060
-# database = "prod_dump_july_2024_4cvzb"
-# user = "doadmin"
-# password = var.postgres_password
+# database = "myFirstDatabase"
+# host = "mongodb+srv://cluster0.szddg49.mongodb.net/"
+# port = 0
+# user = "artie"
+# password = var.mongodb_password
# }
# tables = [
# {
-# name = "invite"
-# schema = "public"
+# name = "customers"
+# schema = ""
+# },
+# {
+# name = "stock"
+# schema = ""
# }
# ]
# }
-# destination_uuid = artie_destination.snowflake.uuid
+# destination_uuid = artie_destination.bigquery.uuid
# destination_config = {
-# database = "DEV_TEST"
-# schema = "PUBLIC"
+# dataset = "customers"
# }
# }
-
-import {
- to = artie_destination.bigquery
- id = "fa7d4efc-3957-41e5-b29c-66e2d49bffde"
-}
-
-variable "mongodb_password" {
- type = string
- sensitive = true
-}
-
-variable "gcp_creds" {
- type = string
- sensitive = true
-}
-
-resource "artie_destination" "bigquery" {
- name = "BigQuery"
- label = "BigQuery"
- config = {
- gcp_location = "us"
- gcp_project_id = "artie-labs"
- gcp_credentials_data = var.gcp_creds
- }
-}
-
-import {
- to = artie_deployment.example
- id = "38d5d2db-870a-4a38-a76c-9891b0e5122d"
-}
-
-resource "artie_deployment" "example" {
- name = "MongoDB ➡️ BigQuery"
- source = {
- name = "MongoDB"
- config = {
- database = "myFirstDatabase"
- host = "mongodb+srv://cluster0.szddg49.mongodb.net/"
- port = 0
- user = "artie"
- password = var.mongodb_password
- }
- tables = [
- {
- name = "customers"
- schema = ""
- },
- {
- name = "stock"
- schema = ""
- }
- ]
- }
- destination_uuid = artie_destination.bigquery.uuid
- destination_config = {
- dataset = "customers"
- }
-}
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index eaa52a4..b3b988a 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -14,7 +14,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
- "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -52,27 +51,14 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
Required: true,
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{Required: true},
- "config": schema.SingleNestedAttribute{
+ "postgres_config": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
- "host": schema.StringAttribute{Required: true},
- "snapshot_host": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "port": schema.Int64Attribute{Required: true},
- "user": schema.StringAttribute{Required: true},
- "password": schema.StringAttribute{Required: true, Sensitive: true},
- "database": schema.StringAttribute{Required: true},
- "dynamodb": schema.SingleNestedAttribute{
- Optional: true,
- Computed: true,
- Attributes: map[string]schema.Attribute{
- "region": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString(""), PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- "table_name": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString(""), PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- "streams_arn": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString(""), PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- "aws_access_key_id": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString(""), PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- "aws_secret_access_key": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString(""), PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- },
- PlanModifiers: []planmodifier.Object{objectplanmodifier.UseStateForUnknown()},
- },
+ "host": schema.StringAttribute{Required: true},
+ "port": schema.Int64Attribute{Required: true},
+ "user": schema.StringAttribute{Required: true},
+ "password": schema.StringAttribute{Required: true, Sensitive: true},
+ "database": schema.StringAttribute{Required: true},
},
},
"tables": schema.ListNestedAttribute{
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index 195cdcc..a656c5c 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -13,27 +13,17 @@ type DeploymentResourceModel struct {
}
type SourceModel struct {
- Name types.String `tfsdk:"name"`
- Config SourceConfigModel `tfsdk:"config"`
- Tables []TableModel `tfsdk:"tables"`
+ Name types.String `tfsdk:"name"`
+ PostgresConfig PostgresConfigModel `tfsdk:"postgres_config"`
+ Tables []TableModel `tfsdk:"tables"`
}
-type SourceConfigModel struct {
- Host types.String `tfsdk:"host"`
- SnapshotHost types.String `tfsdk:"snapshot_host"`
- Port types.Int64 `tfsdk:"port"`
- User types.String `tfsdk:"user"`
- Database types.String `tfsdk:"database"`
- DynamoDB *DynamoDBConfigModel `tfsdk:"dynamodb"`
- Password types.String `tfsdk:"password"`
-}
-
-type DynamoDBConfigModel struct {
- Region types.String `tfsdk:"region"`
- TableName types.String `tfsdk:"table_name"`
- StreamsArn types.String `tfsdk:"streams_arn"`
- AwsAccessKeyID types.String `tfsdk:"aws_access_key_id"`
- AwsSecretAccessKey types.String `tfsdk:"aws_secret_access_key"`
+type PostgresConfigModel struct {
+ Host types.String `tfsdk:"host"`
+ Port types.Int64 `tfsdk:"port"`
+ User types.String `tfsdk:"user"`
+ Database types.String `tfsdk:"database"`
+ Password types.String `tfsdk:"password"`
}
type TableModel struct {
diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go
index 6c79ba7..e552a59 100644
--- a/internal/provider/models/translate_deployment.go
+++ b/internal/provider/models/translate_deployment.go
@@ -23,26 +23,14 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
IsPartitioned: types.BoolValue(apiTable.IsPartitioned),
})
}
- var dynamoDBConfig *DynamoDBConfigModel
- if apiModel.Source.Config.DynamoDB != nil {
- dynamoDBConfig = &DynamoDBConfigModel{
- Region: types.StringValue(apiModel.Source.Config.DynamoDB.Region),
- TableName: types.StringValue(apiModel.Source.Config.DynamoDB.TableName),
- StreamsArn: types.StringValue(apiModel.Source.Config.DynamoDB.StreamsArn),
- AwsAccessKeyID: types.StringValue(apiModel.Source.Config.DynamoDB.AwsAccessKeyID),
- AwsSecretAccessKey: types.StringValue(apiModel.Source.Config.DynamoDB.AwsSecretAccessKey),
- }
- }
resourceModel.Source = &SourceModel{
Name: types.StringValue(apiModel.Source.Name),
- Config: SourceConfigModel{
- Host: types.StringValue(apiModel.Source.Config.Host),
- SnapshotHost: types.StringValue(apiModel.Source.Config.SnapshotHost),
- Port: types.Int64Value(apiModel.Source.Config.Port),
- User: types.StringValue(apiModel.Source.Config.User),
- Password: types.StringValue(apiModel.Source.Config.Password),
- Database: types.StringValue(apiModel.Source.Config.Database),
- DynamoDB: dynamoDBConfig,
+ PostgresConfig: PostgresConfigModel{
+ Host: types.StringValue(apiModel.Source.Config.Host),
+ Port: types.Int64Value(apiModel.Source.Config.Port),
+ User: types.StringValue(apiModel.Source.Config.User),
+ Password: types.StringValue(apiModel.Source.Config.Password),
+ Database: types.StringValue(apiModel.Source.Config.Database),
},
Tables: tables,
}
@@ -75,17 +63,6 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
})
}
- var dynamoDBConfig *DynamoDBConfigAPIModel
- if resourceModel.Source.Config.DynamoDB != nil {
- dynamoDBConfig = &DynamoDBConfigAPIModel{
- Region: resourceModel.Source.Config.DynamoDB.Region.ValueString(),
- TableName: resourceModel.Source.Config.DynamoDB.TableName.ValueString(),
- StreamsArn: resourceModel.Source.Config.DynamoDB.StreamsArn.ValueString(),
- AwsAccessKeyID: resourceModel.Source.Config.DynamoDB.AwsAccessKeyID.ValueString(),
- AwsSecretAccessKey: resourceModel.Source.Config.DynamoDB.AwsSecretAccessKey.ValueString(),
- }
- }
-
return DeploymentAPIModel{
UUID: resourceModel.UUID.ValueString(),
CompanyUUID: resourceModel.CompanyUUID.ValueString(),
@@ -95,13 +72,11 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
Source: SourceAPIModel{
Name: resourceModel.Source.Name.ValueString(),
Config: SourceConfigAPIModel{
- Host: resourceModel.Source.Config.Host.ValueString(),
- SnapshotHost: resourceModel.Source.Config.SnapshotHost.ValueString(),
- Port: resourceModel.Source.Config.Port.ValueInt64(),
- User: resourceModel.Source.Config.User.ValueString(),
- Password: resourceModel.Source.Config.Password.ValueString(),
- Database: resourceModel.Source.Config.Database.ValueString(),
- DynamoDB: dynamoDBConfig,
+ Host: resourceModel.Source.PostgresConfig.Host.ValueString(),
+ Port: resourceModel.Source.PostgresConfig.Port.ValueInt64(),
+ User: resourceModel.Source.PostgresConfig.User.ValueString(),
+ Password: resourceModel.Source.PostgresConfig.Password.ValueString(),
+ Database: resourceModel.Source.PostgresConfig.Database.ValueString(),
},
Tables: tables,
},
From 757da46f4b1544ebbbd69b5e276271bb92a6c6c4 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 16:42:31 -0700
Subject: [PATCH 2/6] Separate config schemas for different destination types
---
docs/resources/deployment.md | 23 +----
docs/resources/destination.md | 44 +++++++---
examples/deployments/main.tf | 10 +--
internal/provider/destination_resource.go | 42 ++++++----
.../models/destination_resource_model.go | 49 ++++++-----
.../provider/models/translate_destination.go | 83 ++++++++++++-------
6 files changed, 143 insertions(+), 108 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index 17e5708..c96c9ba 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -51,12 +51,12 @@ Optional:
Required:
-- `config` (Attributes) (see [below for nested schema](#nestedatt--source--config))
- `name` (String)
+- `postgres_config` (Attributes) (see [below for nested schema](#nestedatt--source--postgres_config))
- `tables` (Attributes List) (see [below for nested schema](#nestedatt--source--tables))
-
-### Nested Schema for `source.config`
+
+### Nested Schema for `source.postgres_config`
Required:
@@ -66,23 +66,6 @@ Required:
- `port` (Number)
- `user` (String)
-Optional:
-
-- `dynamodb` (Attributes) (see [below for nested schema](#nestedatt--source--config--dynamodb))
-- `snapshot_host` (String)
-
-
-### Nested Schema for `source.config.dynamodb`
-
-Optional:
-
-- `aws_access_key_id` (String)
-- `aws_secret_access_key` (String)
-- `region` (String)
-- `streams_arn` (String)
-- `table_name` (String)
-
-
### Nested Schema for `source.tables`
diff --git a/docs/resources/destination.md b/docs/resources/destination.md
index 147d900..5959519 100644
--- a/docs/resources/destination.md
+++ b/docs/resources/destination.md
@@ -17,12 +17,14 @@ Artie Destination resource
### Required
-- `config` (Attributes) (see [below for nested schema](#nestedatt--config))
- `name` (String)
### Optional
+- `big_query_config` (Attributes) (see [below for nested schema](#nestedatt--big_query_config))
- `label` (String)
+- `redshift_config` (Attributes) (see [below for nested schema](#nestedatt--redshift_config))
+- `snowflake_config` (Attributes) (see [below for nested schema](#nestedatt--snowflake_config))
### Read-Only
@@ -30,22 +32,38 @@ Artie Destination resource
- `ssh_tunnel_uuid` (String)
- `uuid` (String)
-
-### Nested Schema for `config`
+
+### Nested Schema for `big_query_config`
-Optional:
+Required:
+
+- `credentials_data` (String, Sensitive)
+- `location` (String)
+- `project_id` (String)
+
+
+
+### Nested Schema for `redshift_config`
+
+Required:
-- `aws_access_key_id` (String)
-- `aws_region` (String)
-- `aws_secret_access_key` (String, Sensitive)
- `endpoint` (String)
-- `gcp_credentials_data` (String, Sensitive)
-- `gcp_location` (String)
-- `gcp_project_id` (String)
- `host` (String)
- `password` (String, Sensitive)
- `port` (Number)
-- `snowflake_account_url` (String)
-- `snowflake_private_key` (String, Sensitive)
-- `snowflake_virtual_dwh` (String)
- `username` (String)
+
+
+
+### Nested Schema for `snowflake_config`
+
+Required:
+
+- `account_url` (String)
+- `username` (String)
+- `virtual_dwh` (String)
+
+Optional:
+
+- `password` (String, Sensitive)
+- `private_key` (String, Sensitive)
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index c391d25..aba8759 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -32,11 +32,11 @@ variable "postgres_password" {
resource "artie_destination" "snowflake" {
name = "Snowflake"
label = "Snowflake (Partner Account)"
- config = {
- snowflake_account_url = "https://znb46775.snowflakecomputing.com"
- username = "tang8330"
- password = var.snowflake_password
- snowflake_virtual_dwh = "compute_wh"
+ snowflake_config = {
+ account_url = "https://znb46775.snowflakecomputing.com"
+ virtual_dwh = "compute_wh"
+ username = "tang8330"
+ password = var.snowflake_password
}
}
diff --git a/internal/provider/destination_resource.go b/internal/provider/destination_resource.go
index 76ce718..707736f 100644
--- a/internal/provider/destination_resource.go
+++ b/internal/provider/destination_resource.go
@@ -12,7 +12,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
- "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
@@ -46,23 +45,32 @@ func (r *DestinationResource) Schema(ctx context.Context, req resource.SchemaReq
"ssh_tunnel_uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"name": schema.StringAttribute{Required: true},
"label": schema.StringAttribute{Optional: true},
- "config": schema.SingleNestedAttribute{
- Required: true,
+ "snowflake_config": schema.SingleNestedAttribute{
+ Optional: true,
Attributes: map[string]schema.Attribute{
- "host": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "port": schema.Int64Attribute{Optional: true, Computed: true, Default: int64default.StaticInt64(0)},
- "endpoint": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "username": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "password": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
- "gcp_project_id": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "gcp_location": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "gcp_credentials_data": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
- "aws_access_key_id": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "aws_secret_access_key": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
- "aws_region": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "snowflake_account_url": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "snowflake_virtual_dwh": schema.StringAttribute{Optional: true, Computed: true, Default: stringdefault.StaticString("")},
- "snowflake_private_key": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
+ "account_url": schema.StringAttribute{Required: true},
+ "virtual_dwh": schema.StringAttribute{Required: true},
+ "username": schema.StringAttribute{Required: true},
+ "password": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
+ "private_key": schema.StringAttribute{Optional: true, Computed: true, Sensitive: true, Default: stringdefault.StaticString("")},
+ },
+ },
+ "big_query_config": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "project_id": schema.StringAttribute{Required: true},
+ "location": schema.StringAttribute{Required: true},
+ "credentials_data": schema.StringAttribute{Required: true, Sensitive: true},
+ },
+ },
+ "redshift_config": schema.SingleNestedAttribute{
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "endpoint": schema.StringAttribute{Required: true},
+ "host": schema.StringAttribute{Required: true},
+ "port": schema.Int64Attribute{Required: true},
+ "username": schema.StringAttribute{Required: true},
+ "password": schema.StringAttribute{Required: true, Sensitive: true},
},
},
},
diff --git a/internal/provider/models/destination_resource_model.go b/internal/provider/models/destination_resource_model.go
index 1541d88..0c3d5a4 100644
--- a/internal/provider/models/destination_resource_model.go
+++ b/internal/provider/models/destination_resource_model.go
@@ -3,27 +3,34 @@ package models
import "github.com/hashicorp/terraform-plugin-framework/types"
type DestinationResourceModel struct {
- UUID types.String `tfsdk:"uuid"`
- CompanyUUID types.String `tfsdk:"company_uuid"`
- SSHTunnelUUID types.String `tfsdk:"ssh_tunnel_uuid"`
- Name types.String `tfsdk:"name"`
- Label types.String `tfsdk:"label"`
- Config *DestinationSharedConfigModel `tfsdk:"config"`
+ UUID types.String `tfsdk:"uuid"`
+ CompanyUUID types.String `tfsdk:"company_uuid"`
+ SSHTunnelUUID types.String `tfsdk:"ssh_tunnel_uuid"`
+ Name types.String `tfsdk:"name"`
+ Label types.String `tfsdk:"label"`
+ SnowflakeConfig *SnowflakeSharedConfigModel `tfsdk:"snowflake_config"`
+ BigQueryConfig *BigQuerySharedConfigModel `tfsdk:"big_query_config"`
+ RedshiftConfig *RedshiftSharedConfigModel `tfsdk:"redshift_config"`
}
-type DestinationSharedConfigModel struct {
- Host types.String `tfsdk:"host"`
- Port types.Int64 `tfsdk:"port"`
- Endpoint types.String `tfsdk:"endpoint"`
- Username types.String `tfsdk:"username"`
- Password types.String `tfsdk:"password"`
- GCPProjectID types.String `tfsdk:"gcp_project_id"`
- GCPLocation types.String `tfsdk:"gcp_location"`
- GCPCredentialsData types.String `tfsdk:"gcp_credentials_data"`
- AWSAccessKeyID types.String `tfsdk:"aws_access_key_id"`
- AWSSecretAccessKey types.String `tfsdk:"aws_secret_access_key"`
- AWSRegion types.String `tfsdk:"aws_region"`
- SnowflakeAccountURL types.String `tfsdk:"snowflake_account_url"`
- SnowflakeVirtualDWH types.String `tfsdk:"snowflake_virtual_dwh"`
- SnowflakePrivateKey types.String `tfsdk:"snowflake_private_key"`
+type SnowflakeSharedConfigModel struct {
+ AccountURL types.String `tfsdk:"account_url"`
+ VirtualDWH types.String `tfsdk:"virtual_dwh"`
+ Username types.String `tfsdk:"username"`
+ Password types.String `tfsdk:"password"`
+ PrivateKey types.String `tfsdk:"private_key"`
+}
+
+type BigQuerySharedConfigModel struct {
+ ProjectID types.String `tfsdk:"project_id"`
+ Location types.String `tfsdk:"location"`
+ CredentialsData types.String `tfsdk:"credentials_data"`
+}
+
+type RedshiftSharedConfigModel struct {
+ Endpoint types.String `tfsdk:"endpoint"`
+ Host types.String `tfsdk:"host"`
+ Port types.Int64 `tfsdk:"port"`
+ Username types.String `tfsdk:"username"`
+ Password types.String `tfsdk:"password"`
}
diff --git a/internal/provider/models/translate_destination.go b/internal/provider/models/translate_destination.go
index 0a00fc6..373bd0b 100644
--- a/internal/provider/models/translate_destination.go
+++ b/internal/provider/models/translate_destination.go
@@ -12,21 +12,29 @@ func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *
resourceModel.Label = types.StringValue(apiModel.Label)
resourceModel.SSHTunnelUUID = types.StringValue(apiModel.SSHTunnelUUID)
- resourceModel.Config = &DestinationSharedConfigModel{
- Host: types.StringValue(apiModel.Config.Host),
- Port: types.Int64Value(apiModel.Config.Port),
- Endpoint: types.StringValue(apiModel.Config.Endpoint),
- Username: types.StringValue(apiModel.Config.Username),
- Password: types.StringValue(apiModel.Config.Password),
- GCPProjectID: types.StringValue(apiModel.Config.GCPProjectID),
- GCPLocation: types.StringValue(apiModel.Config.GCPLocation),
- GCPCredentialsData: types.StringValue(apiModel.Config.GCPCredentialsData),
- AWSAccessKeyID: types.StringValue(apiModel.Config.AWSAccessKeyID),
- AWSSecretAccessKey: types.StringValue(apiModel.Config.AWSSecretAccessKey),
- AWSRegion: types.StringValue(apiModel.Config.AWSRegion),
- SnowflakeAccountURL: types.StringValue(apiModel.Config.SnowflakeAccountURL),
- SnowflakeVirtualDWH: types.StringValue(apiModel.Config.SnowflakeVirtualDWH),
- SnowflakePrivateKey: types.StringValue(apiModel.Config.SnowflakePrivateKey),
+ switch resourceModel.Name.ValueString() {
+ case "Snowflake":
+ resourceModel.SnowflakeConfig = &SnowflakeSharedConfigModel{
+ AccountURL: types.StringValue(apiModel.Config.SnowflakeAccountURL),
+ VirtualDWH: types.StringValue(apiModel.Config.SnowflakeVirtualDWH),
+ PrivateKey: types.StringValue(apiModel.Config.SnowflakePrivateKey),
+ Username: types.StringValue(apiModel.Config.Username),
+ Password: types.StringValue(apiModel.Config.Password),
+ }
+ case "BigQuery":
+ resourceModel.BigQueryConfig = &BigQuerySharedConfigModel{
+ ProjectID: types.StringValue(apiModel.Config.GCPProjectID),
+ Location: types.StringValue(apiModel.Config.GCPLocation),
+ CredentialsData: types.StringValue(apiModel.Config.GCPCredentialsData),
+ }
+ case "Redshift":
+ resourceModel.RedshiftConfig = &RedshiftSharedConfigModel{
+ Endpoint: types.StringValue(apiModel.Config.Endpoint),
+ Host: types.StringValue(apiModel.Config.Host),
+ Port: types.Int64Value(apiModel.Config.Port),
+ Username: types.StringValue(apiModel.Config.Username),
+ Password: types.StringValue(apiModel.Config.Password),
+ }
}
}
@@ -35,27 +43,38 @@ func DestinationResourceToAPIModel(resourceModel DestinationResourceModel) Desti
if sshTunnelUUID == "" {
sshTunnelUUID = uuid.Nil.String()
}
- return DestinationAPIModel{
+ apiModel := DestinationAPIModel{
UUID: resourceModel.UUID.ValueString(),
CompanyUUID: resourceModel.CompanyUUID.ValueString(),
Name: resourceModel.Name.ValueString(),
Label: resourceModel.Label.ValueString(),
SSHTunnelUUID: sshTunnelUUID,
- Config: DestinationSharedConfigAPIModel{
- Host: resourceModel.Config.Host.ValueString(),
- Port: resourceModel.Config.Port.ValueInt64(),
- Endpoint: resourceModel.Config.Endpoint.ValueString(),
- Username: resourceModel.Config.Username.ValueString(),
- Password: resourceModel.Config.Password.ValueString(),
- GCPProjectID: resourceModel.Config.GCPProjectID.ValueString(),
- GCPLocation: resourceModel.Config.GCPLocation.ValueString(),
- GCPCredentialsData: resourceModel.Config.GCPCredentialsData.ValueString(),
- AWSAccessKeyID: resourceModel.Config.AWSAccessKeyID.ValueString(),
- AWSSecretAccessKey: resourceModel.Config.AWSSecretAccessKey.ValueString(),
- AWSRegion: resourceModel.Config.AWSRegion.ValueString(),
- SnowflakeAccountURL: resourceModel.Config.SnowflakeAccountURL.ValueString(),
- SnowflakeVirtualDWH: resourceModel.Config.SnowflakeVirtualDWH.ValueString(),
- SnowflakePrivateKey: resourceModel.Config.SnowflakePrivateKey.ValueString(),
- },
}
+
+ switch resourceModel.Name.ValueString() {
+ case "Snowflake":
+ apiModel.Config = DestinationSharedConfigAPIModel{
+ SnowflakeAccountURL: resourceModel.SnowflakeConfig.AccountURL.ValueString(),
+ SnowflakeVirtualDWH: resourceModel.SnowflakeConfig.VirtualDWH.ValueString(),
+ SnowflakePrivateKey: resourceModel.SnowflakeConfig.PrivateKey.ValueString(),
+ Username: resourceModel.SnowflakeConfig.Username.ValueString(),
+ Password: resourceModel.SnowflakeConfig.Password.ValueString(),
+ }
+ case "BigQuery":
+ apiModel.Config = DestinationSharedConfigAPIModel{
+ GCPProjectID: resourceModel.BigQueryConfig.ProjectID.ValueString(),
+ GCPLocation: resourceModel.BigQueryConfig.Location.ValueString(),
+ GCPCredentialsData: resourceModel.BigQueryConfig.CredentialsData.ValueString(),
+ }
+ case "Redshift":
+ apiModel.Config = DestinationSharedConfigAPIModel{
+ Endpoint: resourceModel.RedshiftConfig.Endpoint.ValueString(),
+ Host: resourceModel.RedshiftConfig.Host.ValueString(),
+ Port: resourceModel.RedshiftConfig.Port.ValueInt64(),
+ Username: resourceModel.RedshiftConfig.Username.ValueString(),
+ Password: resourceModel.RedshiftConfig.Password.ValueString(),
+ }
+ }
+
+ return apiModel
}
From 640a1a58336b99ed1b2a66d2a9a5c7d412f10fe5 Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 16:47:43 -0700
Subject: [PATCH 3/6] Rename destination.name to type
---
docs/resources/destination.md | 2 +-
examples/deployments/main.tf | 2 +-
internal/provider/destination_resource.go | 4 ++--
internal/provider/models/destination_api_model.go | 2 +-
internal/provider/models/destination_resource_model.go | 2 +-
internal/provider/models/translate_destination.go | 8 ++++----
6 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/docs/resources/destination.md b/docs/resources/destination.md
index 5959519..b286678 100644
--- a/docs/resources/destination.md
+++ b/docs/resources/destination.md
@@ -17,7 +17,7 @@ Artie Destination resource
### Required
-- `name` (String)
+- `type` (String)
### Optional
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index aba8759..67d9817 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -30,7 +30,7 @@ variable "postgres_password" {
}
resource "artie_destination" "snowflake" {
- name = "Snowflake"
+ type = "Snowflake"
label = "Snowflake (Partner Account)"
snowflake_config = {
account_url = "https://znb46775.snowflakecomputing.com"
diff --git a/internal/provider/destination_resource.go b/internal/provider/destination_resource.go
index 707736f..617da76 100644
--- a/internal/provider/destination_resource.go
+++ b/internal/provider/destination_resource.go
@@ -43,7 +43,7 @@ func (r *DestinationResource) Schema(ctx context.Context, req resource.SchemaReq
"uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"company_uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
"ssh_tunnel_uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}},
- "name": schema.StringAttribute{Required: true},
+ "type": schema.StringAttribute{Required: true},
"label": schema.StringAttribute{Optional: true},
"snowflake_config": schema.SingleNestedAttribute{
Optional: true,
@@ -107,7 +107,7 @@ func (r *DestinationResource) Create(ctx context.Context, req resource.CreateReq
destModel := models.DestinationResourceToAPIModel(data)
payload := map[string]any{
- "name": destModel.Name,
+ "name": destModel.Type,
"label": destModel.Label,
"sharedConfig": destModel.Config,
}
diff --git a/internal/provider/models/destination_api_model.go b/internal/provider/models/destination_api_model.go
index 409fcac..f84e1a1 100644
--- a/internal/provider/models/destination_api_model.go
+++ b/internal/provider/models/destination_api_model.go
@@ -3,7 +3,7 @@ package models
type DestinationAPIModel struct {
UUID string `json:"uuid"`
CompanyUUID string `json:"companyUUID"`
- Name string `json:"name"`
+ Type string `json:"name"`
Label string `json:"label"`
SSHTunnelUUID string `json:"sshTunnelUUID"`
Config DestinationSharedConfigAPIModel `json:"sharedConfig"`
diff --git a/internal/provider/models/destination_resource_model.go b/internal/provider/models/destination_resource_model.go
index 0c3d5a4..b603688 100644
--- a/internal/provider/models/destination_resource_model.go
+++ b/internal/provider/models/destination_resource_model.go
@@ -6,7 +6,7 @@ type DestinationResourceModel struct {
UUID types.String `tfsdk:"uuid"`
CompanyUUID types.String `tfsdk:"company_uuid"`
SSHTunnelUUID types.String `tfsdk:"ssh_tunnel_uuid"`
- Name types.String `tfsdk:"name"`
+ Type types.String `tfsdk:"type"`
Label types.String `tfsdk:"label"`
SnowflakeConfig *SnowflakeSharedConfigModel `tfsdk:"snowflake_config"`
BigQueryConfig *BigQuerySharedConfigModel `tfsdk:"big_query_config"`
diff --git a/internal/provider/models/translate_destination.go b/internal/provider/models/translate_destination.go
index 373bd0b..3fe7de4 100644
--- a/internal/provider/models/translate_destination.go
+++ b/internal/provider/models/translate_destination.go
@@ -8,11 +8,11 @@ import (
func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *DestinationResourceModel) {
resourceModel.UUID = types.StringValue(apiModel.UUID)
resourceModel.CompanyUUID = types.StringValue(apiModel.CompanyUUID)
- resourceModel.Name = types.StringValue(apiModel.Name)
+ resourceModel.Type = types.StringValue(apiModel.Type)
resourceModel.Label = types.StringValue(apiModel.Label)
resourceModel.SSHTunnelUUID = types.StringValue(apiModel.SSHTunnelUUID)
- switch resourceModel.Name.ValueString() {
+ switch resourceModel.Type.ValueString() {
case "Snowflake":
resourceModel.SnowflakeConfig = &SnowflakeSharedConfigModel{
AccountURL: types.StringValue(apiModel.Config.SnowflakeAccountURL),
@@ -46,12 +46,12 @@ func DestinationResourceToAPIModel(resourceModel DestinationResourceModel) Desti
apiModel := DestinationAPIModel{
UUID: resourceModel.UUID.ValueString(),
CompanyUUID: resourceModel.CompanyUUID.ValueString(),
- Name: resourceModel.Name.ValueString(),
+ Type: resourceModel.Type.ValueString(),
Label: resourceModel.Label.ValueString(),
SSHTunnelUUID: sshTunnelUUID,
}
- switch resourceModel.Name.ValueString() {
+ switch resourceModel.Type.ValueString() {
case "Snowflake":
apiModel.Config = DestinationSharedConfigAPIModel{
SnowflakeAccountURL: resourceModel.SnowflakeConfig.AccountURL.ValueString(),
From 62021b7eecbf7f47d82c514bb833664c3d66681e Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 16:51:14 -0700
Subject: [PATCH 4/6] Rename source.name to type
---
docs/resources/deployment.md | 2 +-
examples/deployments/main.tf | 2 +-
internal/provider/deployment_resource.go | 4 ++--
internal/provider/models/deployment_api_model.go | 2 +-
internal/provider/models/deployment_resource_model.go | 2 +-
internal/provider/models/translate_deployment.go | 4 ++--
6 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index c96c9ba..c5402a3 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -51,9 +51,9 @@ Optional:
Required:
-- `name` (String)
- `postgres_config` (Attributes) (see [below for nested schema](#nestedatt--source--postgres_config))
- `tables` (Attributes List) (see [below for nested schema](#nestedatt--source--tables))
+- `type` (String)
### Nested Schema for `source.postgres_config`
diff --git a/examples/deployments/main.tf b/examples/deployments/main.tf
index 67d9817..ea81f87 100644
--- a/examples/deployments/main.tf
+++ b/examples/deployments/main.tf
@@ -43,7 +43,7 @@ resource "artie_destination" "snowflake" {
resource "artie_deployment" "dev_postgres_to_snowflake" {
name = "Dev PostgreSQL > Snowflake"
source = {
- name = "PostgreSQL"
+ type = "PostgreSQL"
postgres_config = {
host = "db-postgresql-sfo3-03243-do-user-13261354-0.c.db.ondigitalocean.com"
port = 25060
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index b3b988a..a658e60 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -50,7 +50,7 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
"source": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
- "name": schema.StringAttribute{Required: true},
+ "type": schema.StringAttribute{Required: true},
"postgres_config": schema.SingleNestedAttribute{
Required: true,
Attributes: map[string]schema.Attribute{
@@ -123,7 +123,7 @@ func (r *DeploymentResource) Create(ctx context.Context, req resource.CreateRequ
// Our API's create endpoint only accepts the source type, so we need to send two requests:
// one to create the bare-bones deployment, then one to update it with the rest of the data
- payloadBytes, err := json.Marshal(map[string]any{"source": data.Source.Name.ValueString()})
+ payloadBytes, err := json.Marshal(map[string]any{"source": data.Source.Type.ValueString()})
if err != nil {
resp.Diagnostics.AddError("Unable to Create Deployment", err.Error())
return
diff --git a/internal/provider/models/deployment_api_model.go b/internal/provider/models/deployment_api_model.go
index c76c53d..5a90c87 100644
--- a/internal/provider/models/deployment_api_model.go
+++ b/internal/provider/models/deployment_api_model.go
@@ -15,7 +15,7 @@ type DeploymentAPIModel struct {
}
type SourceAPIModel struct {
- Name string `json:"name"`
+ Type string `json:"name"`
Config SourceConfigAPIModel `json:"config"`
Tables []TableAPIModel `json:"tables"`
}
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index a656c5c..00800f7 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -13,7 +13,7 @@ type DeploymentResourceModel struct {
}
type SourceModel struct {
- Name types.String `tfsdk:"name"`
+ Type types.String `tfsdk:"type"`
PostgresConfig PostgresConfigModel `tfsdk:"postgres_config"`
Tables []TableModel `tfsdk:"tables"`
}
diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go
index e552a59..3ce7fa6 100644
--- a/internal/provider/models/translate_deployment.go
+++ b/internal/provider/models/translate_deployment.go
@@ -24,7 +24,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
})
}
resourceModel.Source = &SourceModel{
- Name: types.StringValue(apiModel.Source.Name),
+ Type: types.StringValue(apiModel.Source.Type),
PostgresConfig: PostgresConfigModel{
Host: types.StringValue(apiModel.Source.Config.Host),
Port: types.Int64Value(apiModel.Source.Config.Port),
@@ -70,7 +70,7 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
Status: resourceModel.Status.ValueString(),
DestinationUUID: resourceModel.DestinationUUID.ValueString(),
Source: SourceAPIModel{
- Name: resourceModel.Source.Name.ValueString(),
+ Type: resourceModel.Source.Type.ValueString(),
Config: SourceConfigAPIModel{
Host: resourceModel.Source.PostgresConfig.Host.ValueString(),
Port: resourceModel.Source.PostgresConfig.Port.ValueInt64(),
From a4bf3fbe29b293712add8acc318d6ae77f60fd6e Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 16:57:46 -0700
Subject: [PATCH 5/6] Add mysql config
---
docs/resources/deployment.md | 38 ++++++++++----
internal/provider/deployment_resource.go | 12 ++++-
.../models/deployment_resource_model.go | 15 ++++--
.../provider/models/translate_deployment.go | 52 ++++++++++++++-----
4 files changed, 89 insertions(+), 28 deletions(-)
diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md
index c5402a3..2da192f 100644
--- a/docs/resources/deployment.md
+++ b/docs/resources/deployment.md
@@ -51,21 +51,13 @@ Optional:
Required:
-- `postgres_config` (Attributes) (see [below for nested schema](#nestedatt--source--postgres_config))
- `tables` (Attributes List) (see [below for nested schema](#nestedatt--source--tables))
- `type` (String)
-
-### Nested Schema for `source.postgres_config`
-
-Required:
-
-- `database` (String)
-- `host` (String)
-- `password` (String, Sensitive)
-- `port` (Number)
-- `user` (String)
+Optional:
+- `mysql_config` (Attributes) (see [below for nested schema](#nestedatt--source--mysql_config))
+- `postgres_config` (Attributes) (see [below for nested schema](#nestedatt--source--postgres_config))
### Nested Schema for `source.tables`
@@ -84,3 +76,27 @@ Optional:
Read-Only:
- `uuid` (String)
+
+
+
+### Nested Schema for `source.mysql_config`
+
+Required:
+
+- `database` (String)
+- `host` (String)
+- `password` (String, Sensitive)
+- `port` (Number)
+- `user` (String)
+
+
+
+### Nested Schema for `source.postgres_config`
+
+Required:
+
+- `database` (String)
+- `host` (String)
+- `password` (String, Sensitive)
+- `port` (Number)
+- `user` (String)
diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go
index a658e60..8ce4dc6 100644
--- a/internal/provider/deployment_resource.go
+++ b/internal/provider/deployment_resource.go
@@ -52,7 +52,17 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{Required: true},
"postgres_config": schema.SingleNestedAttribute{
- Required: true,
+ Optional: true,
+ Attributes: map[string]schema.Attribute{
+ "host": schema.StringAttribute{Required: true},
+ "port": schema.Int64Attribute{Required: true},
+ "user": schema.StringAttribute{Required: true},
+ "password": schema.StringAttribute{Required: true, Sensitive: true},
+ "database": schema.StringAttribute{Required: true},
+ },
+ },
+ "mysql_config": schema.SingleNestedAttribute{
+ Optional: true,
Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{Required: true},
"port": schema.Int64Attribute{Required: true},
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index 00800f7..f5669cd 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -13,9 +13,10 @@ type DeploymentResourceModel struct {
}
type SourceModel struct {
- Type types.String `tfsdk:"type"`
- PostgresConfig PostgresConfigModel `tfsdk:"postgres_config"`
- Tables []TableModel `tfsdk:"tables"`
+ Type types.String `tfsdk:"type"`
+ Tables []TableModel `tfsdk:"tables"`
+ PostgresConfig *PostgresConfigModel `tfsdk:"postgres_config"`
+ MySQLConfig *MySQLConfigModel `tfsdk:"mysql_config"`
}
type PostgresConfigModel struct {
@@ -26,6 +27,14 @@ type PostgresConfigModel struct {
Password types.String `tfsdk:"password"`
}
+type MySQLConfigModel struct {
+ Host types.String `tfsdk:"host"`
+ Port types.Int64 `tfsdk:"port"`
+ User types.String `tfsdk:"user"`
+ Database types.String `tfsdk:"database"`
+ Password types.String `tfsdk:"password"`
+}
+
type TableModel struct {
UUID types.String `tfsdk:"uuid"`
Name types.String `tfsdk:"name"`
diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go
index 3ce7fa6..c898f83 100644
--- a/internal/provider/models/translate_deployment.go
+++ b/internal/provider/models/translate_deployment.go
@@ -24,16 +24,28 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
})
}
resourceModel.Source = &SourceModel{
- Type: types.StringValue(apiModel.Source.Type),
- PostgresConfig: PostgresConfigModel{
+ Type: types.StringValue(apiModel.Source.Type),
+ Tables: tables,
+ }
+ switch resourceModel.Source.Type.ValueString() {
+ case "PostgreSQL":
+ resourceModel.Source.PostgresConfig = &PostgresConfigModel{
Host: types.StringValue(apiModel.Source.Config.Host),
Port: types.Int64Value(apiModel.Source.Config.Port),
User: types.StringValue(apiModel.Source.Config.User),
Password: types.StringValue(apiModel.Source.Config.Password),
Database: types.StringValue(apiModel.Source.Config.Database),
- },
- Tables: tables,
+ }
+ case "MySQL":
+ resourceModel.Source.MySQLConfig = &MySQLConfigModel{
+ Host: types.StringValue(apiModel.Source.Config.Host),
+ Port: types.Int64Value(apiModel.Source.Config.Port),
+ User: types.StringValue(apiModel.Source.Config.User),
+ Password: types.StringValue(apiModel.Source.Config.Password),
+ Database: types.StringValue(apiModel.Source.Config.Database),
+ }
}
+
resourceModel.DestinationConfig = &DeploymentDestinationConfigModel{
Dataset: types.StringValue(apiModel.DestinationConfig.Dataset),
Database: types.StringValue(apiModel.DestinationConfig.Database),
@@ -63,21 +75,14 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
})
}
- return DeploymentAPIModel{
+ apiModel := DeploymentAPIModel{
UUID: resourceModel.UUID.ValueString(),
CompanyUUID: resourceModel.CompanyUUID.ValueString(),
Name: resourceModel.Name.ValueString(),
Status: resourceModel.Status.ValueString(),
DestinationUUID: resourceModel.DestinationUUID.ValueString(),
Source: SourceAPIModel{
- Type: resourceModel.Source.Type.ValueString(),
- Config: SourceConfigAPIModel{
- Host: resourceModel.Source.PostgresConfig.Host.ValueString(),
- Port: resourceModel.Source.PostgresConfig.Port.ValueInt64(),
- User: resourceModel.Source.PostgresConfig.User.ValueString(),
- Password: resourceModel.Source.PostgresConfig.Password.ValueString(),
- Database: resourceModel.Source.PostgresConfig.Database.ValueString(),
- },
+ Type: resourceModel.Source.Type.ValueString(),
Tables: tables,
},
DestinationConfig: DestinationConfigAPIModel{
@@ -91,4 +96,25 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
OptionalPrefix: resourceModel.DestinationConfig.OptionalPrefix.ValueString(),
},
}
+
+ switch resourceModel.Source.Type.ValueString() {
+ case "PostgreSQL":
+ apiModel.Source.Config = SourceConfigAPIModel{
+ Host: resourceModel.Source.PostgresConfig.Host.ValueString(),
+ Port: resourceModel.Source.PostgresConfig.Port.ValueInt64(),
+ User: resourceModel.Source.PostgresConfig.User.ValueString(),
+ Password: resourceModel.Source.PostgresConfig.Password.ValueString(),
+ Database: resourceModel.Source.PostgresConfig.Database.ValueString(),
+ }
+ case "MySQL":
+ apiModel.Source.Config = SourceConfigAPIModel{
+ Host: resourceModel.Source.MySQLConfig.Host.ValueString(),
+ Port: resourceModel.Source.MySQLConfig.Port.ValueInt64(),
+ User: resourceModel.Source.MySQLConfig.User.ValueString(),
+ Password: resourceModel.Source.MySQLConfig.Password.ValueString(),
+ Database: resourceModel.Source.MySQLConfig.Database.ValueString(),
+ }
+ }
+
+ return apiModel
}
From cacbcda7a384a3b0e3cab92c29ace9ec6a56853a Mon Sep 17 00:00:00 2001
From: Dana Fallon <8871189+danafallon@users.noreply.github.com>
Date: Mon, 5 Aug 2024 17:05:18 -0700
Subject: [PATCH 6/6] Constantize source/destination types
---
.../provider/models/deployment_resource_model.go | 7 +++++++
.../provider/models/destination_resource_model.go | 8 ++++++++
internal/provider/models/translate_deployment.go | 8 ++++----
internal/provider/models/translate_destination.go | 12 ++++++------
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/internal/provider/models/deployment_resource_model.go b/internal/provider/models/deployment_resource_model.go
index f5669cd..cef060b 100644
--- a/internal/provider/models/deployment_resource_model.go
+++ b/internal/provider/models/deployment_resource_model.go
@@ -2,6 +2,13 @@ package models
import "github.com/hashicorp/terraform-plugin-framework/types"
+type SourceType string
+
+const (
+ PostgreSQL SourceType = "PostgreSQL"
+ MySQL SourceType = "MySQL"
+)
+
type DeploymentResourceModel struct {
UUID types.String `tfsdk:"uuid"`
CompanyUUID types.String `tfsdk:"company_uuid"`
diff --git a/internal/provider/models/destination_resource_model.go b/internal/provider/models/destination_resource_model.go
index b603688..b94889d 100644
--- a/internal/provider/models/destination_resource_model.go
+++ b/internal/provider/models/destination_resource_model.go
@@ -2,6 +2,14 @@ package models
import "github.com/hashicorp/terraform-plugin-framework/types"
+type DestinationType string
+
+const (
+ Snowflake DestinationType = "Snowflake"
+ BigQuery DestinationType = "BigQuery"
+ Redshift DestinationType = "Redshift"
+)
+
type DestinationResourceModel struct {
UUID types.String `tfsdk:"uuid"`
CompanyUUID types.String `tfsdk:"company_uuid"`
diff --git a/internal/provider/models/translate_deployment.go b/internal/provider/models/translate_deployment.go
index c898f83..30c45b9 100644
--- a/internal/provider/models/translate_deployment.go
+++ b/internal/provider/models/translate_deployment.go
@@ -28,7 +28,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
Tables: tables,
}
switch resourceModel.Source.Type.ValueString() {
- case "PostgreSQL":
+ case string(PostgreSQL):
resourceModel.Source.PostgresConfig = &PostgresConfigModel{
Host: types.StringValue(apiModel.Source.Config.Host),
Port: types.Int64Value(apiModel.Source.Config.Port),
@@ -36,7 +36,7 @@ func DeploymentAPIToResourceModel(apiModel DeploymentAPIModel, resourceModel *De
Password: types.StringValue(apiModel.Source.Config.Password),
Database: types.StringValue(apiModel.Source.Config.Database),
}
- case "MySQL":
+ case string(MySQL):
resourceModel.Source.MySQLConfig = &MySQLConfigModel{
Host: types.StringValue(apiModel.Source.Config.Host),
Port: types.Int64Value(apiModel.Source.Config.Port),
@@ -98,7 +98,7 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
}
switch resourceModel.Source.Type.ValueString() {
- case "PostgreSQL":
+ case string(PostgreSQL):
apiModel.Source.Config = SourceConfigAPIModel{
Host: resourceModel.Source.PostgresConfig.Host.ValueString(),
Port: resourceModel.Source.PostgresConfig.Port.ValueInt64(),
@@ -106,7 +106,7 @@ func DeploymentResourceToAPIModel(resourceModel DeploymentResourceModel) Deploym
Password: resourceModel.Source.PostgresConfig.Password.ValueString(),
Database: resourceModel.Source.PostgresConfig.Database.ValueString(),
}
- case "MySQL":
+ case string(MySQL):
apiModel.Source.Config = SourceConfigAPIModel{
Host: resourceModel.Source.MySQLConfig.Host.ValueString(),
Port: resourceModel.Source.MySQLConfig.Port.ValueInt64(),
diff --git a/internal/provider/models/translate_destination.go b/internal/provider/models/translate_destination.go
index 3fe7de4..e526b64 100644
--- a/internal/provider/models/translate_destination.go
+++ b/internal/provider/models/translate_destination.go
@@ -13,7 +13,7 @@ func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *
resourceModel.SSHTunnelUUID = types.StringValue(apiModel.SSHTunnelUUID)
switch resourceModel.Type.ValueString() {
- case "Snowflake":
+ case string(Snowflake):
resourceModel.SnowflakeConfig = &SnowflakeSharedConfigModel{
AccountURL: types.StringValue(apiModel.Config.SnowflakeAccountURL),
VirtualDWH: types.StringValue(apiModel.Config.SnowflakeVirtualDWH),
@@ -21,13 +21,13 @@ func DestinationAPIToResourceModel(apiModel DestinationAPIModel, resourceModel *
Username: types.StringValue(apiModel.Config.Username),
Password: types.StringValue(apiModel.Config.Password),
}
- case "BigQuery":
+ case string(BigQuery):
resourceModel.BigQueryConfig = &BigQuerySharedConfigModel{
ProjectID: types.StringValue(apiModel.Config.GCPProjectID),
Location: types.StringValue(apiModel.Config.GCPLocation),
CredentialsData: types.StringValue(apiModel.Config.GCPCredentialsData),
}
- case "Redshift":
+ case string(Redshift):
resourceModel.RedshiftConfig = &RedshiftSharedConfigModel{
Endpoint: types.StringValue(apiModel.Config.Endpoint),
Host: types.StringValue(apiModel.Config.Host),
@@ -52,7 +52,7 @@ func DestinationResourceToAPIModel(resourceModel DestinationResourceModel) Desti
}
switch resourceModel.Type.ValueString() {
- case "Snowflake":
+ case string(Snowflake):
apiModel.Config = DestinationSharedConfigAPIModel{
SnowflakeAccountURL: resourceModel.SnowflakeConfig.AccountURL.ValueString(),
SnowflakeVirtualDWH: resourceModel.SnowflakeConfig.VirtualDWH.ValueString(),
@@ -60,13 +60,13 @@ func DestinationResourceToAPIModel(resourceModel DestinationResourceModel) Desti
Username: resourceModel.SnowflakeConfig.Username.ValueString(),
Password: resourceModel.SnowflakeConfig.Password.ValueString(),
}
- case "BigQuery":
+ case string(BigQuery):
apiModel.Config = DestinationSharedConfigAPIModel{
GCPProjectID: resourceModel.BigQueryConfig.ProjectID.ValueString(),
GCPLocation: resourceModel.BigQueryConfig.Location.ValueString(),
GCPCredentialsData: resourceModel.BigQueryConfig.CredentialsData.ValueString(),
}
- case "Redshift":
+ case string(Redshift):
apiModel.Config = DestinationSharedConfigAPIModel{
Endpoint: resourceModel.RedshiftConfig.Endpoint.ValueString(),
Host: resourceModel.RedshiftConfig.Host.ValueString(),