forked from huaweicloud/terraform-provider-huaweicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_huaweicloud_rts_software_config_v1.go
88 lines (77 loc) · 2.13 KB
/
data_source_huaweicloud_rts_software_config_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
package huaweicloud
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/rts/v1/softwareconfig"
)
func dataSourceRtsSoftwareConfigV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceRtsSoftwareConfigV1Read,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"group": {
Type: schema.TypeString,
Computed: true,
},
"input_values": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeMap},
},
"output_values": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeMap},
},
"config": {
Type: schema.TypeString,
Computed: true,
},
"options": {
Type: schema.TypeMap,
Computed: true,
},
},
}
}
func dataSourceRtsSoftwareConfigV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
orchestrationClient, err := config.orchestrationV1Client(GetRegion(d, config))
n, err := softwareconfig.Get(orchestrationClient, d.Get("id").(string)).Extract()
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving HuaweiCloud RTS Config: %s", err)
}
log.Printf("[INFO] Retrieved RTS Software Config using given id %s", n.Id)
d.SetId(n.Id)
d.Set("name", n.Name)
d.Set("group", n.Group)
d.Set("region", GetRegion(d, config))
d.Set("config", n.Config)
d.Set("options", n.Options)
if err := d.Set("input_values", n.Inputs); err != nil {
return fmt.Errorf("[DEBUG] Error saving inputs to state for HuaweiCloud RTS Software Config (%s): %s", d.Id(), err)
}
if err := d.Set("output_values", n.Outputs); err != nil {
return fmt.Errorf("[DEBUG] Error saving outputs to state for HuaweiCloud RTS Software Config (%s): %s", d.Id(), err)
}
return nil
}