rambleraptor commented on code in PR #10: URL: https://github.com/apache/iceberg-terraform/pull/10#discussion_r2766419530
########## internal/provider/resource_table.go: ########## @@ -0,0 +1,419 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package provider + +import ( + "context" + "errors" + "strings" + + "github.com/apache/iceberg-go" + "github.com/apache/iceberg-go/catalog" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + rscschema "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/objectplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +var ( + _ resource.Resource = &icebergTableResource{} +) + +func NewTableResource() resource.Resource { + return &icebergTableResource{} +} + + +type icebergTableResourceModel struct { + ID types.String `tfsdk:"id"` + Namespace types.List `tfsdk:"namespace"` + Name types.String `tfsdk:"name"` + Schema types.Object `tfsdk:"schema"` + FullProperties types.Map `tfsdk:"full_properties"` +} + +type icebergTableResource struct { + catalog catalog.Catalog + provider *icebergProvider +} + +func (r *icebergTableResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_table" +} + +func (r *icebergTableResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = rscschema.Schema{ + Description: "A resource for managing Iceberg tables.", + Attributes: map[string]rscschema.Attribute{ + "id": rscschema.StringAttribute{ + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "namespace": rscschema.ListAttribute{ + Description: "The namespace of the table.", + Required: true, + ElementType: types.StringType, + }, + "name": rscschema.StringAttribute{ + Description: "The name of the table.", + Required: true, + }, + "schema": rscschema.SingleNestedAttribute{ + Description: "The schema of the table.", + Required: true, + // TODO: Update schema in place instead of replacement + PlanModifiers: []planmodifier.Object{ + objectplanmodifier.RequiresReplace(), + }, + Attributes: map[string]rscschema.Attribute{ + "id": rscschema.Int64Attribute{ + Description: "The schema ID.", + Required: true, + }, + "fields": rscschema.ListNestedAttribute{ + Description: "The fields of the schema.", + Required: true, + NestedObject: rscschema.NestedAttributeObject{ + Attributes: map[string]rscschema.Attribute{ + "id": rscschema.Int64Attribute{ + Description: "The field ID.", + Required: true, + }, + "name": rscschema.StringAttribute{ + Description: "The field name.", + Required: true, + }, + "type": rscschema.SingleNestedAttribute{ + Description: "The field type.", + Required: true, + Attributes: map[string]rscschema.Attribute{ + "primitive": rscschema.StringAttribute{ Review Comment: So, here's what I settled on. We've got a type field that's a string. We've also got fields like `decimal_properties`, `map_properties` for more complex types. If you set `type = decimal`, that's the only way you're allowed to set decimal_properties. That way, we still get full type validation on the decimal properties. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
