From 6e51e565708b35db43d9535889331706af918f93 Mon Sep 17 00:00:00 2001 From: mouuii <49775493+mouuii@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:04:00 +0800 Subject: [PATCH] terraform provider 03 --- internal/provider/provider.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ceb834a..c9d2676 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -3,6 +3,7 @@ package provider import ( "context" "github.com/hashicorp-demoapp/hashicups-client-go" + "github.com/hashicorp/terraform-plugin-log/tflog" "os" "github.com/hashicorp/terraform-plugin-framework/datasource" @@ -60,6 +61,7 @@ func (p *hashicupsProvider) Schema(_ context.Context, _ provider.SchemaRequest, } func (p *hashicupsProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { + tflog.Info(ctx, "Configuring HashiCups client") // Retrieve provider data from configuration var config hashicupsProviderModel diags := req.Config.Get(ctx, &config) @@ -157,7 +159,12 @@ func (p *hashicupsProvider) Configure(ctx context.Context, req provider.Configur if resp.Diagnostics.HasError() { return } + ctx = tflog.SetField(ctx, "hashicups_host", host) + ctx = tflog.SetField(ctx, "hashicups_username", username) + ctx = tflog.SetField(ctx, "hashicups_password", password) + ctx = tflog.MaskFieldValuesWithFieldKeys(ctx, "hashicups_password") + tflog.Debug(ctx, "Creating HashiCups client") // Create a new HashiCups client using the configuration values client, err := hashicups.NewClient(&host, &username, &password) if err != nil { @@ -174,6 +181,7 @@ func (p *hashicupsProvider) Configure(ctx context.Context, req provider.Configur // type Configure methods. resp.DataSourceData = client resp.ResourceData = client + tflog.Info(ctx, "Configured HashiCups client", map[string]any{"success": true}) } // DataSources defines the data sources implemented in the provider.