Skip to content

Commit 36c4cac

Browse files
authored
feat(instance_server): prevent usage of routed_ip_enabled as false (#2763)
* feat(instance_server): prevent usage of routed_ip_enabled as false * feat(instance_ip): prevent usage of nat ips * correct message * add documentation link * lint
1 parent 4863479 commit 36c4cac

10 files changed

+638
-10714
lines changed

internal/services/instance/ip.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package instance
33
import (
44
"context"
55

6+
"github.com/hashicorp/go-cty/cty"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -42,6 +43,18 @@ func ResourceIP() *schema.Resource {
4243
Computed: true,
4344
Optional: true,
4445
Description: "The type of instance IP",
46+
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
47+
if i.(string) == "nat" {
48+
return diag.Diagnostics{{
49+
Severity: diag.Error,
50+
Summary: "NAT IPs are not supported anymore",
51+
Detail: "Remove explicit nat configuration, migrate to routed ips or downgrade terraform.\nLearn more about migration: https://www.scaleway.com/en/docs/compute/instances/how-to/migrate-routed-ips/",
52+
AttributePath: path,
53+
}}
54+
}
55+
56+
return nil
57+
},
4558
},
4659
"reverse": {
4760
Type: schema.TypeString,

internal/services/instance/ip_test.go

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -98,116 +98,6 @@ func TestAccIP_Tags(t *testing.T) {
9898
})
9999
}
100100

101-
func TestAccIP_RoutedMigrate(t *testing.T) {
102-
tt := acctest.NewTestTools(t)
103-
defer tt.Cleanup()
104-
105-
resource.ParallelTest(t, resource.TestCase{
106-
ProviderFactories: tt.ProviderFactories,
107-
CheckDestroy: instancechecks.IsIPDestroyed(tt),
108-
Steps: []resource.TestStep{
109-
{
110-
Config: `
111-
resource "scaleway_instance_ip" "main" {
112-
type = "nat"
113-
}
114-
`,
115-
Check: resource.ComposeTestCheckFunc(
116-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
117-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "nat"),
118-
),
119-
},
120-
{
121-
Config: `
122-
resource "scaleway_instance_ip" "main" {
123-
type = "nat"
124-
}
125-
resource "scaleway_instance_ip" "copy" {
126-
}
127-
`,
128-
Check: resource.ComposeTestCheckFunc(
129-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
130-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.copy"),
131-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "nat"),
132-
resource.TestCheckResourceAttr("scaleway_instance_ip.copy", "type", "nat"),
133-
resource.TestCheckResourceAttrPair("scaleway_instance_ip.main", "id", "scaleway_instance_ip.copy", "id"),
134-
),
135-
ResourceName: "scaleway_instance_ip.copy",
136-
ImportState: true,
137-
ImportStateIdFunc: func(state *terraform.State) (string, error) {
138-
return state.RootModule().Resources["scaleway_instance_ip.main"].Primary.ID, nil
139-
},
140-
ImportStatePersist: true,
141-
},
142-
{
143-
Config: `
144-
resource "scaleway_instance_ip" "main" {
145-
type = "routed_ipv4"
146-
}
147-
resource "scaleway_instance_ip" "copy" {
148-
}
149-
`,
150-
Check: resource.ComposeTestCheckFunc(
151-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
152-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.copy"),
153-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "routed_ipv4"),
154-
resource.TestCheckResourceAttrPair("scaleway_instance_ip.main", "id", "scaleway_instance_ip.copy", "id"),
155-
),
156-
},
157-
{
158-
// After the main IP migrated, we check that there is no ForceNew on the copy
159-
// This check that the ip is not deleted if the migration is done outside terraform
160-
RefreshState: true,
161-
Check: resource.ComposeTestCheckFunc(
162-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
163-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.copy"),
164-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "routed_ipv4"),
165-
resource.TestCheckResourceAttr("scaleway_instance_ip.copy", "type", "routed_ipv4"),
166-
resource.TestCheckResourceAttrPair("scaleway_instance_ip.main", "id", "scaleway_instance_ip.copy", "id"),
167-
),
168-
},
169-
},
170-
})
171-
}
172-
173-
func TestAccIP_RoutedDowngrade(t *testing.T) {
174-
tt := acctest.NewTestTools(t)
175-
defer tt.Cleanup()
176-
177-
resource.ParallelTest(t, resource.TestCase{
178-
ProviderFactories: tt.ProviderFactories,
179-
CheckDestroy: instancechecks.IsIPDestroyed(tt),
180-
Steps: []resource.TestStep{
181-
{
182-
Config: `
183-
resource "scaleway_instance_ip" "main" {
184-
type = "routed_ipv4"
185-
}
186-
`,
187-
Check: resource.ComposeTestCheckFunc(
188-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
189-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "routed_ipv4"),
190-
isIPValid("scaleway_instance_ip.main", "address"),
191-
isIPCIDRValid("scaleway_instance_ip.main", "prefix"),
192-
),
193-
},
194-
{
195-
Config: `
196-
resource "scaleway_instance_ip" "main" {
197-
type = "nat"
198-
}
199-
`,
200-
Check: resource.ComposeTestCheckFunc(
201-
instancechecks.CheckIPExists(tt, "scaleway_instance_ip.main"),
202-
resource.TestCheckResourceAttr("scaleway_instance_ip.main", "type", "nat"),
203-
isIPValid("scaleway_instance_ip.main", "address"),
204-
isIPCIDRValid("scaleway_instance_ip.main", "prefix"),
205-
),
206-
},
207-
},
208-
})
209-
}
210-
211101
func TestAccIP_RoutedIPV6(t *testing.T) {
212102
tt := acctest.NewTestTools(t)
213103
defer tt.Cleanup()

internal/services/instance/server.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ func ResourceServer() *schema.Resource {
229229
"ipv6_prefix_length": {
230230
Type: schema.TypeInt,
231231
Computed: true,
232+
Deprecated: "Please use a scaleway_instance_ip with a `routed_ipv6` type",
232233
Description: "The IPv6 prefix length routed to the server.",
233234
},
234235
"enable_dynamic_ip": {
@@ -338,9 +339,25 @@ func ResourceServer() *schema.Resource {
338339
},
339340
"routed_ip_enabled": {
340341
Type: schema.TypeBool,
341-
Description: "If server supports routed IPs, default to true if public_ips is used",
342+
Description: "If server supports routed IPs, default to true",
342343
Optional: true,
343344
Computed: true,
345+
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
346+
if i == nil {
347+
return nil
348+
}
349+
if !i.(bool) {
350+
return diag.Diagnostics{{
351+
Severity: diag.Error,
352+
Summary: "NAT IPs are not supported anymore",
353+
Detail: "Remove explicit disabling, enable it or downgrade terraform.\nLearn more about migration: https://www.scaleway.com/en/docs/compute/instances/how-to/migrate-routed-ips/",
354+
AttributePath: path,
355+
}}
356+
}
357+
358+
return nil
359+
},
360+
Deprecated: "Routed IP is the default configuration, it should always be true",
344361
},
345362
"zone": zonal.Schema(),
346363
"organization_id": account.OrganizationIDSchema(),

0 commit comments

Comments
 (0)