From 8109b5ac144d1c291c52ef330ab893f7a6e893c7 Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:20:39 -0700 Subject: [PATCH] Validate source and destination types (#55) --- go.mod | 1 + go.sum | 2 ++ internal/provider/deployment_resource.go | 12 +++++++++++- internal/provider/destination_resource.go | 15 +++++++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d8cb49f..6068fec 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/google/uuid v1.6.0 github.com/hashicorp/terraform-plugin-docs v0.19.4 github.com/hashicorp/terraform-plugin-framework v1.11.0 + github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 github.com/hashicorp/terraform-plugin-log v0.9.0 ) diff --git a/go.sum b/go.sum index 137b895..3d64f20 100644 --- a/go.sum +++ b/go.sum @@ -85,6 +85,8 @@ github.com/hashicorp/terraform-plugin-docs v0.19.4 h1:G3Bgo7J22OMtegIgn8Cd/CaSey github.com/hashicorp/terraform-plugin-docs v0.19.4/go.mod h1:4pLASsatTmRynVzsjEhbXZ6s7xBlUw/2Kt0zfrq8HxA= github.com/hashicorp/terraform-plugin-framework v1.11.0 h1:M7+9zBArexHFXDx/pKTxjE6n/2UCXY6b8FIq9ZYhwfE= github.com/hashicorp/terraform-plugin-framework v1.11.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= diff --git a/internal/provider/deployment_resource.go b/internal/provider/deployment_resource.go index 973f240..2dbf13e 100644 --- a/internal/provider/deployment_resource.go +++ b/internal/provider/deployment_resource.go @@ -7,6 +7,7 @@ import ( "terraform-provider-artie/internal/artieclient" "terraform-provider-artie/internal/provider/models" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -15,6 +16,7 @@ import ( "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" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -48,7 +50,15 @@ func (r *DeploymentResource) Schema(ctx context.Context, req resource.SchemaRequ "source": schema.SingleNestedAttribute{ Required: true, Attributes: map[string]schema.Attribute{ - "type": schema.StringAttribute{Required: true}, + "type": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf( + string(models.MySQL), + string(models.PostgreSQL), + ), + }, + }, "postgres_config": schema.SingleNestedAttribute{ Optional: true, Attributes: map[string]schema.Attribute{ diff --git a/internal/provider/destination_resource.go b/internal/provider/destination_resource.go index 2b0a857..149b418 100644 --- a/internal/provider/destination_resource.go +++ b/internal/provider/destination_resource.go @@ -7,12 +7,14 @@ import ( "terraform-provider-artie/internal/artieclient" "terraform-provider-artie/internal/provider/models" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "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/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -39,8 +41,17 @@ func (r *DestinationResource) Schema(ctx context.Context, req resource.SchemaReq Attributes: map[string]schema.Attribute{ "uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}}, "ssh_tunnel_uuid": schema.StringAttribute{Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}}, - "type": schema.StringAttribute{Required: true}, - "label": schema.StringAttribute{Optional: true}, + "type": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf( + string(models.BigQuery), + string(models.Redshift), + string(models.Snowflake), + ), + }, + }, + "label": schema.StringAttribute{Optional: true}, "snowflake_config": schema.SingleNestedAttribute{ Optional: true, Attributes: map[string]schema.Attribute{