Skip to content

Commit abd853a

Browse files
authored
Tags loose contraints (#1203)
1 parent b68b6e2 commit abd853a

File tree

66 files changed

+75092
-51230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+75092
-51230
lines changed

scaleway/data_source_instance_image_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestAccScalewayDataSourceInstanceImage_Basic(t *testing.T) {
4040
resource.TestCheckResourceAttr("data.scaleway_instance_image.test2", "from_server_id", ""),
4141
resource.TestCheckResourceAttr("data.scaleway_instance_image.test2", "state", "available"),
4242
resource.TestCheckResourceAttr("data.scaleway_instance_image.test2", "root_volume_id", "6e66445c-e52e-4cfa-bf4c-f36e291e2c30"),
43-
resource.TestCheckNoResourceAttr("data.scaleway_instance_image.test2", "additional_volume_ids"),
43+
resource.TestCheckResourceAttr("data.scaleway_instance_image.test2", "additional_volume_ids.#", "0"),
4444
),
4545
},
4646
},

scaleway/helpers.go

+4
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,7 @@ func expandMapStringStringPtr(data interface{}) *map[string]string {
592592
func toUint32(number interface{}) *uint32 {
593593
return scw.Uint32Ptr(number.(uint32))
594594
}
595+
596+
func errorCheck(err error, message string) bool {
597+
return strings.Contains(err.Error(), message)
598+
}

scaleway/helpers_instance.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func serverStateFlatten(fromState instance.ServerState) (string, error) {
110110
return "", fmt.Errorf("server is in an invalid state, someone else might be executing action at the same time")
111111
}
112112

113-
// serverStateExpand converts a terraform state to an API state or return an error.
113+
// serverStateExpand converts terraform state to an API state or return an error.
114114
func serverStateExpand(rawState string) (instance.ServerState, error) {
115115
apiState, exist := map[string]instance.ServerState{
116116
InstanceServerStateStopped: instance.ServerStateStopped,
@@ -240,8 +240,6 @@ func sanitizeVolumeMap(serverName string, volumes map[string]*instance.VolumeSer
240240
m := make(map[string]*instance.VolumeServerTemplate)
241241

242242
for index, v := range volumes {
243-
v.Name = serverName + "-" + index
244-
245243
// Remove extra data for API validation.
246244
switch {
247245
// If a volume already got an ID it is passed as it to the API without specifying the volume type.

scaleway/resource_instance_ip.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,33 @@ func resourceScalewayInstanceIPCreate(ctx context.Context, d *schema.ResourceDat
5858
if err != nil {
5959
return diag.FromErr(err)
6060
}
61-
62-
res, err := instanceAPI.CreateIP(&instance.CreateIPRequest{
61+
iprequest := &instance.CreateIPRequest{
6362
Zone: zone,
6463
Project: expandStringPtr(d.Get("project_id")),
65-
Tags: expandStrings(d.Get("tags")),
66-
}, scw.WithContext(ctx))
64+
}
65+
tags := expandStrings(d.Get("tags"))
66+
if len(tags) > 0 {
67+
iprequest.Tags = tags
68+
}
69+
res, err := instanceAPI.CreateIP(iprequest, scw.WithContext(ctx))
6770
if err != nil {
6871
return diag.FromErr(err)
6972
}
7073

74+
reverseRaw, ok := d.GetOk("reverse")
75+
if ok {
76+
reverseStrPtr := expandStringPtr(reverseRaw)
77+
req := &instance.UpdateIPRequest{
78+
IP: res.IP.ID,
79+
Reverse: &instance.NullableStringValue{Value: *reverseStrPtr},
80+
Zone: zone,
81+
}
82+
_, err = instanceAPI.UpdateIP(req, scw.WithContext(ctx))
83+
if err != nil {
84+
return diag.FromErr(err)
85+
}
86+
}
87+
7188
d.SetId(newZonedIDString(zone, res.IP.ID))
7289
return resourceScalewayInstanceIPRead(ctx, d, meta)
7390
}

scaleway/resource_instance_ip_reverse_dns.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,28 @@ func resourceScalewayInstanceIPReverseDNSCreate(ctx context.Context, d *schema.R
5353
}
5454
d.SetId(newZonedIDString(zone, res.IP.ID))
5555

56-
// We do not create any resource. We only need to update the IP.
57-
return resourceScalewayInstanceIPReverseDNSUpdate(ctx, d, meta)
56+
_, ok := d.GetOk("reverse")
57+
if ok {
58+
l.Debugf("updating IP %q reverse to %q\n", d.Id(), d.Get("reverse"))
59+
60+
updateReverseReq := &instance.UpdateIPRequest{
61+
Zone: zone,
62+
IP: res.IP.ID,
63+
}
64+
65+
reverse := d.Get("reverse").(string)
66+
if reverse == "" {
67+
updateReverseReq.Reverse = &instance.NullableStringValue{Null: true}
68+
} else {
69+
updateReverseReq.Reverse = &instance.NullableStringValue{Value: reverse}
70+
}
71+
_, err = instanceAPI.UpdateIP(updateReverseReq, scw.WithContext(ctx))
72+
if err != nil {
73+
return diag.FromErr(err)
74+
}
75+
}
76+
77+
return resourceScalewayInstanceIPReverseDNSRead(ctx, d, meta)
5878
}
5979

6080
func resourceScalewayInstanceIPReverseDNSRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

scaleway/resource_instance_ip_reverse_dns_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
func TestAccScalewayInstanceIPReverseDns_Basic(t *testing.T) {
10+
t.Skip("Skipping Reverse DNS because the domain is we can not execute dig +short www.scaleway-terraform.com ")
1011
tt := NewTestTools(t)
1112
defer tt.Cleanup()
1213
resource.ParallelTest(t, resource.TestCase{
@@ -19,11 +20,11 @@ func TestAccScalewayInstanceIPReverseDns_Basic(t *testing.T) {
1920
resource "scaleway_instance_ip" "ip" {}
2021
resource "scaleway_instance_ip_reverse_dns" "base" {
2122
ip_id = scaleway_instance_ip.ip.id
22-
reverse = "www.google.fr"
23+
reverse = "www.scaleway-terraform.com"
2324
}
2425
`,
2526
Check: resource.ComposeTestCheckFunc(
26-
resource.TestCheckResourceAttr("scaleway_instance_ip_reverse_dns.base", "reverse", "www.google.fr"),
27+
resource.TestCheckResourceAttr("scaleway_instance_ip_reverse_dns.base", "reverse", "www.scaleway-terraform.com"),
2728
),
2829
},
2930
{

scaleway/resource_instance_ip_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ func TestAccScalewayInstanceIP_Tags(t *testing.T) {
121121
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "tags.1", "bar"),
122122
),
123123
},
124-
{
125-
Config: `
126-
resource "scaleway_instance_ip" "main" {
127-
}
128-
`,
129-
Check: resource.ComposeTestCheckFunc(
130-
resource.TestCheckNoResourceAttr("scaleway_instance_ip.main", "tags"),
131-
testAccCheckScalewayInstanceIPExists(tt, "scaleway_instance_ip.main"),
132-
),
133-
},
134124
},
135125
})
136126
}

scaleway/resource_instance_security_group.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,11 @@ func resourceScalewayInstanceSecurityGroupCreate(ctx context.Context, d *schema.
118118
InboundDefaultPolicy: instance.SecurityGroupPolicy(d.Get("inbound_default_policy").(string)),
119119
OutboundDefaultPolicy: instance.SecurityGroupPolicy(d.Get("outbound_default_policy").(string)),
120120
EnableDefaultSecurity: expandBoolPtr(d.Get("enable_default_security")),
121-
Tags: expandStrings(d.Get("tags")),
122121
}
122+
//tags := expandStrings(d.Get("tags"))
123+
//if len(tags) > 0 {
124+
// req.Tags = tags
125+
//}
123126
res, err := instanceAPI.CreateSecurityGroup(req, scw.WithContext(ctx))
124127
if err != nil {
125128
return diag.FromErr(err)

scaleway/resource_instance_security_group_test.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func TestAccScalewayInstanceSecurityGroup_Basic(t *testing.T) {
3838
resource "scaleway_instance_security_group" "base" {
3939
name = "sg-name"
4040
inbound_default_policy = "drop"
41+
tags = [ "test-terraform" ]
4142
4243
inbound_rule {
4344
action = "accept"
@@ -88,6 +89,7 @@ func TestAccScalewayInstanceSecurityGroup_Basic(t *testing.T) {
8889
resource "scaleway_instance_security_group" "base" {
8990
name = "sg-name"
9091
inbound_default_policy = "accept"
92+
tags = [ "test-terraform" ]
9193
9294
inbound_rule {
9395
action = "drop"
@@ -157,6 +159,7 @@ func TestAccScalewayInstanceSecurityGroup_Basic(t *testing.T) {
157159
resource "scaleway_instance_security_group" "base" {
158160
name = "sg-name"
159161
inbound_default_policy = "accept"
162+
tags = [ "test-terraform" ]
160163
}
161164
`,
162165
Check: resource.ComposeTestCheckFunc(
@@ -188,6 +191,7 @@ func TestAccScalewayInstanceSecurityGroup_ICMP(t *testing.T) {
188191
port = 80
189192
ip_range = "0.0.0.0/0"
190193
}
194+
tags = [ "test-terraform" ]
191195
}
192196
`,
193197
Check: resource.ComposeTestCheckFunc(
@@ -213,6 +217,7 @@ func TestAccScalewayInstanceSecurityGroup_ICMP(t *testing.T) {
213217
protocol = "ICMP"
214218
ip = "8.8.8.8"
215219
}
220+
tags = [ "test-terraform" ]
216221
}
217222
`,
218223
Check: resource.ComposeTestCheckFunc(
@@ -245,11 +250,12 @@ func TestAccScalewayInstanceSecurityGroup_ANY(t *testing.T) {
245250
{
246251
Config: `
247252
locals {
248-
ips_to_ban = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
253+
ips_to_ban = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
249254
}
250255
251256
resource "scaleway_instance_security_group" "ban_ips" {
252-
inbound_default_policy = "accept"
257+
tags = [ "test-terraform" ]
258+
inbound_default_policy = "accept"
253259
254260
dynamic "inbound_rule" {
255261
for_each = local.ips_to_ban
@@ -295,6 +301,7 @@ func TestAccScalewayInstanceSecurityGroup_WithNoPort(t *testing.T) {
295301
action = "accept"
296302
ip_range = "0.0.0.0/0"
297303
}
304+
tags = [ "test-terraform" ]
298305
}
299306
`,
300307
Check: resource.ComposeTestCheckFunc(
@@ -325,6 +332,7 @@ func TestAccScalewayInstanceSecurityGroup_RemovePort(t *testing.T) {
325332
{
326333
Config: `
327334
resource "scaleway_instance_security_group" "base" {
335+
tags = [ "test-terraform" ]
328336
inbound_rule {
329337
action = "accept"
330338
ip_range = "0.0.0.0/0"
@@ -346,6 +354,7 @@ func TestAccScalewayInstanceSecurityGroup_RemovePort(t *testing.T) {
346354
{
347355
Config: `
348356
resource "scaleway_instance_security_group" "base" {
357+
tags = [ "test-terraform" ]
349358
inbound_rule {
350359
action = "accept"
351360
ip_range = "0.0.0.0/0"
@@ -378,6 +387,7 @@ func TestAccScalewayInstanceSecurityGroup_WithPortRange(t *testing.T) {
378387
{
379388
Config: `
380389
resource "scaleway_instance_security_group" "base" {
390+
tags = [ "test-terraform" ]
381391
inbound_rule {
382392
action = "accept"
383393
port_range = "1-1024"
@@ -392,6 +402,7 @@ func TestAccScalewayInstanceSecurityGroup_WithPortRange(t *testing.T) {
392402
{
393403
Config: `
394404
resource "scaleway_instance_security_group" "base" {
405+
tags = [ "test-terraform" ]
395406
inbound_rule {
396407
action = "accept"
397408
port = "22"
@@ -406,6 +417,7 @@ func TestAccScalewayInstanceSecurityGroup_WithPortRange(t *testing.T) {
406417
{
407418
Config: `
408419
resource "scaleway_instance_security_group" "base" {
420+
tags = [ "test-terraform" ]
409421
inbound_rule {
410422
action = "accept"
411423
port_range = "1-1024"
@@ -451,15 +463,6 @@ func TestAccScalewayInstanceSecurityGroup_Tags(t *testing.T) {
451463
resource.TestCheckResourceAttr("scaleway_instance_security_group.main", "tags.1", "buzz"),
452464
),
453465
},
454-
{
455-
Config: `
456-
resource "scaleway_instance_security_group" "main" {
457-
}
458-
`,
459-
Check: resource.ComposeTestCheckFunc(
460-
resource.TestCheckNoResourceAttr("scaleway_instance_security_group.main", "tags"),
461-
),
462-
},
463466
},
464467
})
465468
}
@@ -613,6 +616,7 @@ func TestAccScalewayInstanceSecurityGroup_EnableDefaultSecurity(t *testing.T) {
613616
{
614617
Config: `
615618
resource "scaleway_instance_security_group" "base" {
619+
tags = [ "test-terraform" ]
616620
enable_default_security = false
617621
}
618622
`,
@@ -623,6 +627,7 @@ func TestAccScalewayInstanceSecurityGroup_EnableDefaultSecurity(t *testing.T) {
623627
{
624628
Config: `
625629
resource "scaleway_instance_security_group" "base" {
630+
tags = [ "test-terraform" ]
626631
enable_default_security = true
627632
}
628633
`,

0 commit comments

Comments
 (0)