@@ -55,14 +55,16 @@ func resourceCluster() *schema.Resource {
55
55
Schema : kindConfigFields (),
56
56
},
57
57
},
58
- "kubeconfig " : {
58
+ "kubeconfig_path " : {
59
59
Type : schema .TypeString ,
60
- Description : `Kubeconfig set after the the cluster is created.` ,
60
+ Description : `Kubeconfig path set after the the cluster is created or by the user to override defaults.` ,
61
+ ForceNew : true ,
62
+ Optional : true ,
61
63
Computed : true ,
62
64
},
63
- "kubeconfig_path " : {
65
+ "kubeconfig " : {
64
66
Type : schema .TypeString ,
65
- Description : `Kubeconfig path set after the the cluster is created.` ,
67
+ Description : `Kubeconfig set after the the cluster is created.` ,
66
68
Computed : true ,
67
69
},
68
70
"client_certificate" : {
@@ -95,9 +97,17 @@ func resourceKindClusterCreate(d *schema.ResourceData, meta interface{}) error {
95
97
nodeImage := d .Get ("node_image" ).(string )
96
98
config := d .Get ("kind_config" )
97
99
waitForReady := d .Get ("wait_for_ready" ).(bool )
100
+ kubeconfigPath := d .Get ("kubeconfig_path" )
98
101
99
102
var copts []cluster.CreateOption
100
103
104
+ if kubeconfigPath != nil {
105
+ path := kubeconfigPath .(string )
106
+ if path != "" {
107
+ copts = append (copts , cluster .CreateWithKubeconfigPath (path ))
108
+ }
109
+ }
110
+
101
111
if config != nil {
102
112
cfg := config .([]interface {})
103
113
if len (cfg ) == 1 { // there is always just one kind_config allowed
@@ -147,13 +157,16 @@ func resourceKindClusterRead(d *schema.ResourceData, meta interface{}) error {
147
157
d .SetId ("" )
148
158
return err
149
159
}
150
- exportPath := fmt .Sprintf ("%s%s%s-config" , currentPath , string (os .PathSeparator ), name )
151
- err = provider .ExportKubeConfig (name , exportPath )
152
- if err != nil {
153
- d .SetId ("" )
154
- return err
160
+
161
+ if _ , ok := d .GetOkExists ("kubeconfig_path" ); ! ok {
162
+ exportPath := fmt .Sprintf ("%s%s%s-config" , currentPath , string (os .PathSeparator ), name )
163
+ err = provider .ExportKubeConfig (name , exportPath )
164
+ if err != nil {
165
+ d .SetId ("" )
166
+ return err
167
+ }
168
+ d .Set ("kubeconfig_path" , exportPath )
155
169
}
156
- d .Set ("kubeconfig_path" , exportPath )
157
170
158
171
// use the current context in kubeconfig
159
172
config , err := clientcmd .RESTConfigFromKubeConfig ([]byte (kconfig ))
@@ -185,6 +198,10 @@ func resourceKindClusterUpdate(d *schema.ResourceData, meta interface{}) error {
185
198
d .SetPartial ("kind_config" )
186
199
}
187
200
201
+ if d .HasChange ("kubeconfig_path" ) {
202
+ d .SetPartial ("kubeconfig_path" )
203
+ }
204
+
188
205
d .Partial (false )
189
206
return resourceKindClusterRead (d , meta )
190
207
}
0 commit comments