-
Notifications
You must be signed in to change notification settings - Fork 645
/
resource_ibm_container_vpc_alb_create.go
157 lines (140 loc) · 4.15 KB
/
resource_ibm_container_vpc_alb_create.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
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package kubernetes
import (
"time"
v2 "github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func ResourceIBMContainerVpcAlbCreateNew() *schema.Resource {
return &schema.Resource{
Create: resourceIBMContainerVpcAlbCreate,
Read: resourceIBMContainerVpcALBRead,
Update: resourceIBMContainerVpcALBUpdate,
Delete: resourceIBMContainerVpcALBDelete,
Importer: &schema.ResourceImporter{},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Update: schema.DefaultTimeout(60 * time.Minute),
},
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The type of ALB that you want to create.",
},
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The zone where you want to deploy the ALB.",
},
"cluster": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The ID of the cluster that the ALB belongs to.",
ValidateFunc: validate.InvokeValidator(
"ibm_container_vpc_alb_create",
"cluster"),
},
"resource_group_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the resource group.",
},
"enable": {
Type: schema.TypeBool,
Optional: true,
Description: "Enable the ALB instance in the cluster",
},
//response
"alb_id": {
Type: schema.TypeString,
Computed: true,
ForceNew: true,
Description: "The ID of the application load balancer (ALB).",
},
//get
"alb_type": {
Type: schema.TypeString,
Computed: true,
Description: "Type of the ALB",
},
"disable_deployment": {
Type: schema.TypeBool,
Computed: true,
Description: "Disable the ALB instance in the cluster",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "ALB name",
},
"load_balancer_hostname": {
Type: schema.TypeString,
Computed: true,
Description: "Load balancer host name",
},
"resize": {
Type: schema.TypeBool,
Computed: true,
Description: "boolean value to resize the albs",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "ALB state",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Status of the ALB",
},
},
}
}
func resourceIBMContainerVpcAlbCreate(d *schema.ResourceData, meta interface{}) error {
albClient, err := meta.(conns.ClientSession).VpcContainerAPI()
if err != nil {
return err
}
albAPI := albClient.Albs()
params := v2.AlbCreateReq{}
if v, ok := d.GetOkExists("cluster"); ok {
params.Cluster = v.(string)
}
if v, ok := d.GetOkExists("type"); ok {
params.Type = v.(string)
}
if v, ok := d.GetOkExists("zone"); ok {
params.ZoneAlb = v.(string)
}
if v, ok := d.GetOk("enable"); ok {
params.EnableByDefault = v.(bool)
}
targetEnv, _ := getVpcClusterTargetHeader(d, meta)
//v2.AlbCreateResp
albResp, err := albAPI.CreateAlb(params, targetEnv)
if err != nil {
return err
}
d.SetId(albResp.Alb)
return nil
}
func ResourceIBMContainerVpcAlbCreateNewValidator() *validate.ResourceValidator {
validateSchema := make([]validate.ValidateSchema, 0)
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: "cluster",
ValidateFunctionIdentifier: validate.ValidateCloudData,
Type: validate.TypeString,
Required: true,
CloudDataType: "cluster",
CloudDataRange: []string{"resolved_to:id"}})
iBMContainerVpcAlbCreateNewValidator := validate.ResourceValidator{ResourceName: "ibm_container_nlb_dns", Schema: validateSchema}
return &iBMContainerVpcAlbCreateNewValidator
}