Skip to content

Commit 11e8064

Browse files
authored
chore: migrate services to their own packages (#2466)
* chore: migrate provider to its own package * FIx * Fix IAM * fix iot * Fix * Fix * Fix block * Fix redis * Fix rdb * Fix mnq * Fix instance * fix tem * Fix * fix az * cleanup * Fix registry and tem * Fix * Fix webhosting * fix rdb * fix documentdb * fix cassettes validation * Fix instance * FIx * Fix * Fix * Fix wrong indentation * Fix cassette format * go mod tidy * fix * fix nightly tests
1 parent c36bb57 commit 11e8064

File tree

1,327 files changed

+98733
-86823
lines changed

Some content is hidden

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

1,327 files changed

+98733
-86823
lines changed

.github/contributing/acceptance_test.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ This keeps the tests readable, and allows reuse of assertion functions across di
9898
The definition of a complete test looks like this:
9999

100100
```go
101-
func TestAccScalewayInstanceServerImport(t *testing.T) {
101+
func TestAccServerImport(t *testing.T) {
102102
tt := acctest.NewTestTools(t)
103103
defer tt.Cleanup()
104104
resource.ParallelTest(t, resource.TestCase{
105105
PreCheck: func() { testAccPreCheck(t) },
106106
ProviderFactories: tt.ProviderFactories,
107-
CheckDestroy: testAccCheckScalewayInstanceServerDestroy(tt),
107+
CheckDestroy: instancechecks.CheckServerDestroy(tt),
108108
Steps: []resource.TestStep{
109109
{
110110
Config: `
@@ -145,14 +145,14 @@ When executing the test, the following steps are taken for each `TestStep`:
145145
For example, to verify that the `scaleway_instance_server` described above was created successfully, a test function like this is used:
146146
147147
```go
148-
func testAccCheckScalewayInstanceServerExists(tt *TestTools, n string) resource.TestCheckFunc {
148+
func testAccCheckInstanceServerExists(tt *TestTools, n string) resource.TestCheckFunc {
149149
return func(state *terraform.State) error {
150150
rs, ok := state.RootModule().Resources[n]
151151
if !ok {
152152
return fmt.Errorf("resource not found: %s", n)
153153
}
154154
155-
instanceAPI, zone, ID, err := scaleway.InstanceAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
155+
instanceAPI, zone, ID, err := InstanceAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
156156
if err != nil {
157157
return err
158158
}
@@ -183,14 +183,14 @@ When executing the test, the following steps are taken for each `TestStep`:
183183
The code to ensure that the `scaleway_instance_server` shown above has been destroyed looks like this:
184184
185185
```go
186-
func testAccCheckScalewayInstanceServerDestroy(tt *TestTools) resource.TestCheckFunc {
186+
func instancechecks.CheckServerDestroy(tt *TestTools) resource.TestCheckFunc {
187187
return func(state *terraform.State) error {
188188
for _, rs := range s.RootModule().Resources {
189189
if rs.Type != "scaleway_instance_server" {
190190
continue
191191
}
192192
193-
instanceAPI, zone, ID, err := scaleway.InstanceAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
193+
instanceAPI, zone, ID, err := InstanceAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
194194
if err != nil {
195195
return err
196196
}

.github/contributing/common_reviews_items.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ Below are style-based items that _may_ be noted during review and are recommende
5656

5757
Below are required items that will be noted during submission review and prevent immediate merging:
5858

59-
- [ ] __Implements CheckDestroy__: Resource testing should include a `CheckDestroy` function (typically named `testAccCheckScaleway{SERVICE}{RESOURCE}Destroy`) that calls the API to verify that the Terraform resource has been deleted or disassociated as appropriate.
59+
- [ ] __Implements CheckDestroy__: Resource testing should include a `CheckDestroy` function (typically named `testAccCheck{SERVICE}{RESOURCE}Destroy`) that calls the API to verify that the Terraform resource has been deleted or disassociated as appropriate.
6060
More information about `CheckDestroy` functions can be found in the [Extending Terraform TestCase documentation](https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy).
61-
- [ ] __Implements Exists Check Function__: Resource testing should include a `TestCheckFunc` function (typically named `testAccCheckScaleway{SERVICE}{RESOURCE}Exists`) that calls the API to verify that the Terraform resource has been created or associated as appropriate.
61+
- [ ] __Implements Exists Check Function__: Resource testing should include a `TestCheckFunc` function (typically named `testAccCheck{SERVICE}{RESOURCE}Exists`) that calls the API to verify that the Terraform resource has been created or associated as appropriate.
6262
Preferably, this function will also accept a pointer to an API object representing the Terraform resource from the API response that can be set for potential usage in later `TestCheckFunc`.
6363
More information about these functions can be found in the [Extending Terraform Custom Check Functions documentation](https://www.terraform.io/docs/extend/testing/acceptance-tests/testcase.html#checkdestroy).
6464
- [ ] __Excludes Provider Declarations__: Test configurations should not include `provider "scaleway" {...}` declarations.

.github/workflows/acceptance-tests.yaml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,37 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
products:
13-
- Account
14-
- AppleSilicon
15-
- Baremetal
16-
- Billing
17-
- Block
18-
- Cockpit
19-
- Container
20-
- Domain
21-
- DocumentDB
22-
- Function
23-
- Iam
24-
- Instance
25-
- Iot
26-
- IPAM
27-
- Job
28-
- K8S
29-
- Lb
30-
- Marketplace
31-
- MNQ
32-
- Object
33-
- Rdb
34-
- Redis
35-
- Registry
36-
- Secret
37-
- ServerlessSQLDB
38-
- Tem
39-
- VPC
13+
- account
14+
- applesilicon
15+
- az
16+
- baremetal
17+
- billing
18+
- block
19+
- cockpit
20+
- container
21+
- documentdb
22+
- domain
23+
- flexibleip
24+
- function
25+
- iam
26+
- instance
27+
- iot
28+
- ipam
29+
- jobs
30+
- k8s
31+
- lb
32+
- marketplace
33+
- mnq
34+
- object
35+
- rdb
36+
- redis
37+
- registry
38+
- sdb
39+
- secret
40+
- tem
41+
- vpc
42+
- vpcgw
43+
- webhosting
4044
runs-on: ubuntu-latest
4145
steps:
4246
- name: Install Go
@@ -46,7 +50,7 @@ jobs:
4650
- name: Checkout
4751
uses: actions/checkout@v3
4852
- name: Run Acceptance Tests
49-
run: go test -v ./... -timeout=2h -run "TestAccScaleway(DataSource)?${{ matrix.products }}.*"
53+
run: go test -v ./internal/services/${{ matrix.products }} -timeout=2h
5054
env:
5155
TF_LOG: DEBUG
5256
TF_ACC: 1

.github/workflows/nightly.yml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,37 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
products:
14-
- Account
15-
- AppleSilicon
16-
- Baremetal
17-
- Billing
18-
- Block
19-
- Cockpit
20-
- Domain
21-
- DocumentDB
22-
- Function
23-
- Container
24-
- Iam
25-
- Instance
26-
- Iot
27-
- IPAM
28-
- Job
29-
- K8S
30-
- Lb
31-
- Marketplace
32-
- MNQ
33-
- Object
34-
- Rdb
35-
- Redis
36-
- Registry
37-
- Secret
38-
- ServerlessSQLDB
39-
- Tem
40-
- VPC
14+
- account
15+
- applesilicon
16+
- az
17+
- baremetal
18+
- billing
19+
- block
20+
- cockpit
21+
- container
22+
- documentdb
23+
- domain
24+
- flexibleip
25+
- function
26+
- iam
27+
- instance
28+
- iot
29+
- ipam
30+
- jobs
31+
- k8s
32+
- lb
33+
- marketplace
34+
- mnq
35+
- object
36+
- rdb
37+
- redis
38+
- registry
39+
- sdb
40+
- secret
41+
- tem
42+
- vpc
43+
- vpcgw
44+
- webhosting
4145
runs-on: ubuntu-latest
4246
steps:
4347
- name: Install Go
@@ -47,7 +51,7 @@ jobs:
4751
- name: Checkout
4852
uses: actions/checkout@v3
4953
- name: Run Acceptance Tests
50-
run: go test -v ./... -timeout=4h -run "TestAccScaleway(DataSource)?${{ matrix.products }}.*"
54+
run: go test -v ./internal/services/${{ matrix.products }} -timeout=4h
5155
env:
5256
TF_LOG: DEBUG
5357
# https://www.terraform.io/docs/extend/testing/acceptance-tests/index.html#running-acceptance-tests
@@ -71,7 +75,7 @@ jobs:
7175
"type": "section",
7276
"text": {
7377
"type": "mrkdwn",
74-
"text": "'"Nightly workflow failed: <https://github.com/scaleway/terraform-provider-scaleway/actions/runs/${GITHUB_RUN_ID}|${FAILED_PRODUCT}>"'"
78+
"text": "'"Terraform Nightly workflow failed: <https://github.com/scaleway/terraform-provider-scaleway/actions/runs/${GITHUB_RUN_ID}|${FAILED_PRODUCT}>"'"
7579
}
7680
}
7781
]

.github/workflows/tfproviderlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Install tfproviderlint
1717
run: go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
1818
- name: Run tfproviderlint
19-
run: tfproviderlint -R014=false ./...
19+
run: tfproviderlint -R014=false -AT001.ignored-filename-suffixes=_data_source_test.go ./...
2020
tfproviderdocs:
2121
runs-on: ubuntu-latest
2222
steps:

cmd/tftemplate/datasource.go.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
99
)
1010

11-
func DataSourceScaleway{{.Resource}}() *schema.Resource {
11+
func DataSource{{.Resource}}() *schema.Resource {
1212
// Generate datasource schema from resource
13-
dsSchema := datasourceSchemaFromResourceSchema(resourceScaleway{{.Resource}}().Schema)
13+
dsSchema := datasourceSchemaFromResourceSchema(Resource{{.Resource}}().Schema)
1414

1515
addOptionalFieldsToSchema(dsSchema, "name", "{{.Locality}}")
1616

@@ -24,12 +24,12 @@ func DataSourceScaleway{{.Resource}}() *schema.Resource {
2424
dsSchema["project_id"].Optional = true
2525

2626
return &schema.Resource{
27-
ReadContext: dataSourceScaleway{{.Resource}}Read,
27+
ReadContext: DataSource{{.Resource}}Read,
2828
Schema: dsSchema,
2929
}
3030
}
3131

32-
func dataSourceScaleway{{.Resource}}Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
32+
func DataSource{{.Resource}}Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
3333
api, {{.Locality}}, err := {{.API}}APIWith{{.LocalityUpper}}(d, m)
3434
if err != nil {
3535
return diag.FromErr(err)
@@ -65,7 +65,7 @@ func dataSourceScaleway{{.Resource}}Read(ctx context.Context, d *schema.Resource
6565
return diag.FromErr(err)
6666
}
6767

68-
diags := resourceScaleway{{.Resource}}Read(ctx, d, m)
68+
diags := Resource{{.Resource}}Read(ctx, d, m)
6969
if diags != nil {
7070
return append(diags, diag.Errorf("failed to read {{.ResourceCleanLow}} state")...)
7171
}

cmd/tftemplate/datasource_test.go.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
88
)
99

10-
func TestAccScalewayDataSource{{.Resource}}_Basic(t *testing.T) {
10+
func TestAccDataSource{{.Resource}}_Basic(t *testing.T) {
1111
tt := acctest.NewTestTools(t)
1212
defer tt.Cleanup()
1313
resource.ParallelTest(t, resource.TestCase{
1414
PreCheck: func() { testAccPreCheck(t) },
1515
ProviderFactories: tt.ProviderFactories,
1616
CheckDestroy: resource.ComposeTestCheckFunc(
17-
testAccCheckScaleway{{.Resource}}Destroy(tt),
17+
testAccCheck{{.Resource}}Destroy(tt),
1818
),
1919
Steps: []resource.TestStep{
2020
{
@@ -32,7 +32,7 @@ func TestAccScalewayDataSource{{.Resource}}_Basic(t *testing.T) {
3232
}
3333
`,
3434
Check: resource.ComposeTestCheckFunc(
35-
testAccCheckScaleway{{.Resource}}Exists(tt, "scaleway_{{.ResourceHCL}}.main"),
35+
testAccCheck{{.Resource}}Exists(tt, "scaleway_{{.ResourceHCL}}.main"),
3636

3737
resource.TestCheckResourceAttrPair("scaleway_{{.ResourceHCL}}.main", "name", "data.scaleway_{{.ResourceHCL}}.find_by_name", "name"),
3838
resource.TestCheckResourceAttrPair("scaleway_{{.ResourceHCL}}.main", "name", "data.scaleway_{{.ResourceHCL}}.find_by_id", "name"),

cmd/tftemplate/resource.go.tmpl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"github.com/scaleway/scaleway-sdk-go/scw"
1010
)
1111

12-
func ResourceScaleway{{ .Resource }}() *schema.Resource {
12+
func Resource{{ .Resource }}() *schema.Resource {
1313
return &schema.Resource{
14-
CreateContext: resourceScaleway{{ .Resource }}Create,
15-
ReadContext: resourceScaleway{{ .Resource }}Read,
16-
UpdateContext: resourceScaleway{{ .Resource }}Update,
17-
DeleteContext: resourceScaleway{{ .Resource }}Delete,
14+
CreateContext: Resource{{ .Resource }}Create,
15+
ReadContext: Resource{{ .Resource }}Read,
16+
UpdateContext: Resource{{ .Resource }}Update,
17+
DeleteContext: Resource{{ .Resource }}Delete,
1818
Importer: &schema.ResourceImporter{
1919
StateContext: schema.ImportStatePassthroughContext,
2020
},
@@ -28,12 +28,12 @@ func ResourceScaleway{{ .Resource }}() *schema.Resource {
2828
Description: "The {{ .ResourceCleanLow }} name",
2929
},
3030
"{{ .Locality }}": {{ .Locality }}Schema(),
31-
"project_id": projectIDSchema(),
31+
"project_id": account.ProjectIDSchema(),
3232
},
3333
}
3434
}
3535

36-
func resourceScaleway{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
36+
func Resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
3737
api, {{ .Locality }}, err := {{ .API }}APIWith{{ .LocalityUpper }}(d, m)
3838
if err != nil {
3939
return diag.FromErr(err)
@@ -57,10 +57,10 @@ func resourceScaleway{{ .Resource }}Create(ctx context.Context, d *schema.Resour
5757
}
5858
{{end}}
5959

60-
return resourceScaleway{{ .Resource }}Read(ctx, d, m)
60+
return Resource{{ .Resource }}Read(ctx, d, m)
6161
}
6262

63-
func resourceScaleway{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
63+
func Resource{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
6464
api, {{ .Locality }}, id, err := {{ .API }}APIWith{{ .LocalityUpper }}AndID(m, d.Id())
6565
if err != nil {
6666
return diag.FromErr(err)
@@ -88,7 +88,7 @@ func resourceScaleway{{ .Resource }}Read(ctx context.Context, d *schema.Resource
8888
return nil
8989
}
9090

91-
func resourceScaleway{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
91+
func Resource{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
9292
api, {{ .Locality }}, id, err := {{ .API }}APIWith{{ .LocalityUpper }}AndID(m, d.Id())
9393
if err != nil {
9494
return diag.FromErr(err)
@@ -116,10 +116,10 @@ func resourceScaleway{{ .Resource }}Update(ctx context.Context, d *schema.Resour
116116
return diag.FromErr(err)
117117
}
118118

119-
return resourceScaleway{{ .Resource }}Read(ctx, d, m)
119+
return Resource{{ .Resource }}Read(ctx, d, m)
120120
}
121121

122-
func resourceScaleway{{ .Resource }}Delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
122+
func Resource{{ .Resource }}Delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
123123
api, {{ .Locality }}, id, err := {{ .API }}APIWith{{ .LocalityUpper }}AndID(m, d.Id())
124124
if err != nil {
125125
return diag.FromErr(err)

0 commit comments

Comments
 (0)