File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package nextdns
2
2
3
3
import (
4
4
"context"
5
+ "os"
5
6
6
7
"github.com/amalucelli/nextdns-go/nextdns"
7
8
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -13,7 +14,7 @@ func Provider() *schema.Provider {
13
14
Schema : map [string ]* schema.Schema {
14
15
"api_key" : {
15
16
Type : schema .TypeString ,
16
- Required : true ,
17
+ Optional : true ,
17
18
Description : "NextDNS API Key" ,
18
19
},
19
20
},
@@ -37,8 +38,19 @@ func Provider() *schema.Provider {
37
38
38
39
// nolint:revive
39
40
func configure (ctx context.Context , d * schema.ResourceData ) (interface {}, diag.Diagnostics ) {
40
- client , err := nextdns .New (
41
- nextdns .WithAPIKey (d .Get ("api_key" ).(string )))
41
+ apiKey := os .Getenv ("NEXTDNS_API_KEY" )
42
+
43
+ if key , ok := d .Get ("api_key" ).(string ); ok && len (key ) > 0 {
44
+ apiKey = key
45
+ }
46
+
47
+ if len (apiKey ) == 0 {
48
+ return nil , diag .Errorf (
49
+ "NextDNS API key must be provided in the provider block or NEXTDNS_API_KEY environment variable." ,
50
+ )
51
+ }
52
+
53
+ client , err := nextdns .New (nextdns .WithAPIKey (apiKey ))
42
54
if err != nil {
43
55
return nil , diag .FromErr (err )
44
56
}
You can’t perform that action at this time.
0 commit comments