-
Notifications
You must be signed in to change notification settings - Fork 1
/
orchestration_stack_v1.go
91 lines (81 loc) · 2.42 KB
/
orchestration_stack_v1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package viettelidc
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/orchestration/v1/stacks"
)
func buildTE(t map[string]interface{}) (*stacks.TE, error) {
log.Printf("[DEBUG] Start to build TE structure")
te := &stacks.TE{}
if t["Bin"] != nil {
if v, ok := t["Bin"].(string); ok {
te.Bin = []byte(v)
} else {
return nil, fmt.Errorf("Bin value is expected to be a string")
}
}
if t["URL"] != nil {
if v, ok := t["URL"].(string); ok {
te.URL = v
} else {
return nil, fmt.Errorf("URL value is expected to be a string")
}
}
if t["Files"] != nil {
if v, ok := t["Files"].(map[string]string); ok {
te.Files = v
} else {
return nil, fmt.Errorf("URL value is expected to be a map of string")
}
}
log.Printf("[DEBUG] TE structure builded")
return te, nil
}
func buildTemplateOpts(d *schema.ResourceData) (*stacks.Template, error) {
log.Printf("[DEBUG] Start building TemplateOpts")
te, err := buildTE(d.Get("template_opts").(map[string]interface{}))
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Return TemplateOpts")
return &stacks.Template{
TE: *te,
}, nil
}
func buildEnvironmentOpts(d *schema.ResourceData) (*stacks.Environment, error) {
log.Printf("[DEBUG] Start building EnvironmentOpts")
if d.Get("environment_opts") != nil {
t := d.Get("environment_opts").(map[string]interface{})
te, err := buildTE(t)
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Return EnvironmentOpts")
return &stacks.Environment{
TE: *te,
}, nil
}
return nil, nil
}
func orchestrationStackV1StateRefreshFunc(client *gophercloud.ServiceClient, stackID string, isdelete bool) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
log.Printf("[DEBUG] Refresh Stack status %s", stackID)
stack, err := stacks.Find(client, stackID).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok && isdelete {
return stack, "DELETE_COMPLETE", nil
}
return nil, "", err
}
if strings.Contains(stack.Status, "FAILED") {
return stack, stack.Status, fmt.Errorf("The stack is in error status. " +
"Please check with your cloud admin or check the orchestration " +
"API logs to see why this error occurred.")
}
return stack, stack.Status, nil
}
}