-
Notifications
You must be signed in to change notification settings - Fork 644
/
data_source_ibm_cm_offering_instance.go
183 lines (170 loc) · 6.32 KB
/
data_source_ibm_cm_offering_instance.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package catalogmanagement
import (
"context"
"fmt"
"log"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM/platform-services-go-sdk/catalogmanagementv1"
)
func DataSourceIBMCmOfferingInstance() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMCmOfferingInstanceRead,
Schema: map[string]*schema.Schema{
"instance_identifier": {
Type: schema.TypeString,
Required: true,
Description: "ID for this instance",
},
"url": {
Type: schema.TypeString,
Computed: true,
Description: "url reference to this object.",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "platform CRN for this instance.",
},
"_rev": {
Type: schema.TypeString,
Computed: true,
Description: "Cloudant Revision for this instance",
},
"label": {
Type: schema.TypeString,
Computed: true,
Description: "the label for this instance.",
},
"catalog_id": {
Type: schema.TypeString,
Computed: true,
Description: "Catalog ID this instance was created from.",
},
"offering_id": {
Type: schema.TypeString,
Computed: true,
Description: "Offering ID this instance was created from.",
},
"kind_format": {
Type: schema.TypeString,
Computed: true,
Description: "the format this instance has (helm, operator, ova...).",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "The version this instance was installed from (not version id).",
},
"cluster_id": {
Type: schema.TypeString,
Computed: true,
Description: "Cluster ID.",
},
"cluster_region": {
Type: schema.TypeString,
Computed: true,
Description: "Cluster region (e.g., us-south).",
},
"cluster_namespaces": {
Type: schema.TypeList,
Computed: true,
Description: "List of target namespaces to install into.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"cluster_all_namespaces": {
Type: schema.TypeBool,
Computed: true,
Description: "designate to install into all namespaces.",
},
"schematics_workspace_id": {
Type: schema.TypeString,
Computed: true,
Description: "id of the schematics workspace, for offerings installed through schematics",
},
"resource_group_id": {
Type: schema.TypeString,
Computed: true,
Description: "id of the resource group",
},
"install_plan": {
Type: schema.TypeString,
Computed: true,
Description: "install plan for the subscription of the operator- can be either Automatic or Manual. Required for operator bundles",
},
"channel": {
Type: schema.TypeString,
Computed: true,
Description: "channel to target for the operator subscription. Required for operator bundles",
},
},
}
}
func dataSourceIBMCmOfferingInstanceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
catalogManagementClient, err := meta.(conns.ClientSession).CatalogManagementV1()
if err != nil {
return diag.FromErr(err)
}
getOfferingInstanceOptions := &catalogmanagementv1.GetOfferingInstanceOptions{}
getOfferingInstanceOptions.SetInstanceIdentifier(d.Get("instance_identifier").(string))
offeringInstance, response, err := catalogManagementClient.GetOfferingInstanceWithContext(context, getOfferingInstanceOptions)
if err != nil {
log.Printf("[DEBUG] GetOfferingInstanceWithContext failed %s\n%s", err, response)
return diag.FromErr(err)
}
d.SetId(*offeringInstance.ID)
if err = d.Set("url", offeringInstance.URL); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting url: %s", err))
}
if err = d.Set("crn", offeringInstance.CRN); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting crn: %s", err))
}
if err = d.Set("_rev", offeringInstance.Rev); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting _rev: %s", err))
}
if err = d.Set("label", offeringInstance.Label); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting label: %s", err))
}
if err = d.Set("catalog_id", offeringInstance.CatalogID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting catalog_id: %s", err))
}
if err = d.Set("offering_id", offeringInstance.OfferingID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting offering_id: %s", err))
}
if err = d.Set("kind_format", offeringInstance.KindFormat); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting kind_format: %s", err))
}
if err = d.Set("version", offeringInstance.Version); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting version: %s", err))
}
if err = d.Set("cluster_id", offeringInstance.ClusterID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting cluster_id: %s", err))
}
if err = d.Set("cluster_region", offeringInstance.ClusterRegion); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting cluster_region: %s", err))
}
if err = d.Set("cluster_namespaces", offeringInstance.ClusterNamespaces); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting cluster_namespaces: %s", err))
}
if err = d.Set("cluster_all_namespaces", offeringInstance.ClusterAllNamespaces); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting cluster_all_namespaces: %s", err))
}
if err = d.Set("schematics_workspace_id", offeringInstance.SchematicsWorkspaceID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting schematics_workspace_id: %s", err))
}
if err = d.Set("resource_group_id", offeringInstance.ResourceGroupID); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group_id: %s", err))
}
if err = d.Set("install_plan", offeringInstance.InstallPlan); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting install_plan: %s", err))
}
if err = d.Set("channel", offeringInstance.Channel); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting channel: %s", err))
}
return nil
}