Skip to content

Commit 1e589f5

Browse files
nicolai86stack72
authored andcommitted
provider/scaleway improve bootscript data source (hashicorp#11183)
* provider/scaleway: fix bootscript tests the bootscript tests where failing because the referenced bootscript is no longer available. for now this just makes the tests pass again, next step should be to lookup a bootscript so we don't have to update the tests all the time * provider/scaleway: fix bootscript data source filter bug when providing a name only the architecture was ignoerd, which can lead to issues since some bootscript names are identical, even though the architecture is different. * provider/scaleway: remove data bootscript exact name test the test fails after some time because scaleway removes older bootscripts. let's just settle with filtered tests for now, which don't have this problem.
1 parent 4fd9012 commit 1e589f5

2 files changed

Lines changed: 6 additions & 27 deletions

File tree

builtin/providers/scaleway/data_source_scaleway_bootscript.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ func dataSourceScalewayBootscriptRead(d *schema.ResourceData, meta interface{})
8080

8181
var isMatch func(api.ScalewayBootscript) bool
8282

83+
architecture := d.Get("architecture")
8384
if name, ok := d.GetOk("name"); ok {
8485
isMatch = func(s api.ScalewayBootscript) bool {
85-
return s.Title == name.(string)
86+
architectureMatch := true
87+
if architecture != "" {
88+
architectureMatch = architecture == s.Arch
89+
}
90+
return s.Title == name.(string) && architectureMatch
8691
}
8792
} else if nameFilter, ok := d.GetOk("name_filter"); ok {
88-
architecture := d.Get("architecture")
8993
exp, err := regexp.Compile(nameFilter.(string))
9094
if err != nil {
9195
return err

builtin/providers/scaleway/data_source_scaleway_bootscript_test.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,12 @@ package scaleway
22

33
import (
44
"fmt"
5-
"regexp"
65
"testing"
76

87
"github.com/hashicorp/terraform/helper/resource"
98
"github.com/hashicorp/terraform/terraform"
109
)
1110

12-
func TestAccScalewayDataSourceBootscript_Basic(t *testing.T) {
13-
resource.Test(t, resource.TestCase{
14-
PreCheck: func() { testAccPreCheck(t) },
15-
Providers: testAccProviders,
16-
Steps: []resource.TestStep{
17-
resource.TestStep{
18-
Config: testAccCheckScalewayBootscriptConfig,
19-
Check: resource.ComposeTestCheckFunc(
20-
testAccCheckBootscriptID("data.scaleway_bootscript.debug"),
21-
resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "architecture", "x86_64"),
22-
resource.TestCheckResourceAttr("data.scaleway_bootscript.debug", "public", "true"),
23-
resource.TestMatchResourceAttr("data.scaleway_bootscript.debug", "kernel", regexp.MustCompile("4.8.3")),
24-
),
25-
},
26-
},
27-
})
28-
}
29-
3011
func TestAccScalewayDataSourceBootscript_Filtered(t *testing.T) {
3112
resource.Test(t, resource.TestCase{
3213
PreCheck: func() { testAccPreCheck(t) },
@@ -65,12 +46,6 @@ func testAccCheckBootscriptID(n string) resource.TestCheckFunc {
6546
}
6647
}
6748

68-
const testAccCheckScalewayBootscriptConfig = `
69-
data "scaleway_bootscript" "debug" {
70-
name = "x86_64 4.8.3 debug #1"
71-
}
72-
`
73-
7449
const testAccCheckScalewayBootscriptFilterConfig = `
7550
data "scaleway_bootscript" "debug" {
7651
architecture = "arm"

0 commit comments

Comments
 (0)