-
Notifications
You must be signed in to change notification settings - Fork 640
/
data_source_ibm_app_config_environment.go
133 lines (121 loc) · 3.68 KB
/
data_source_ibm_app_config_environment.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
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright IBM Corp. 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package appconfiguration
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
)
func DataSourceIBMAppConfigEnvironment() *schema.Resource {
return &schema.Resource{
Read: dataSourceIbmAppConfigEnvironmentRead,
Schema: map[string]*schema.Schema{
"guid": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "GUID of the App Configuration service. Get it from the service instance credentials section of the dashboard.",
},
"environment_id": {
Type: schema.TypeString,
Required: true,
Description: "Environment Id.",
},
"expand": {
Type: schema.TypeBool,
Optional: true,
Description: "If set to `true`, returns expanded view of the resource details.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Environment name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Environment description.",
},
"tags": {
Type: schema.TypeString,
Computed: true,
Description: "Tags associated with the environment.",
},
"color_code": {
Type: schema.TypeString,
Computed: true,
Description: "Color code to distinguish the environment. The Hex code for the color. For example `#FF0000` for `red`.",
},
"created_time": {
Type: schema.TypeString,
Computed: true,
Description: "Creation time of the environment.",
},
"updated_time": {
Type: schema.TypeString,
Computed: true,
Description: "Last modified time of the environment data.",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "Environment URL.",
},
},
}
}
func dataSourceIbmAppConfigEnvironmentRead(d *schema.ResourceData, meta interface{}) error {
guid := d.Get("guid").(string)
appconfigClient, err := getAppConfigClient(meta, guid)
if err != nil {
return err
}
options := &appconfigurationv1.GetEnvironmentOptions{}
options.SetEnvironmentID(d.Get("environment_id").(string))
if _, ok := d.GetOk("expand"); ok {
options.SetExpand(d.Get("expand").(bool))
}
result, response, err := appconfigClient.GetEnvironment(options)
if err != nil {
log.Printf("GetEnvironment failed %s\n%s", err, response)
return err
}
d.SetId(fmt.Sprintf("%s/%s", guid, *result.EnvironmentID))
if result.Name != nil {
if err = d.Set("name", result.Name); err != nil {
return fmt.Errorf("[ERROR] Error setting name: %s", err)
}
}
if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return fmt.Errorf("[ERROR] Error setting description: %s", err)
}
}
if result.Tags != nil {
if err = d.Set("tags", result.Tags); err != nil {
return fmt.Errorf("[ERROR] Error setting tags: %s", err)
}
}
if result.ColorCode != nil {
if err = d.Set("color_code", result.ColorCode); err != nil {
return fmt.Errorf("[ERROR] Error setting color_code: %s", err)
}
}
if result.CreatedTime != nil {
if err = d.Set("created_time", result.CreatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting created_time: %s", err)
}
}
if result.UpdatedTime != nil {
if err = d.Set("updated_time", result.UpdatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting updated_time: %s", err)
}
}
if result.Href != nil {
if err = d.Set("href", result.Href); err != nil {
return fmt.Errorf("[ERROR] Error setting href: %s", err)
}
}
return nil
}