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_software_deployment_v1.go
96 lines (85 loc) · 2.43 KB
/
data_source_opentelekomcloud_rts_software_deployment_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
package opentelekomcloud
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk/openstack/rts/v1/softwaredeployment"
)
func dataSourceRtsSoftwareDeploymentV1() *schema.Resource {
return &schema.Resource{
Read: dataSourceRTSSoftwareDeploymentV1Read,
Schema: map[string]*schema.Schema{ //request and response parameters
"region": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"config_id": {
Type: schema.TypeString,
Optional: true,
},
"server_id": {
Type: schema.TypeString,
Optional: true,
},
"status": {
Type: schema.TypeString,
Optional: true,
},
"action": {
Type: schema.TypeString,
Optional: true,
},
"input_values": {
Type: schema.TypeMap,
Computed: true,
},
"status_reason": {
Type: schema.TypeString,
Computed: true,
},
"output_values": {
Type: schema.TypeMap,
Computed: true,
},
"id": {
Type: schema.TypeString,
Optional: true,
},
},
}
}
func dataSourceRTSSoftwareDeploymentV1Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
orchestrationClient, err := config.orchestrationV1Client(GetRegion(d, config))
listOpts := softwaredeployment.ListOpts{
Id: d.Id(),
ServerId: d.Get("server_id").(string),
ConfigId: d.Get("config_id").(string),
Action: d.Get("action").(string),
Status: d.Get("status").(string),
}
refinedDeployments, err := softwaredeployment.List(orchestrationClient, listOpts)
if err != nil {
return fmt.Errorf("Unable to retrieve RTS Software Deployment: %s", err)
}
if len(refinedDeployments) < 1 {
return fmt.Errorf("No matching resource found. " +
"Please change your search criteria and try again.")
}
if len(refinedDeployments) > 1 {
return fmt.Errorf("Multiple resources matched; use additional constraints to reduce matches to a single resource")
}
stackResource := refinedDeployments[0]
d.SetId(stackResource.Id)
d.Set("id", stackResource.Id)
d.Set("status", stackResource.Status)
d.Set("server_id", stackResource.ServerId)
d.Set("config_id", stackResource.ConfigId)
d.Set("status_reason", stackResource.StatusReason)
d.Set("action", stackResource.Action)
d.Set("output_values", stackResource.OutputValues)
d.Set("input_values", stackResource.InputValues)
d.Set("region", GetRegion(d, config))
return nil
}