This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_source_flexibleengine_rts_software_config_v1.go
104 lines (89 loc) · 2.61 KB
/
data_source_flexibleengine_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package flexibleengine
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"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,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: 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))
listOpts := softwareconfig.ListOpts{
Id: d.Get("id").(string),
Name: d.Get("name").(string),
}
refinedConfigs, err := softwareconfig.List(orchestrationClient, listOpts)
if err != nil {
return fmt.Errorf("Unable to retrieve RTS Software Configs: %s", err)
}
if len(refinedConfigs) < 1 {
return fmt.Errorf("Your query returned no results. " +
"Please change your search criteria and try again.")
}
if len(refinedConfigs) > 1 {
return fmt.Errorf("Your query returned more than one result." +
" Please try a more specific search criteria")
}
Config := refinedConfigs[0]
log.Printf("[INFO] Retrieved RTS Software Config using given filter %s: %+v", Config.Id, Config)
d.SetId(Config.Id)
d.Set("name", Config.Name)
d.Set("group", Config.Group)
d.Set("region", GetRegion(d, config))
n, err := softwareconfig.Get(orchestrationClient, Config.Id).Extract()
if err != nil {
return fmt.Errorf("Unable to retrieve RTS Software Config: %s", err)
}
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 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 RTS Software Config (%s): %s", d.Id(), err)
}
return nil
}