-
Notifications
You must be signed in to change notification settings - Fork 649
/
data_source_ibm_container_alb.go
89 lines (81 loc) · 2.12 KB
/
data_source_ibm_container_alb.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
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package kubernetes
import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMContainerALB() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMContainerALBRead,
Schema: map[string]*schema.Schema{
"alb_id": {
Type: schema.TypeString,
Required: true,
Description: "ALB ID",
},
"alb_type": {
Type: schema.TypeString,
Computed: true,
Description: "ALB type",
},
"cluster": {
Type: schema.TypeString,
Computed: true,
Description: "Cluster id",
},
"user_ip": {
Type: schema.TypeString,
Computed: true,
Description: "IP assigned by the user",
},
"enable": {
Type: schema.TypeBool,
Computed: true,
Description: "set to true if ALB needs to be enabled",
},
"disable_deployment": {
Type: schema.TypeBool,
Computed: true,
Description: "Set to true if ALB needs to be disabled",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "ALB name",
},
"zone": {
Type: schema.TypeString,
Computed: true,
Description: "ALB zone",
},
},
}
}
func dataSourceIBMContainerALBRead(d *schema.ResourceData, meta interface{}) error {
albClient, err := meta.(conns.ClientSession).ContainerAPI()
if err != nil {
return err
}
albID := d.Get("alb_id").(string)
albAPI := albClient.Albs()
targetEnv, err := getAlbTargetHeader(d, meta)
if err != nil {
return err
}
albConfig, err := albAPI.GetALB(albID, targetEnv)
if err != nil {
return err
}
d.SetId(albID)
d.Set("alb_type", &albConfig.ALBType)
d.Set("cluster", &albConfig.ClusterID)
d.Set("name", &albConfig.Name)
d.Set("enable", &albConfig.Enable)
d.Set("disable_deployment", &albConfig.DisableDeployment)
d.Set("replicas", &albConfig.NumOfInstances)
d.Set("resize", &albConfig.Resize)
d.Set("user_ip", &albConfig.ALBIP)
d.Set("zone", &albConfig.Zone)
return nil
}