Skip to content

Commit 3253a15

Browse files
feat(instance): add support for enable_default_security (#651)
Co-authored-by: Jerome Quere <[email protected]>
1 parent 28142bd commit 3253a15

7 files changed

+803
-3
lines changed

docs/resources/instance_security_group.md

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ The following arguments are supported:
120120

121121
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the security group is associated with.
122122

123+
- `enable_defaul_security` - Whether to block SMTP on IPv4/IPv6 (Port 25, 465, 587). Set to false will unblock SMTP if your account is authorized to. If your organization is not yet authorized to send SMTP traffic, [open a support ticket](https://console.scaleway.com/support/tickets).
123124

124125
The `inbound_rule` and `outbound_rule` block supports:
125126

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/go-cmp v0.5.2
88
github.com/hashicorp/go-retryablehttp v0.6.7
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.2.0
10-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201113152841-1153aa56e20e
10+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201210153359-29e11ec95efd
1111
github.com/stretchr/testify v1.6.1
1212
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
1313
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
299299
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
300300
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
301301
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
302-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201113152841-1153aa56e20e h1:KW5n7q2CMM/MsFNAwdZWB0UioVa3E3XQSrKRZcjmaGo=
303-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201113152841-1153aa56e20e/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
302+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201210153359-29e11ec95efd h1:CjD+yEroS8fNyXwWNdGHb1fr3DE6As6dZoBhNIHZtHk=
303+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20201210153359-29e11ec95efd/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
304304
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
305305
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
306306
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=

scaleway/helpers.go

+7
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,13 @@ func expandStringPtr(data interface{}) *string {
386386
return scw.StringPtr(data.(string))
387387
}
388388

389+
func expandBoolPtr(data interface{}) *bool {
390+
if data == nil {
391+
return nil
392+
}
393+
return scw.BoolPtr(data.(bool))
394+
}
395+
389396
func flattenInt32Ptr(i *int32) interface{} {
390397
if i == nil {
391398
return 0

scaleway/resource_instance_security_group.go

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func resourceScalewayInstanceSecurityGroup() *schema.Resource {
8282
Default: false,
8383
ConflictsWith: []string{"inbound_rule", "outbound_rule"},
8484
},
85+
"enable_default_security": {
86+
Type: schema.TypeBool,
87+
Description: "Enable blocking of SMTP on IPv4 and IPv6",
88+
Optional: true,
89+
Default: true,
90+
},
8591
"zone": zoneSchema(),
8692
"organization_id": organizationIDSchema(),
8793
"project_id": projectIDSchema(),
@@ -104,6 +110,7 @@ func resourceScalewayInstanceSecurityGroupCreate(ctx context.Context, d *schema.
104110
Stateful: d.Get("stateful").(bool),
105111
InboundDefaultPolicy: instance.SecurityGroupPolicy(d.Get("inbound_default_policy").(string)),
106112
OutboundDefaultPolicy: instance.SecurityGroupPolicy(d.Get("outbound_default_policy").(string)),
113+
EnableDefaultSecurity: expandBoolPtr(d.Get("enable_default_security")),
107114
}, scw.WithContext(ctx))
108115
if err != nil {
109116
return diag.FromErr(err)
@@ -144,6 +151,7 @@ func resourceScalewayInstanceSecurityGroupRead(ctx context.Context, d *schema.Re
144151
_ = d.Set("description", res.SecurityGroup.Description)
145152
_ = d.Set("inbound_default_policy", res.SecurityGroup.InboundDefaultPolicy.String())
146153
_ = d.Set("outbound_default_policy", res.SecurityGroup.OutboundDefaultPolicy.String())
154+
_ = d.Set("enable_default_security", res.SecurityGroup.EnableDefaultSecurity)
147155

148156
if !d.Get("external_rules").(bool) {
149157
inboundRules, outboundRules, err := getSecurityGroupRules(instanceAPI, zone, ID, d)
@@ -232,6 +240,10 @@ func resourceScalewayInstanceSecurityGroupUpdate(ctx context.Context, d *schema.
232240
OutboundDefaultPolicy: &outboundDefaultPolicy,
233241
}
234242

243+
if d.HasChange("enable_default_security") {
244+
updateReq.EnableDefaultSecurity = expandBoolPtr(d.Get("enable_default_security"))
245+
}
246+
235247
// Only update name if one is provided in the state
236248
if d.Get("name") != nil && d.Get("name").(string) != "" {
237249
updateReq.Name = expandStringPtr(d.Get("name"))

scaleway/resource_instance_security_group_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,35 @@ func testSweepComputeInstanceSecurityGroup(_ string) error {
538538
return nil
539539
})
540540
}
541+
542+
func TestAccScalewayInstanceSecurityGroup_EnableDefaultSecurity(t *testing.T) {
543+
tt := NewTestTools(t)
544+
defer tt.Cleanup()
545+
resource.Test(t, resource.TestCase{
546+
PreCheck: func() { testAccPreCheck(t) },
547+
ProviderFactories: tt.ProviderFactories,
548+
CheckDestroy: testAccCheckScalewayInstanceSecurityGroupDestroy(tt),
549+
Steps: []resource.TestStep{
550+
{
551+
Config: `
552+
resource "scaleway_instance_security_group" "base" {
553+
enable_default_security = false
554+
}
555+
`,
556+
Check: resource.ComposeTestCheckFunc(
557+
resource.TestCheckResourceAttr("scaleway_instance_security_group.base", "enable_default_security", "false"),
558+
),
559+
},
560+
{
561+
Config: `
562+
resource "scaleway_instance_security_group" "base" {
563+
enable_default_security = true
564+
}
565+
`,
566+
Check: resource.ComposeTestCheckFunc(
567+
resource.TestCheckResourceAttr("scaleway_instance_security_group.base", "enable_default_security", "true"),
568+
),
569+
},
570+
},
571+
})
572+
}

0 commit comments

Comments
 (0)