@@ -15,12 +15,16 @@ func Provider() *schema.Provider {
1515 return & schema.Provider {
1616 Schema : map [string ]* schema.Schema {
1717 "access_key" : {
18- Type : schema .TypeString ,
19- Required : true ,
18+ Type : schema .TypeString ,
19+ Optional : true ,
20+ DefaultFunc : schema .EnvDefaultFunc ("IIS_ACCESS_KEY" , nil ),
21+ Description : "The access key for IIS authentication. Can also be sourced from the IIS_ACCESS_KEY environment variable." ,
2022 },
2123 "host" : {
22- Type : schema .TypeString ,
23- Required : true ,
24+ Type : schema .TypeString ,
25+ Optional : true ,
26+ DefaultFunc : schema .EnvDefaultFunc ("IIS_HOST" , nil ),
27+ Description : "The IIS host URL. Can also be sourced from the IIS_HOST environment variable." ,
2428 },
2529 },
2630 ResourcesMap : map [string ]* schema.Resource {
@@ -38,6 +42,30 @@ func Provider() *schema.Provider {
3842}
3943
4044func providerConfigure (ctx context.Context , d * schema.ResourceData ) (interface {}, diag.Diagnostics ) {
45+ var diags diag.Diagnostics
46+
47+ host := d .Get ("host" ).(string )
48+ if host == "" {
49+ diags = append (diags , diag.Diagnostic {
50+ Severity : diag .Error ,
51+ Summary : "Missing IIS Host" ,
52+ Detail : "The IIS host must be configured via the 'host' argument or IIS_HOST environment variable." ,
53+ })
54+ }
55+
56+ accessKey := d .Get ("access_key" ).(string )
57+ if accessKey == "" {
58+ diags = append (diags , diag.Diagnostic {
59+ Severity : diag .Error ,
60+ Summary : "Missing IIS Access Key" ,
61+ Detail : "The IIS access key must be configured via the 'access_key' argument or IIS_ACCESS_KEY environment variable." ,
62+ })
63+ }
64+
65+ if diags .HasError () {
66+ return nil , diags
67+ }
68+
4169 transport := & http.Transport {
4270 TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
4371 }
@@ -46,8 +74,8 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
4674 HttpClient : http.Client {
4775 Transport : loggingTransport ,
4876 },
49- Host : d . Get ( " host" ).( string ) ,
50- AccessKey : d . Get ( "access_key" ).( string ) ,
77+ Host : host ,
78+ AccessKey : accessKey ,
5179 }
5280
5381 return client , nil
0 commit comments