This repository has been archived by the owner on Aug 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_source_opentelekomcloud_rts_stack_v1.go
121 lines (108 loc) · 2.97 KB
/
data_source_opentelekomcloud_rts_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package opentelekomcloud
import (
"fmt"
"log"
"reflect"
"unsafe"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/rts/v1/stacks"
"github.com/huaweicloud/golangsdk/openstack/rts/v1/stacktemplates"
)
func dataSourceRTSStackV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceRTSStackV1Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"status_reason": {
Type: schema.TypeString,
Computed: true,
},
"outputs": {
Type: schema.TypeMap,
Computed: true,
},
"parameters": {
Type: schema.TypeMap,
Computed: true,
},
"timeout_mins": {
Type: schema.TypeInt,
Computed: true,
},
"disable_rollback": {
Type: schema.TypeBool,
Computed: true,
},
"capabilities": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"notification_topics": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"template_body": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceRTSStackV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
orchestrationClient, err := config.orchestrationV1Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating OpenTelekomCloud rts client: %s", err)
}
stackName := d.Get("name").(string)
stack, err := stacks.Get(orchestrationClient, stackName).Extract()
if err != nil {
return fmt.Errorf("Unable to retrieve stack %s: %s", stackName, err)
}
log.Printf("[INFO] Retrieved Stack %s", stackName)
d.SetId(stack.ID)
d.Set("disable_rollback", stack.DisableRollback)
d.Set("parameters", stack.Parameters)
d.Set("status_reason", stack.StatusReason)
d.Set("name", stack.Name)
d.Set("outputs", flattenStackOutputs(stack.Outputs))
d.Set("capabilities", stack.Capabilities)
d.Set("notification_topics", stack.NotificationTopics)
d.Set("timeout_mins", stack.Timeout)
d.Set("status", stack.Status)
d.Set("region", GetRegion(d, config))
out, err := stacktemplates.Get(orchestrationClient, stack.Name, stack.ID).Extract()
if err != nil {
return err
}
sTemplate := BytesToString(out)
template, error := normalizeStackTemplate(sTemplate)
if error != nil {
return errwrap.Wrapf("template body contains an invalid JSON or YAML: {{err}}", err)
}
d.Set("template_body", template)
return nil
}
func BytesToString(b []byte) string {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := reflect.StringHeader{Data: bh.Data, Len: bh.Len}
return *(*string)(unsafe.Pointer(&sh))
}