Skip to content

Commit

Permalink
terraform provider 03
Browse files Browse the repository at this point in the history
  • Loading branch information
mouuii committed Nov 30, 2023
1 parent 6e75c6d commit 6e51e56
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down

0 comments on commit 6e51e56

Please sign in to comment.