-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support enable secure-by-default #5751
Changes from all commits
2c1242f
986bab0
c9c7fa4
ee589a7
6c4d00e
37e212b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ const ( | |
|
||
const ( | ||
DisableOutboundTrafficProtectionFlag = "disable_outbound_traffic_protection" | ||
EnableSecureByDefaultFlag = "enable_secure_by_default" | ||
) | ||
|
||
func ResourceIBMContainerVpcCluster() *schema.Resource { | ||
|
@@ -52,6 +53,9 @@ func ResourceIBMContainerVpcCluster() *schema.Resource { | |
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { | ||
return flex.ResourceTagsCustomizeDiff(diff) | ||
}, | ||
func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { | ||
return flex.OnlyInUpdateDiff([]string{EnableSecureByDefaultFlag}, diff) | ||
}, | ||
), | ||
|
||
Schema: map[string]*schema.Schema{ | ||
|
@@ -357,6 +361,22 @@ func ResourceIBMContainerVpcCluster() *schema.Resource { | |
Description: "Allow outbound connections to public destinations", | ||
}, | ||
|
||
EnableSecureByDefaultFlag: { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Enable Secure-by-default on existing clusters (note: can be used on existing clusters)", | ||
ValidateFunc: func(i interface{}, s string) (warnings []string, errors []error) { | ||
v := i.(bool) | ||
if !v { | ||
// The field can only be true | ||
errors = append(errors, fmt.Errorf("%s can be only true", s)) | ||
return warnings, errors | ||
} | ||
|
||
return warnings, errors | ||
}, | ||
}, | ||
|
||
//Get Cluster info Request | ||
"state": { | ||
Type: schema.TypeString, | ||
|
@@ -746,8 +766,7 @@ func resourceIBMContainerVpcClusterUpdate(d *schema.ResourceData, meta interface | |
} | ||
} | ||
|
||
if d.HasChange(DisableOutboundTrafficProtectionFlag) { | ||
outbound_traffic_protection := !d.Get(DisableOutboundTrafficProtectionFlag).(bool) | ||
if d.HasChange(DisableOutboundTrafficProtectionFlag) || d.HasChange(EnableSecureByDefaultFlag) { | ||
ClusterClient, err := meta.(conns.ClientSession).VpcContainerAPI() | ||
if err != nil { | ||
return err | ||
|
@@ -758,9 +777,21 @@ func resourceIBMContainerVpcClusterUpdate(d *schema.ResourceData, meta interface | |
return err | ||
} | ||
|
||
if err := ClusterClient.VPCs().SetOutboundTrafficProtection(clusterID, outbound_traffic_protection, Env); err != nil { | ||
return err | ||
if d.HasChange(DisableOutboundTrafficProtectionFlag) { | ||
outbound_traffic_protection := !d.Get(DisableOutboundTrafficProtectionFlag).(bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we are storing opposite value of DisableOutboundTrafficProtectionFlag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a legacy stuff, I didn't change the functionality here. On the other hand if I'm right the |
||
if err := ClusterClient.VPCs().SetOutboundTrafficProtection(clusterID, outbound_traffic_protection, Env); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if d.HasChange(EnableSecureByDefaultFlag) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we enable we can disable it back also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I can follow you. |
||
enableSecureByDefault := d.Get(EnableSecureByDefaultFlag).(bool) | ||
if err := ClusterClient.VPCs().EnableSecureByDefault(clusterID, enableSecureByDefault, Env); err != nil { | ||
return err | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
if (d.HasChange("kube_version") || d.HasChange("update_all_workers") || d.HasChange("patch_version") || d.HasChange("retry_patch_version")) && !d.IsNewResource() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we are checking if its type bool or value can be true or false since we defined it as bool type will not it implictly take only true/false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, the first check is not needed. I'll remove it