@@ -23,11 +23,27 @@ func resourcePortainerStack() *schema.Resource {
2323 Importer : & schema.ResourceImporter {
2424 State : func (d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
2525 // "<endpoint_id>-<stack_id>-<deployment_type>"
26- var endpointID , stackID int
27- var deploymentType string
28- _ , err := fmt .Sscanf (d .Id (), "%d-%d-%s" , & endpointID , & stackID , & deploymentType )
26+ // "<endpoint_id>-<stack_id>-<deployment_type>-<method>"
27+
28+ parts := strings .Split (d .Id (), "-" )
29+ if len (parts ) < 3 {
30+ return nil , fmt .Errorf ("invalid ID format. Use '<endpoint_id>-<stack_id>-<deployment_type>[-<method>]'" )
31+ }
32+
33+ endpointID , err := strconv .Atoi (parts [0 ])
2934 if err != nil {
30- return nil , fmt .Errorf ("invalid ID format. Use '<endpoint_id>-<stack_id>-<deployment_type>'" )
35+ return nil , fmt .Errorf ("invalid endpoint_id in import ID: %s" , parts [0 ])
36+ }
37+
38+ stackID , err := strconv .Atoi (parts [1 ])
39+ if err != nil {
40+ return nil , fmt .Errorf ("invalid stack_id in import ID: %s" , parts [1 ])
41+ }
42+
43+ deploymentType := parts [2 ]
44+
45+ if len (parts ) > 3 {
46+ d .Set ("method" , parts [3 ])
3147 }
3248 d .Set ("endpoint_id" , endpointID )
3349 d .Set ("deployment_type" , deploymentType )
@@ -125,7 +141,7 @@ func resourcePortainerStack() *schema.Resource {
125141 },
126142 },
127143 },
128- "tlsskip_verify" : {Type : schema .TypeBool , Optional : true , Default : false , ForceNew : true },
144+ "tlsskip_verify" : {Type : schema .TypeBool , Optional : true , Computed : true , ForceNew : true },
129145 "prune" : {
130146 Type : schema .TypeBool ,
131147 Optional : true ,
@@ -334,12 +350,21 @@ func resourcePortainerStackRead(d *schema.ResourceData, meta interface{}) error
334350 EndpointID int `json:"EndpointId"`
335351 SupportRelativePath bool `json:"supportRelativePath"`
336352 AutoUpdate * struct {
337- Webhook string `json:"webhook"`
353+ Webhook string `json:"webhook"`
354+ ForcePullImage bool `json:"forcePullImage"`
338355 } `json:"AutoUpdate,omitempty"`
339356 Env []struct {
340357 Name string `json:"name"`
341358 Value string `json:"value"`
342359 } `json:"Env"`
360+
361+ Option struct {
362+ Prune bool `json:"prune"`
363+ } `json:"Option"`
364+
365+ GitConfig * struct {
366+ TLSSkipVerify bool `json:"tlsskipVerify"`
367+ } `json:"gitConfig,omitempty"`
343368 }
344369 if err := json .NewDecoder (resp .Body ).Decode (& stack ); err != nil {
345370 return fmt .Errorf ("failed to decode stack response: %w" , err )
@@ -392,12 +417,15 @@ func resourcePortainerStackRead(d *schema.ResourceData, meta interface{}) error
392417 }
393418 d .Set ("env" , tfEnvs )
394419 _ = d .Set ("method" , method )
395- _ = d .Set ("endpoint_id" , client . Endpoint )
420+ _ = d .Set ("endpoint_id" , stack . EndpointID )
396421 _ = d .Set ("stack_webhook" , stack .AutoUpdate != nil && stack .AutoUpdate .Webhook != "" )
397422 _ = d .Set ("support_relative_path" , stack .SupportRelativePath )
398- _ = d .Set ("prune" , false )
399- _ = d .Set ("pull_image" , false )
400- _ = d .Set ("tlsskip_verify" , false )
423+ if method == "repository" && stack .GitConfig != nil {
424+ _ = d .Set ("tlsskip_verify" , stack .GitConfig .TLSSkipVerify )
425+ }
426+ if stack .AutoUpdate != nil {
427+ _ = d .Set ("pull_image" , stack .AutoUpdate .ForcePullImage )
428+ }
401429
402430 return nil
403431}
0 commit comments