rambleraptor commented on code in PR #8:
URL: https://github.com/apache/iceberg-terraform/pull/8#discussion_r2765805935


##########
internal/provider/provider.go:
##########
@@ -45,12 +64,93 @@ func (p *icebergProvider) Metadata(_ context.Context, _ 
provider.MetadataRequest
 func (p *icebergProvider) Schema(_ context.Context, _ provider.SchemaRequest, 
resp *provider.SchemaResponse) {
        resp.Schema = schema.Schema{
                Description: "Use OpenTofu to interact with Iceberg REST 
Catalog instances.",
+               Attributes: map[string]schema.Attribute{
+                       "catalog_uri": schema.StringAttribute{
+                               Description: "The URI of the Iceberg REST 
catalog.",
+                               Required:    true,
+                       },
+                       "token": schema.StringAttribute{
+                               Description: "The token to use for 
authentication.",
+                               Optional:    true,
+                               Sensitive:   true,
+                       },
+                       "warehouse": schema.StringAttribute{
+                               Description: "The warehouse to use for the 
Iceberg REST catalog. This will be passed as `warehouse` property in the 
catalog properties.",
+                               Optional:    true,
+                       },
+                       "headers": schema.MapAttribute{
+                               Description: "The headers to use for 
authentication.",
+                               Optional:    true,
+                               Sensitive:   true,
+                               ElementType: types.StringType,
+                       },
+               },
        }
 }
 
 // Configure prepares a Iceberg API client for data sources and resources.
 func (p *icebergProvider) Configure(ctx context.Context, req 
provider.ConfigureRequest, resp *provider.ConfigureResponse) {
-       // Provider schema is empty, so no configuration to retrieve.
+       var data icebergProviderModel
+
+       diags := req.Config.Get(ctx, &data)
+       resp.Diagnostics.Append(diags...)
+
+       if resp.Diagnostics.HasError() {
+               return
+       }
+
+       if data.CatalogURI.IsUnknown() {
+               return
+       }
+
+       p.catalogURI = data.CatalogURI.ValueString()
+
+       if !data.Token.IsNull() && !data.Token.IsUnknown() {
+               p.token = data.Token.ValueString()
+       }
+
+       if !data.Warehouse.IsNull() && !data.Warehouse.IsUnknown() {
+               p.warehouse = data.Warehouse.ValueString()
+       }
+
+       if !data.Headers.IsNull() && !data.Headers.IsUnknown() {
+               headers := make(map[string]string)
+               resp.Diagnostics.Append(data.Headers.ElementsAs(ctx, &headers, 
false)...)
+               if resp.Diagnostics.HasError() {
+                       return
+               }
+
+               p.headers = headers
+       }
+
+       resp.DataSourceData = p
+       resp.ResourceData = p

Review Comment:
   (This is boilerplate as I'm sure you're aware).
   
   Terraform providers have two different things:
   
   - Resources: what we're building. They do basic CRUD operations, they 
represent things being created. 
   - DataSources: read-only representations of resources. These are used to 
fetch information that's injected into your Terraform script.
   
   Here's a (contrived) example: we could have a token datasource that fetches 
an OAuth Token, which is then used in our Terraform resources to authenticate 
and create our namespaces.



-- 
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]

Reply via email to