Skip to content

Commit 7cbbd08

Browse files
committed
feat(SNI): Server Name Indicator (SNI) routing for ALB
1 parent e4f4824 commit 7cbbd08

10 files changed

+96
-15
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ require (
4343
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.10
4444
github.com/IBM/vmware-go-sdk v0.1.3
4545
github.com/IBM/vpc-beta-go-sdk v0.8.0
46-
github.com/IBM/vpc-go-sdk v0.66.0
46+
github.com/IBM/vpc-go-sdk v0.67.0
4747
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
4848
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
4949
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5J
180180
github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE=
181181
github.com/IBM/vpc-go-sdk v0.66.0 h1:S0HW+f6Qf6OLSGESQ7WRgWLq1bDgvs+vvOJ7AWgUMbw=
182182
github.com/IBM/vpc-go-sdk v0.66.0/go.mod h1:VL7sy61ybg6tvA60SepoQx7TFe20m7JyNUt+se2tHP4=
183+
github.com/IBM/vpc-go-sdk v0.67.0 h1:p8G5bqTUyVheBrJpT+pLpoZoA/Yu1R2xX4xJLM4tT9w=
184+
github.com/IBM/vpc-go-sdk v0.67.0/go.mod h1:VL7sy61ybg6tvA60SepoQx7TFe20m7JyNUt+se2tHP4=
183185
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
184186
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc=
185187
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=

ibm/service/vpc/data_source_ibm_is_lb_listener_policy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func DataSourceIBMISLBListenerPolicy() *schema.Resource {
101101
"target": &schema.Schema{
102102
Type: schema.TypeList,
103103
Computed: true,
104-
Description: "- If `action` is `forward`, the response is a `LoadBalancerPoolReference`- If `action` is `redirect`, the response is a `LoadBalancerListenerPolicyRedirectURL`- If `action` is `https_redirect`, the response is a `LoadBalancerListenerHTTPSRedirect`.",
104+
Description: "- If `action` is `forward` or `forward_to_pool`, the response is a `LoadBalancerPoolReference`- If `action` is `forward_to_listener`, specify a `LoadBalancerListenerIdentity` in this load balancer to forward to. - If `action` is `redirect`, the response is a `LoadBalancerListenerPolicyRedirectURL`- If `action` is `https_redirect`, the response is a `LoadBalancerListenerHTTPSRedirect`.",
105105
Elem: &schema.Resource{
106106
Schema: map[string]*schema.Schema{
107107
"deleted": &schema.Schema{
@@ -126,12 +126,12 @@ func DataSourceIBMISLBListenerPolicy() *schema.Resource {
126126
"id": &schema.Schema{
127127
Type: schema.TypeString,
128128
Computed: true,
129-
Description: "The unique identifier for this load balancer pool.",
129+
Description: "The unique identifier for this load balancer pool or load balancer listener",
130130
},
131131
"name": &schema.Schema{
132132
Type: schema.TypeString,
133133
Computed: true,
134-
Description: "The user-defined name for this load balancer pool.",
134+
Description: "The user-defined name for this load balancer pool or load balancer listener.",
135135
},
136136
"http_status_code": &schema.Schema{
137137
Type: schema.TypeInt,

ibm/service/vpc/resource_ibm_is_lb_listener_policy.go

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ func ResourceIBMISLBListenerPolicy() *schema.Resource {
133133
ForceNew: true,
134134
ValidateFunc: validate.InvokeValidator("ibm_is_lb_listener_policy", isLBListenerPolicyAction),
135135
Description: "Policy Action",
136+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
137+
// Suppress the change if the old value is 'forward' and new value is 'forward_to_pool'
138+
if old == "forward" && new == "forward_to_pool" {
139+
return true
140+
}
141+
return false
142+
},
136143
},
137144

138145
isLBListenerPolicyPriority: {
@@ -360,7 +367,7 @@ func ResourceIBMISLBListenerPolicy() *schema.Resource {
360367
func ResourceIBMISLBListenerPolicyValidator() *validate.ResourceValidator {
361368

362369
validateSchema := make([]validate.ValidateSchema, 0)
363-
action := "forward, redirect, reject, https_redirect"
370+
action := "forward,forward_to_pool,forward_to_listener,redirect,reject,https_redirect"
364371
validateSchema = append(validateSchema,
365372
validate.ValidateSchema{
366373
Identifier: isLBListenerPolicyName,
@@ -464,20 +471,32 @@ func lbListenerPolicyCreate(d *schema.ResourceData, meta interface{}, lbID, list
464471
}
465472

466473
} else {
467-
if actionChk.(string) == "forward" {
474+
if actionChk.(string) == "forward" || actionChk.(string) == "forward_to_pool" {
468475
if targetIDSet {
469476

470477
//User can set the poolId as combination of lbID/poolID, if so parse the string & get the poolID
471478
id, err := getPoolID(tID.(string))
472479
if err != nil {
473480
return diag.FromErr(err)
474481
}
475-
476482
target = &vpcv1.LoadBalancerListenerPolicyTargetPrototypeLoadBalancerPoolIdentity{
477483
ID: &id,
478484
}
479485
} else {
480-
return diag.FromErr(fmt.Errorf("When action is forward please specify target_id"))
486+
return diag.FromErr(fmt.Errorf("when action is forward or forward_to_pool please specify target_id"))
487+
}
488+
} else if actionChk.(string) == "forward_to_listener" {
489+
if targetIDSet {
490+
//User can set listener id as combination of lbID/listenerID, parse and get the listenerID
491+
listenerID, err := getListenerID(d.Get(isLBListenerPolicyListenerID).(string))
492+
if err != nil {
493+
return diag.FromErr(err)
494+
}
495+
target = &vpcv1.LoadBalancerListenerPolicyTargetPrototypeLoadBalancerListenerIdentity{
496+
ID: &listenerID,
497+
}
498+
} else {
499+
return diag.FromErr(fmt.Errorf("when action is forward_to_listener please specify listener id"))
481500
}
482501
} else if actionChk.(string) == "redirect" {
483502

@@ -794,9 +813,9 @@ func lbListenerPolicyUpdate(d *schema.ResourceData, meta interface{}, lbID, list
794813
hasChanged = true
795814

796815
} else {
797-
816+
actionChk := (d.Get(isLBListenerPolicyAction).(string))
798817
//If Action is forward and TargetID is changed, set the target to pool ID
799-
if d.Get(isLBListenerPolicyAction).(string) == "forward" && d.HasChange(isLBListenerPolicyTargetID) {
818+
if (actionChk == "forward" || actionChk == "forward_to_pool") && d.HasChange(isLBListenerPolicyTargetID) {
800819

801820
//User can set the poolId as combination of lbID/poolID, if so parse the string & get the poolID
802821
id, err := getPoolID(d.Get(isLBListenerPolicyTargetID).(string))
@@ -809,6 +828,15 @@ func lbListenerPolicyUpdate(d *schema.ResourceData, meta interface{}, lbID, list
809828

810829
loadBalancerListenerPolicyPatchModel.Target = target
811830
hasChanged = true
831+
} else if actionChk == "forward_to_listener" && d.HasChange(isLBListenerPolicyTargetID) {
832+
//User can set listener id as combination of lbID/listenerID, parse and get the listenerID
833+
listenerID, err := getListenerID(d.Get(isLBListenerPolicyListenerID).(string))
834+
if err != nil {
835+
return diag.FromErr(err)
836+
}
837+
target = &vpcv1.LoadBalancerListenerPolicyTargetPatchLoadBalancerListenerIdentity{
838+
ID: &listenerID,
839+
}
812840
} else if d.Get(isLBListenerPolicyAction).(string) == "redirect" {
813841
//if Action is redirect and either status code or URL chnaged, set accordingly
814842
//LoadBalancerListenerPolicyPatchTargetLoadBalancerListenerPolicyRedirectURLPatch
@@ -1104,12 +1132,19 @@ func lbListenerPolicyGet(d *schema.ResourceData, meta interface{}, lbID, listene
11041132
return diag.FromErr(fmt.Errorf("Error setting target: %s", err))
11051133
}
11061134
} else {
1107-
if *(policy.Action) == "forward" {
1135+
if *(policy.Action) == "forward" || *(policy.Action) == "forward_to_pool" {
11081136
if reflect.TypeOf(policy.Target).String() == "*vpcv1.LoadBalancerListenerPolicyTargetLoadBalancerPoolReference" {
11091137
target, ok := policy.Target.(*vpcv1.LoadBalancerListenerPolicyTargetLoadBalancerPoolReference)
11101138
if ok {
11111139
d.Set(isLBListenerPolicyTargetID, target.ID)
11121140
}
1141+
} else if *(policy.Action) == "forward_to_listener" {
1142+
if reflect.TypeOf(policy.Target).String() == "*vpcv1.LoadBalancerListenerPolicyTargetLoadBalancerListenerReference" {
1143+
target, ok := policy.Target.(*vpcv1.LoadBalancerListenerPolicyTargetLoadBalancerListenerReference)
1144+
if ok {
1145+
d.Set(isLBListenerPolicyTargetID, target.ID)
1146+
}
1147+
}
11131148
}
11141149

11151150
} else if *(policy.Action) == "redirect" {

ibm/service/vpc/resource_ibm_is_lb_listener_policy_rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func ResourceIBMISLBListenerPolicyRuleValidator() *validate.ResourceValidator {
163163

164164
validateSchema := make([]validate.ValidateSchema, 0)
165165
condition := "contains, equals, matches_regex"
166-
ruletype := "header, hostname, path, body, query"
166+
ruletype := "header, hostname, path, body, query, sni_hostname"
167167
validateSchema = append(validateSchema,
168168
validate.ValidateSchema{
169169
Identifier: isLBListenerPolicyRulecondition,

ibm/service/vpc/resource_ibm_is_lb_listener_policy_rule_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ func TestAccIBMISLBListenerPolicyRule_basic(t *testing.T) {
2727
//lblistenerpolicyname2 := fmt.Sprintf("tflblisuat-listener-policy-%d", acctest.RandIntRange(10, 100))
2828
lblistenerpolicyRuleField1 := fmt.Sprintf("tflblipolicy-rule-field-%d", acctest.RandIntRange(10, 100))
2929
lblistenerpolicyRuleField2 := fmt.Sprintf("tflblipolicy-rule-field-%d", acctest.RandIntRange(10, 100))
30+
lblistenerpolicyRuleField3 := fmt.Sprintf("tflblipolicy-rule-field-%d", acctest.RandIntRange(10, 100))
3031
lblistenerpolicyRuleValue1 := fmt.Sprintf("tflblipolicy-rule-value-%d", acctest.RandIntRange(10, 100))
3132
lblistenerpolicyRuleValue2 := fmt.Sprintf("tflblipolicy-rule-value-%d", acctest.RandIntRange(10, 100))
33+
lblistenerpolicyRuleValue3 := fmt.Sprintf("tflblipolicy-rule-value-%d", acctest.RandIntRange(10, 100))
3234

3335
priority := "1"
3436
protocol := "http"
@@ -38,6 +40,7 @@ func TestAccIBMISLBListenerPolicyRule_basic(t *testing.T) {
3840
condition := "equals"
3941
typeh := "header"
4042
typeb := "body"
43+
typeSni := "sni_hostname"
4144

4245
resource.Test(t, resource.TestCase{
4346
PreCheck: func() { acc.TestAccPreCheck(t) },
@@ -57,6 +60,19 @@ func TestAccIBMISLBListenerPolicyRule_basic(t *testing.T) {
5760
),
5861
},
5962

63+
{
64+
Config: testAccCheckIBMISLBListenerPolicyRuleConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port, protocol, lblistenerpolicyname, action, priority, condition, typeSni, lblistenerpolicyRuleField1, lblistenerpolicyRuleValue1),
65+
Check: resource.ComposeTestCheckFunc(
66+
testAccCheckIBMISLBListenerPolicyRuleExists("ibm_is_lb_listener_policy_rule.testacc_lb_listener_policy_rule", ruleID),
67+
resource.TestCheckResourceAttr(
68+
"ibm_is_lb.testacc_LB", "name", lbname),
69+
resource.TestCheckResourceAttr(
70+
"ibm_is_lb_listener_policy_rule.testacc_lb_listener_policy_rule", "field", lblistenerpolicyRuleField3),
71+
resource.TestCheckResourceAttr(
72+
"ibm_is_lb_listener_policy_rule.testacc_lb_listener_policy_rule", "value", lblistenerpolicyRuleValue3),
73+
),
74+
},
75+
6076
{
6177
Config: testAccCheckIBMISLBListenerPolicyRuleConfigUpdate(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port, protocol, lblistenerpolicyname, priority, condition, typeb, lblistenerpolicyRuleField2, lblistenerpolicyRuleValue2),
6278
Check: resource.ComposeTestCheckFunc(

ibm/service/vpc/resource_ibm_is_lb_listener_policy_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func TestAccIBMISLBListenerPolicy_basic(t *testing.T) {
3131
port := "8080"
3232
action := "forward"
3333
priority2 := "2"
34+
actionPool := "forward_to_pool"
35+
actionListener := "forward_to_listener"
3436

3537
resource.Test(t, resource.TestCase{
3638
PreCheck: func() { acc.TestAccPreCheck(t) },
@@ -50,6 +52,32 @@ func TestAccIBMISLBListenerPolicy_basic(t *testing.T) {
5052
"ibm_is_lb_listener_policy.testacc_lb_listener_policy", "priority", priority1),
5153
),
5254
},
55+
{
56+
Config: testAccCheckIBMISLBListenerPolicyConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port, protocol, lblistenerpolicyname1, actionPool, priority1),
57+
Check: resource.ComposeTestCheckFunc(
58+
testAccCheckIBMISLBListenerPolicyExists("ibm_is_lb_listener_policy.testacc_lb_listener_policy", policyID),
59+
resource.TestCheckResourceAttr(
60+
"ibm_is_lb.testacc_LB", "name", lbname),
61+
resource.TestCheckResourceAttr(
62+
"ibm_is_lb_listener_policy.testacc_lb_listener_policy", "name", lblistenerpolicyname1),
63+
64+
resource.TestCheckResourceAttr(
65+
"ibm_is_lb_listener_policy.testacc_lb_listener_policy", "priority", priority1),
66+
),
67+
},
68+
{
69+
Config: testAccCheckIBMISLBListenerPolicyConfig(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port, protocol, lblistenerpolicyname1, actionListener, priority1),
70+
Check: resource.ComposeTestCheckFunc(
71+
testAccCheckIBMISLBListenerPolicyExists("ibm_is_lb_listener_policy.testacc_lb_listener_policy", policyID),
72+
resource.TestCheckResourceAttr(
73+
"ibm_is_lb.testacc_LB", "name", lbname),
74+
resource.TestCheckResourceAttr(
75+
"ibm_is_lb_listener_policy.testacc_lb_listener_policy", "name", lblistenerpolicyname1),
76+
77+
resource.TestCheckResourceAttr(
78+
"ibm_is_lb_listener_policy.testacc_lb_listener_policy", "priority", priority1),
79+
),
80+
},
5381

5482
{
5583
Config: testAccCheckIBMISLBListenerPolicyConfigUpdate(vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, lbname, port, protocol, lblistenerpolicyname2, priority2, action),

website/docs/d/is_lb_listener_policy.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Nested scheme for `rules`:
5252
- `href` - (String) The rule's canonical URL.
5353
- `id` - (String) The rule's unique identifier.
5454

55-
- `target` - (List) - If `action` is `forward`, the response is a `LoadBalancerPoolReference`- If `action` is `redirect`, the response is a `LoadBalancerListenerPolicyRedirectURL`- If `action` is `https_redirect`, the response is a `LoadBalancerListenerHTTPSRedirect`.
55+
- `target` - (List) - If `action` is `forward`, the response is a `LoadBalancerPoolReference`-If `action` is `forward_to_pool`, the response is a `LoadBalancerPoolReference`-If `action` is `forward_to_listener`, specify a `LoadBalancerListenerIdentity` in this load balancer to forward to.`- If `action` is `redirect`, the response is a `LoadBalancerListenerPolicyRedirectURL`- If `action` is `https_redirect`, the response is a `LoadBalancerListenerHTTPSRedirect`.
5656
Nested scheme for `target`:
5757
- `deleted` - (List) If present, this property indicates the referenced resource has been deleted and provides some supplementary information.
5858
Nested scheme for `deleted`:

website/docs/d/is_lb_listener_policy_rule.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In addition to all argument references listed, you can access the following attr
3838

3939
- `created_at` - (String) The date and time that this rule was created.
4040

41-
- `field` - (String) The field. This is applicable to `header`, `query`, and `body` rule types.If the rule type is `header`, this property is required.If the rule type is `query`, this is optional. If specified and the rule condition is not`matches_regex`, the value must be percent-encoded.If the rule type is `body`, this is optional.
41+
- `field` - (String) The field. This is applicable to `header`, `query`,`body` and `sni_hostname` rule types.If the rule type is `header`, this property is required.If the rule type is `query`, this is optional. If specified and the rule condition is not`matches_regex`, the value must be percent-encoded.If the rule type is `body`, this is optional.
4242

4343
- `href` - (String) The rule's canonical URL.
4444

website/docs/r/is_lb_listener_policy.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ The `ibm_is_lb_listener_policy` resource provides the following [Timeouts](https
167167
## Argument reference
168168
Review the argument references that you can specify for your resource.
169169

170-
- `action` - (Required, Forces new resource, String) The action that you want to specify for your policy. Supported values are `forward`, `redirect`, `reject`, and `https_redirect`.
170+
- `action` - (Required, Forces new resource, String) The action that you want to specify for your policy. Supported values are `forward_to_pool`,`forward_to_listener`, `redirect`, `reject`, and `https_redirect`.
171171
- `lb` - (Required, Forces new resource, String) The ID of the load balancer for which you want to create a load balancer listener policy.
172172
- `listener` - (Required, Forces new resource, String) The ID of the load balancer listener.
173173
- `name` - (Optional, String) The name for the load balancer policy. Names must be unique within a load balancer listener.

0 commit comments

Comments
 (0)