Skip to content

Commit 1ec62a1

Browse files
committed
fix(iot): replace ExactlyOneOf with ConflictsWith for route types
1 parent 0abaa5d commit 1ec62a1

File tree

3 files changed

+582
-532
lines changed

3 files changed

+582
-532
lines changed

internal/services/iot/routes.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,13 @@ func ResourceRoute() *schema.Resource {
5151
Description: "The Topic the route subscribes to (wildcards allowed)",
5252
},
5353
"database": {
54-
Type: schema.TypeList,
55-
MinItems: 1,
56-
MaxItems: 1,
57-
Optional: true,
58-
ForceNew: true,
59-
Description: "Database Route parameters",
60-
ExactlyOneOf: []string{
61-
iot.RouteRouteTypeDatabase.String(),
62-
iot.RouteRouteTypeRest.String(),
63-
iot.RouteRouteTypeS3.String(),
64-
},
54+
Type: schema.TypeList,
55+
MinItems: 1,
56+
MaxItems: 1,
57+
Optional: true,
58+
ForceNew: true,
59+
Description: "Database Route parameters",
60+
ConflictsWith: []string{"rest", "s3"},
6561
Elem: &schema.Resource{
6662
Schema: map[string]*schema.Schema{
6763
"query": {
@@ -105,12 +101,13 @@ func ResourceRoute() *schema.Resource {
105101
},
106102
},
107103
"rest": {
108-
Type: schema.TypeList,
109-
MinItems: 1,
110-
MaxItems: 1,
111-
Optional: true,
112-
ForceNew: true,
113-
Description: "Rest Route parameters",
104+
Type: schema.TypeList,
105+
MinItems: 1,
106+
MaxItems: 1,
107+
Optional: true,
108+
ForceNew: true,
109+
Description: "Rest Route parameters",
110+
ConflictsWith: []string{"database", "s3"},
114111
Elem: &schema.Resource{
115112
Schema: map[string]*schema.Schema{
116113
"verb": {
@@ -140,12 +137,13 @@ func ResourceRoute() *schema.Resource {
140137
},
141138
},
142139
"s3": {
143-
Type: schema.TypeList,
144-
MinItems: 1,
145-
MaxItems: 1,
146-
Optional: true,
147-
ForceNew: true,
148-
Description: "S3 Route parameters",
140+
Type: schema.TypeList,
141+
MinItems: 1,
142+
MaxItems: 1,
143+
Optional: true,
144+
ForceNew: true,
145+
Description: "S3 Route parameters",
146+
ConflictsWith: []string{"database", "rest"},
149147
Elem: &schema.Resource{
150148
Schema: map[string]*schema.Schema{
151149
"bucket_region": {

internal/services/iot/routes_test.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ func TestAccRoute_RDB(t *testing.T) {
8181
}
8282

8383
func TestAccRoute_S3(t *testing.T) {
84-
if !*acctest.UpdateCassettes {
85-
t.Skip("Skipping ObjectStorage test as this kind of resource can't be deleted before 24h")
86-
}
87-
8884
tt := acctest.NewTestTools(t)
8985
defer tt.Cleanup()
9086

@@ -101,30 +97,35 @@ func TestAccRoute_S3(t *testing.T) {
10197
Steps: []resource.TestStep{
10298
{
10399
Config: fmt.Sprintf(`
104-
resource "scaleway_object_bucket" "minimal" {
105-
name = "%s"
106-
}
100+
locals {
101+
bucket_region = "fr-par"
102+
}
107103
108-
resource "scaleway_iot_hub" "minimal" {
109-
name = "minimal"
110-
product_plan = "plan_shared"
111-
}
104+
resource "scaleway_object_bucket" "minimal" {
105+
name = "%s"
106+
region = local.bucket_region
107+
}
112108
113-
resource "scaleway_iot_route" "default" {
114-
name = "default"
115-
hub_id = scaleway_iot_hub.minimal.id
116-
topic = "#"
109+
resource "scaleway_iot_hub" "minimal" {
110+
name = "minimal"
111+
product_plan = "plan_shared"
112+
}
117113
118-
s3 {
119-
bucket_region = scaleway_object_bucket.minimal.region
120-
bucket_name = scaleway_object_bucket.minimal.name
121-
object_prefix = "foo"
122-
strategy = "per_topic"
123-
}
124-
125-
depends_on = [scaleway_object_bucket.minimal]
126-
}
127-
`, bucketName),
114+
resource "scaleway_iot_route" "default" {
115+
name = "default"
116+
hub_id = scaleway_iot_hub.minimal.id
117+
topic = "#"
118+
119+
s3 {
120+
bucket_region = local.bucket_region
121+
bucket_name = scaleway_object_bucket.minimal.name
122+
object_prefix = "foo"
123+
strategy = "per_topic"
124+
}
125+
126+
depends_on = [scaleway_object_bucket.minimal]
127+
}
128+
`, bucketName),
128129
Check: resource.ComposeTestCheckFunc(
129130
objectchecks.CheckBucketExists(tt, "scaleway_object_bucket.minimal", true),
130131
isHubPresent(tt, "scaleway_iot_hub.minimal"),

0 commit comments

Comments
 (0)