generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
aws_alb.go
93 lines (87 loc) · 2.97 KB
/
aws_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
90
91
92
93
package load_balancer
import (
"context"
"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func ResourceAwsALB() *schema.Resource {
resource := &schema.Resource{
Description: "Resource for creating an AWS application load balancer",
ReadContext: resourceLoadBalancerRead,
CreateContext: resourceAwsALBCreateOrUpdate,
UpdateContext: resourceAwsALBCreateOrUpdate,
DeleteContext: resourceLoadBalancerDelete,
Importer: helpers.MultiLevelResourceImporter,
Schema: map[string]*schema.Schema{
"identifier": {
Description: "Unique identifier of the resource",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the proxy",
Type: schema.TypeString,
Required: true,
},
"host_name": {
Description: "Hostname for the proxy",
Type: schema.TypeString,
Required: true,
},
"cloud_connector_id": {
Description: "Id of the cloud connector",
Type: schema.TypeString,
Required: true,
},
"region": {
Description: "Region in which cloud resources are hosted",
Type: schema.TypeString,
Required: true,
},
"security_groups": {
Description: "Security Group to define the security rules that determine the inbound and outbound traffic",
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"vpc": {
Description: "VPC in which cloud resources are hosted",
Type: schema.TypeString,
Required: true,
},
"certificate_id": {
Description: "",
Type: schema.TypeString,
Optional: true,
},
"route53_hosted_zone_id": {
Description: "Route 53 hosted zone id",
Type: schema.TypeString,
Optional: true,
},
"alb_arn": {
Description: "Arn of AWS ALB to be imported. Required only for importing existing ALB",
Type: schema.TypeString,
Optional: true,
},
"delete_cloud_resources_on_destroy": {
Description: "Governs how the loadabalancer entity will be deleted on Terraform destroy. When set to true, the associated ALB will be deleted permanently from AWS account. Be fully aware of the consequneces of settting this to true, as the action is irreversible. When set to false, solely the Harness LB representation will be deleted, leaving the cloud resources intact.",
Type: schema.TypeBool,
Required: true,
},
},
}
return resource
}
func resourceAwsALBCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb, err := buildLoadBalancer(d, c.AccountId, "aws", "")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}