Skip to content

Commit 1c7d454

Browse files
authored
Merge branch 'master' into chore/bump_sdk_go
2 parents eb98c5a + 83cfa19 commit 1c7d454

File tree

455 files changed

+501811
-250265
lines changed

Some content is hidden

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

455 files changed

+501811
-250265
lines changed

.github/workflows/acceptance-tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ jobs:
1818
- block
1919
- cockpit
2020
- container
21-
- documentdb
2221
- domain
2322
- flexibleip
2423
- function
2524
- iam
2625
- instance
26+
- inference
2727
- iot
2828
- ipam
2929
- jobs
3030
- k8s
3131
- lb
3232
- marketplace
3333
- mnq
34+
- mongodb
3435
- object
3536
- rdb
3637
- redis

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
SCW_ACCESS_KEY: "SCWXXXXXXXXXXXXXFAKE"
2727
SCW_SECRET_KEY: "11111111-1111-1111-1111-111111111111"
2828
- name: Upload coverage to Codecov
29-
uses: codecov/codecov-action@v4
29+
uses: codecov/codecov-action@v5

.github/workflows/nightly.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ jobs:
1919
- block
2020
- cockpit
2121
- container
22-
- documentdb
2322
- domain
2423
- flexibleip
2524
- function
2625
- iam
26+
- inference
2727
- instance
2828
- iot
2929
- ipam
@@ -32,6 +32,7 @@ jobs:
3232
- lb
3333
- marketplace
3434
- mnq
35+
- mongodb
3536
- object
3637
- rdb
3738
- redis

.golangci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ linters:
3434
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
3535
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
3636
- gosimple #(megacheck): Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false]
37+
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase [fast: false, auto-fix: false]
3738
- govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
3839
- grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
3940
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
@@ -62,6 +63,7 @@ linters:
6263
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
6364
- staticcheck #(megacheck): Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false]
6465
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
66+
- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true]
6567
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
6668
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false]
6769
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
@@ -80,8 +82,8 @@ linters:
8082
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
8183
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
8284
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
85+
- err113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
8386
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
84-
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds [fast: false, auto-fix: false]
8587
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
8688
- forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
8789
- funlen # Tool for detection of long functions [fast: true, auto-fix: false]
@@ -90,10 +92,9 @@ linters:
9092
- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
9193
- godot # Check if comments end in a period [fast: true, auto-fix: true]
9294
- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
93-
- err113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
94-
- gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
9595
- lll # Reports long lines [fast: true, auto-fix: false]
9696
- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
97+
- mnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
9798
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
9899
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
99100
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]

cmd/tftemplate/helpers.go.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/scaleway/scaleway-sdk-go/scw"
77
)
88

9-
// newAPIWith{{.LocalityUpper}} returns a new {{.API}} API and the {{.Locality}} for a Create request
10-
func {{.API}}APIWith{{.LocalityUpper}}(d *schema.ResourceData, m interface{}) (*{{.API}}.API, scw.{{.LocalityUpper}}, error) {
9+
// NewAPIWith{{.LocalityUpper}} returns a new {{.API}} API and the {{.Locality}} for a Create request
10+
func NewAPIWith{{.LocalityUpper}}(d *schema.ResourceData, m interface{}) (*{{.API}}.API, scw.{{.LocalityUpper}}, error) {
1111
{{.API}}API := {{.API}}.NewAPI(meta.ExtractScwClient(m))
1212

1313
{{.Locality}}, err := meta.Extract{{.LocalityUpper}}(d, m)
@@ -18,8 +18,8 @@ func {{.API}}APIWith{{.LocalityUpper}}(d *schema.ResourceData, m interface{}) (*
1818
return {{.API}}API, {{.Locality}}, nil
1919
}
2020

21-
// {{.API}}APIWith{{.LocalityAdjectiveUpper}}AndID returns a new {{.API }} API with {{.Locality}} and ID extracted from the state
22-
func {{.API}}APIWith{{.LocalityUpper}}AndID(m interface{}, {{.LocalityAdjective}}ID string) (*{{.API}}.API, scw.{{.LocalityUpper}}, string, error) {
21+
// NewAPIWith{{.LocalityUpper}}AndID returns a new {{.API }} API with {{.Locality}} and ID extracted from the state
22+
func NewAPIWith{{.LocalityUpper}}AndID(m interface{}, {{.LocalityAdjective}}ID string) (*{{.API}}.API, scw.{{.LocalityUpper}}, string, error) {
2323
{{.API}}API := {{.API}}.NewAPI(meta.ExtractScwClient(m))
2424

2525
{{.Locality}}, ID, err := {{.LocalityAdjective}}.ParseID({{.LocalityAdjective}}ID)

cmd/tftemplate/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ var (
2424
datasourceTemplateFile string
2525
//go:embed datasource_test.go.tmpl
2626
datasourceTestTemplateFile string
27+
//go:embed sweep_test.go.tmpl
28+
resourceSweepTemplateFile string
29+
//go:embed sweep.go.tmpl
30+
resourceSweepTestTemplateFile string
2731
)
2832

2933
var resourceQS = []*survey.Question{
@@ -66,6 +70,13 @@ var resourceQS = []*survey.Question{
6670
Default: true,
6771
},
6872
},
73+
{
74+
Name: "sweep",
75+
Prompt: &survey.Confirm{
76+
Message: "Generate sweeper ? Will be added to ../../internal/services/{api}/sweep.go",
77+
Default: true,
78+
},
79+
},
6980
}
7081

7182
func contains[T comparable](slice []T, expected T) bool {
@@ -86,6 +97,7 @@ func main() {
8697
Locality string
8798
Helpers bool
8899
Waiters bool
100+
Sweep bool
89101
}{}
90102
err := survey.Ask(resourceQS, &resourceInput)
91103
if err != nil {
@@ -126,6 +138,18 @@ func main() {
126138
Skip: !resourceInput.Waiters,
127139
Append: true,
128140
},
141+
{
142+
FileName: fmt.Sprintf("../../internal/services/%s/testfuncs/sweep.go", resourceData.API),
143+
TemplateFile: resourceSweepTemplateFile,
144+
Skip: !contains(resourceInput.Targets, "resource"),
145+
Append: true,
146+
},
147+
{
148+
FileName: fmt.Sprintf("../../internal/services/%s/sweep_test.go", resourceData.API),
149+
TemplateFile: resourceSweepTestTemplateFile,
150+
Skip: !contains(resourceInput.Targets, "resource"),
151+
Append: true,
152+
},
129153
}
130154

131155
for _, tmpl := range templates {

cmd/tftemplate/models/resource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package models
22

33
import (
4-
"golang.org/x/text/cases"
5-
"golang.org/x/text/language"
64
"strings"
75
"unicode"
6+
7+
"golang.org/x/text/cases"
8+
"golang.org/x/text/language"
89
)
910

1011
type ResourceTemplate struct {

cmd/tftemplate/resource.go.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData,
4949

5050
req := &{{ .API }}.Create{{ .ResourceClean }}Request{
5151
{{.LocalityUpper}}: {{.Locality}},
52-
ProjectID: types.ExpandStringPtr(d.Get("project_id").(string)),
52+
ProjectID: d.Get("project_id").(string),
5353
Name: types.ExpandOrGenerateString(d.Get("name").(string), "{{ .ResourceCleanLow }}"),
5454
}
5555

@@ -71,7 +71,7 @@ func Resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData,
7171
}
7272

7373
func Resource{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
74-
api, id, zone, err := NewAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
74+
api,{{.Locality}}, id, err := newAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
7575
if err != nil {
7676
return diag.FromErr(err)
7777
}
@@ -101,7 +101,7 @@ func Resource{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, m
101101
}
102102

103103
func Resource{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
104-
api, {{ .Locality }}, id, err := NewAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
104+
api, {{ .Locality }}, id, err := newAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
105105
if err != nil {
106106
return diag.FromErr(err)
107107
}
@@ -132,7 +132,7 @@ func Resource{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData,
132132
}
133133

134134
func Resource{{ .Resource }}Delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
135-
api, {{ .Locality }}, id, err := NewAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
135+
api, {{ .Locality }}, id, err := newAPIWith{{ .LocalityUpper }}AndID(m, d.Id())
136136
if err != nil {
137137
return diag.FromErr(err)
138138
}

cmd/tftemplate/resource_test.go.tmpl

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{- /*gotype: tftemplate/models.ResourceTemplate*/ -}}
2-
package scaleway
2+
package {{.API}}_test
33

44
import (
55
"fmt"
@@ -10,74 +10,40 @@ import (
1010
"github.com/scaleway/scaleway-sdk-go/scw"
1111
)
1212

13-
func init() {
14-
resource.AddTestSweepers("scaleway_{{ .ResourceHCL }}", &resource.Sweeper{
15-
Name: "scaleway_{{ .ResourceHCL }}",
16-
F: testSweep{{ .Resource }},
17-
})
18-
}
19-
20-
func testSweep{{ .Resource }}(_ string) error {
21-
return sweep{{.LocalityUpper}}s((&{{ .API }}.API{}).{{ .LocalityUpper }}s(), func(scwClient *scw.Client, {{ .Locality }} scw.{{.LocalityUpper}}) error {
22-
{{ .API }}API := {{ .API }}.NewAPI(scwClient)
23-
l.Debugf("sweeper: destroying the {{ .API }} {{ .ResourceCleanLow }}s in (%s)", {{.Locality}})
24-
list{{.ResourceClean}}s, err := {{.API}}API.List{{.ResourceClean}}s(
25-
&{{.API}}.List{{.ResourceClean}}sRequest{
26-
{{.LocalityUpper}}: {{.Locality}},
27-
}, scw.WithAllPages())
28-
if err != nil {
29-
return fmt.Errorf("error listing {{.ResourceCleanLow}} in (%s) in sweeper: %s", {{.Locality}}, err)
30-
}
3113

32-
for _, {{.ResourceCleanLow}} := range list{{.ResourceClean}}s.{{.ResourceClean}}s {
33-
_, err := {{.API}}API.Delete{{.ResourceClean}}(&{{.API}}.Delete{{.ResourceClean}}Request{
34-
{{.ResourceClean}}ID: {{.ResourceCleanLow}}.ID,
35-
{{.LocalityUpper}}: {{.Locality}},
36-
})
37-
if err != nil {
38-
l.Debugf("sweeper: error (%s)", err)
39-
40-
return fmt.Errorf("error deleting {{.ResourceCleanLow}} in sweeper: %s", err)
41-
}
42-
}
43-
44-
return nil
45-
})
46-
}
4714

4815
func TestAcc{{.Resource}}_Basic(t *testing.T) {
4916
tt := acctest.NewTestTools(t)
5017
defer tt.Cleanup()
5118

5219
resource.ParallelTest(t, resource.TestCase{
53-
PreCheck: func() { testAccPreCheck(t) },
20+
PreCheck: func() { acctest.PreCheck(t) },
5421
ProviderFactories: tt.ProviderFactories,
5522
CheckDestroy: testAccCheck{{.Resource}}Destroy(tt),
5623
Steps: []resource.TestStep{
5724
{
5825
Config: `
59-
resource scaleway_{{.ResourceHCL}} main {
26+
resource "scaleway_{{.API}}_{{.ResourceHCL}}" "main" {
6027
name = "test-{{.API}}-{{ .ResourceCleanLow}}-basic"
6128
}
6229
`,
6330
Check: resource.ComposeTestCheckFunc(
64-
testAccCheck{{.Resource}}Exists(tt, "scaleway_{{.ResourceHCL}}.main"),
65-
testCheckResourceAttrUUID("scaleway_{{.ResourceHCL}}.main", "id"),
66-
resource.TestCheckResourceAttr("scaleway_{{.ResourceHCL}}.main", "name", "test-{{.API}}-{{ .ResourceCleanLow}}-basic"),
31+
testAccCheck{{.Resource}}Exists(tt, "scaleway_{{.API}}_{{.ResourceHCL}}.main"),
32+
resource.TestCheckResourceAttr("scaleway_{{.API}}_{{.ResourceHCL}}.main", "name", "test-{{.API}}-{{ .ResourceCleanLow}}-basic"),
6733
),
6834
},
6935
},
7036
})
7137
}
7238

73-
func testAccCheck{{.Resource}}Exists(tt *TestTools, n string) resource.TestCheckFunc {
39+
func testAccCheck{{.Resource}}Exists(tt *acctest.TestTools, n string) resource.TestCheckFunc {
7440
return func(state *terraform.State) error {
7541
rs, ok := state.RootModule().Resources[n]
7642
if !ok {
7743
return fmt.Errorf("resource not found: %s", n)
7844
}
7945

80-
api, {{.Locality}}, id, err := {{.API}}APIWith{{.LocalityUpper}}AndID(tt.Meta, rs.Primary.ID)
46+
api, {{.Locality}}, id, err := newAPIWith{{.LocalityUpper}}AndID(tt.Meta, rs.Primary.ID)
8147
if err != nil {
8248
return err
8349
}
@@ -95,14 +61,14 @@ func testAccCheck{{.Resource}}Exists(tt *TestTools, n string) resource.TestCheck
9561
}
9662
}
9763

98-
func testAccCheck{{.Resource}}Destroy(tt *TestTools) resource.TestCheckFunc {
64+
func testAccCheck{{.Resource}}Destroy(tt *acctest.TestTools) resource.TestCheckFunc {
9965
return func(state *terraform.State) error {
10066
for _, rs := range state.RootModule().Resources {
101-
if rs.Type != "scaleway_{{.ResourceHCL}}" {
67+
if rs.Type != "scaleway_{{.API}}_{{.ResourceHCL}}" {
10268
continue
10369
}
10470

105-
api, {{.Locality}}, id, err := {{.API}}APIWith{{.LocalityUpper}}AndID(tt.Meta, rs.Primary.ID)
71+
api, {{.Locality}}, id, err := newAPIWith{{.LocalityUpper}}AndID(tt.Meta, rs.Primary.ID)
10672
if err != nil {
10773
return err
10874
}
@@ -116,7 +82,7 @@ func testAccCheck{{.Resource}}Destroy(tt *TestTools) resource.TestCheckFunc {
11682
return fmt.Errorf("{{.API}} {{.ResourceCleanLow}} (%s) still exists", rs.Primary.ID)
11783
}
11884

119-
if !is404Error(err) {
85+
if !httperrors.Is404(err) {
12086
return err
12187
}
12288
}

cmd/tftemplate/sweep.go.tmpl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- /*gotype: tftemplate/models.ResourceTemplate*/ -}}
2+
package {{.API}}testfuncs
3+
4+
import (
5+
"fmt"
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10+
"github.com/scaleway/scaleway-sdk-go/scw"
11+
)
12+
13+
func testSweep{{ .Resource }}(_ string) error {
14+
return acctest.Sweep{{.LocalityUpper}}s((&{{ .API }}.API{}).{{ .LocalityUpper }}s(), func(scwClient *scw.Client, {{ .Locality }} scw.{{.LocalityUpper}}) error {
15+
{{ .API }}API := {{ .API }}.NewAPI(scwClient)
16+
logging.L.Debugf("sweeper: destroying the {{ .API }} {{ .ResourceCleanLow }}s in (%s)", {{.Locality}})
17+
list{{.ResourceClean}}s, err := {{.API}}API.List{{.ResourceClean}}s(
18+
&{{.API}}.List{{.ResourceClean}}sRequest{
19+
{{.LocalityUpper}}: {{.Locality}},
20+
}, scw.WithAllPages())
21+
if err != nil {
22+
return fmt.Errorf("error listing {{.ResourceCleanLow}} in (%s) in sweeper: %s", {{.Locality}}, err)
23+
}
24+
25+
for _, {{.ResourceCleanLow}} := range list{{.ResourceClean}}s.{{.ResourceClean}}s {
26+
_, err := {{.API}}API.Delete{{.ResourceClean}}(&{{.API}}.Delete{{.ResourceClean}}Request{
27+
{{.ResourceClean}}ID: {{.ResourceCleanLow}}.ID,
28+
{{.LocalityUpper}}: {{.Locality}},
29+
})
30+
if err != nil {
31+
logging.L.Debugf("sweeper: error (%s)", err)
32+
33+
return fmt.Errorf("error deleting {{.ResourceCleanLow}} in sweeper: %s", err)
34+
}
35+
}
36+
37+
return nil
38+
})
39+
}

0 commit comments

Comments
 (0)