Skip to content

Commit 9dd4291

Browse files
authored
fix:types (#9)
1 parent 23f1d23 commit 9dd4291

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

internal/provider/provider.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
1212
"github.com/hashicorp/terraform-plugin-framework/resource"
1313
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
14+
"github.com/hashicorp/terraform-plugin-framework/types"
1415
"github.com/knowledge-work/terraform-provider-kw-github/internal/githubclient"
1516
)
1617

@@ -72,13 +73,13 @@ func (p *kwgithubProvider) Schema(_ context.Context, _ provider.SchemaRequest, r
7273

7374
func (p *kwgithubProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
7475
var config struct {
75-
Token string `tfsdk:"token"`
76-
Owner string `tfsdk:"owner"`
77-
GithubBaseURL string `tfsdk:"github_base_url"`
76+
Token types.String `tfsdk:"token"`
77+
Owner types.String `tfsdk:"owner"`
78+
GithubBaseURL types.String `tfsdk:"github_base_url"`
7879
AppAuth []struct {
79-
ID string `tfsdk:"id"`
80-
InstallationID string `tfsdk:"installation_id"`
81-
PemFile string `tfsdk:"pem_file"`
80+
ID types.String `tfsdk:"id"`
81+
InstallationID types.String `tfsdk:"installation_id"`
82+
PemFile types.String `tfsdk:"pem_file"`
8283
} `tfsdk:"app_auth"`
8384
}
8485

@@ -88,8 +89,8 @@ func (p *kwgithubProvider) Configure(ctx context.Context, req provider.Configure
8889
}
8990

9091
baseURL := "https://api.github.com"
91-
if config.GithubBaseURL != "" {
92-
baseURL = config.GithubBaseURL
92+
if !config.GithubBaseURL.IsNull() && !config.GithubBaseURL.IsUnknown() {
93+
baseURL = config.GithubBaseURL.ValueString()
9394
} else if envBaseURL := os.Getenv("GITHUB_BASE_URL"); envBaseURL != "" {
9495
baseURL = envBaseURL
9596
}
@@ -99,15 +100,24 @@ func (p *kwgithubProvider) Configure(ctx context.Context, req provider.Configure
99100

100101
if len(config.AppAuth) > 0 {
101102
appAuth := config.AppAuth[0]
102-
appID := appAuth.ID
103+
appID := ""
104+
if !appAuth.ID.IsNull() && !appAuth.ID.IsUnknown() {
105+
appID = appAuth.ID.ValueString()
106+
}
103107
if appID == "" {
104108
appID = os.Getenv("GITHUB_APP_ID")
105109
}
106-
installationID := appAuth.InstallationID
110+
installationID := ""
111+
if !appAuth.InstallationID.IsNull() && !appAuth.InstallationID.IsUnknown() {
112+
installationID = appAuth.InstallationID.ValueString()
113+
}
107114
if installationID == "" {
108115
installationID = os.Getenv("GITHUB_APP_INSTALLATION_ID")
109116
}
110-
pemFile := appAuth.PemFile
117+
pemFile := ""
118+
if !appAuth.PemFile.IsNull() && !appAuth.PemFile.IsUnknown() {
119+
pemFile = appAuth.PemFile.ValueString()
120+
}
111121
if pemFile == "" {
112122
pemFile = os.Getenv("GITHUB_APP_PEM_FILE")
113123
}
@@ -130,7 +140,9 @@ func (p *kwgithubProvider) Configure(ctx context.Context, req provider.Configure
130140
return
131141
}
132142
} else {
133-
token = config.Token
143+
if !config.Token.IsNull() && !config.Token.IsUnknown() {
144+
token = config.Token.ValueString()
145+
}
134146
if token == "" {
135147
token = os.Getenv("GITHUB_TOKEN")
136148
}

0 commit comments

Comments
 (0)