4
4
"fmt"
5
5
6
6
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7
- "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
8
7
9
8
"sigs.k8s.io/kustomize/api/filesys"
10
9
)
@@ -18,14 +17,17 @@ func dataSourceKustomization() *schema.Resource {
18
17
Type : schema .TypeString ,
19
18
Required : true ,
20
19
},
21
- "load_restrictor " : & schema.Schema {
22
- Type : schema .TypeString ,
20
+ "kustomize_options " : & schema.Schema {
21
+ Type : schema .TypeMap ,
23
22
Optional : true ,
24
- Default : "" ,
25
- ValidateFunc : validation .StringInSlice (
26
- []string {"none" , "" },
27
- false ,
28
- ),
23
+ Elem : & schema.Resource {
24
+ Schema : map [string ]* schema.Schema {
25
+ "load_restrictor" : {
26
+ Type : schema .TypeString ,
27
+ Optional : true ,
28
+ },
29
+ },
30
+ },
29
31
},
30
32
"ids" : & schema.Schema {
31
33
Type : schema .TypeSet ,
@@ -52,17 +54,39 @@ func dataSourceKustomization() *schema.Resource {
52
54
}
53
55
}
54
56
57
+ type kustomizeOptions struct {
58
+ loadRestrictor string
59
+ }
60
+
61
+ func getKustomizeOptions (d * schema.ResourceData ) (k kustomizeOptions ) {
62
+ // initialize kustomizeOptions with defaults
63
+ k = kustomizeOptions {
64
+ loadRestrictor : "" ,
65
+ }
66
+
67
+ kOpts := d .Get ("kustomize_options" ).(map [string ]interface {})
68
+
69
+ if kOpts ["load_restrictor" ] != nil {
70
+ if kOpts ["load_restrictor" ].(string ) == "none" {
71
+ k .loadRestrictor = "none"
72
+ }
73
+ }
74
+
75
+ return k
76
+ }
77
+
55
78
func kustomizationBuild (d * schema.ResourceData , m interface {}) error {
56
79
path := d .Get ("path" ).(string )
57
- load_restrictor := d .Get ("load_restrictor" ).(string )
80
+
81
+ kOpts := getKustomizeOptions (d )
58
82
59
83
fSys := filesys .MakeFsOnDisk ()
60
84
61
85
// mutex as tmp workaround for upstream bug
62
86
// https://github.com/kubernetes-sigs/kustomize/issues/3659
63
87
mu := m .(* Config ).Mutex
64
88
mu .Lock ()
65
- rm , err := runKustomizeBuild (fSys , path , load_restrictor )
89
+ rm , err := runKustomizeBuild (fSys , path , kOpts . loadRestrictor )
66
90
mu .Unlock ()
67
91
if err != nil {
68
92
return fmt .Errorf ("kustomizationBuild: %s" , err )
0 commit comments