Skip to content

Commit 545b916

Browse files
authored
Merge branch 'master' into timeout
2 parents e184ca7 + 7b7cdec commit 545b916

31 files changed

+10350
-3211
lines changed

.github/workflows/golangci-lint.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010
- name: golangci-lint
11-
uses: golangci/golangci-lint-action@v1
11+
uses: golangci/golangci-lint-action@v2
1212
with:
1313
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
14-
version: v1.27
15-
args: "--timeout=1m"
14+
version: v1.32.2
15+
args: --timeout 5m
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
page_title: "Scaleway: scaleway_vpc_private_network"
3+
description: |-
4+
Get information about Scaleway VPC Private Networks.
5+
---
6+
7+
# scaleway_vpc_private_network
8+
9+
Gets information about a private network.
10+
11+
## Example Usage
12+
13+
N/A, the usage will be meaningful in the next releases of VPC.
14+
15+
## Argument Reference
16+
17+
* `name` - (Required) Exact name of the private network.
18+
19+
## Attributes Reference
20+
21+
`id` is set to the ID of the found private network. Addition attributes are
22+
exported.
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
page_title: "Scaleway: scaleway_instance_private_nic"
3+
description: |-
4+
Manages Scaleway Compute Instance Private NICs.
5+
---
6+
7+
# scaleway_instance_private_nic
8+
9+
Creates and manages Scaleway Instance Private NICs. For more information, see
10+
[the documentation](https://developers.scaleway.com/en/products/instance/api/#private-nics-a42eea).
11+
12+
## Example
13+
14+
```hcl
15+
resource "scaleway_instance_private_nic" "pnic01" {
16+
server_id = "fr-par-1/11111111-1111-1111-1111-111111111111"
17+
private_network_id = "fr-par-1/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
18+
}
19+
```
20+
21+
## Arguments Reference
22+
23+
The following arguments are required:
24+
25+
- `server_id` - (Required) The ID of the server associated with.
26+
- `private_network_id` - (Required) The ID of the private network attached to.
27+
28+
## Attributes Reference
29+
30+
In addition to all above arguments, the following attributes are exported:
31+
32+
- `id` - The ID of the private NIC.
33+
34+
## Import
35+
36+
Private NICs can be imported using the `{zone}/{server_id}/{private_nic_id}`, e.g.
37+
38+
```bash
39+
$ terraform import scaleway_instance_volume.server_volume fr-par-1/11111111-1111-1111-1111-111111111111/22222222-2222-2222-2222-222222222222
40+
```

docs/resources/lb_backend.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The following arguments are supported:
4949
- `forward_protocol` - (Required) Backend protocol. Possible values are: `tcp` or `http`.
5050
- `name` - (Optional) The name of the load-balancer backend.
5151
- `forward_port` - (Required) User sessions will be forwarded to this port of backend servers.
52-
- `forward_port_algorithm` - (Default: `roundrobin`) Load balancing algorithm. Possible values are: `roundrobin` and `leastconn`.
52+
- `forward_port_algorithm` - (Default: `roundrobin`) Load balancing algorithm. Possible values are: `roundrobin`, `leastconn` and `first`.
5353
- `sticky_sessions` - (Default: `none`) Load balancing algorithm. Possible values are: `none`, `cookie` and `table`.
5454
- `sticky_sessions_cookie_name` - (Optional) Cookie name for for sticky sessions. Only applicable when sticky_sessions is set to `cookie`.
5555
- `server_ips` - (Optional) List of backend server IP addresses. Addresses can be either IPv4 or IPv6.

docs/resources/vpc_private_network.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
page_title: "Scaleway: scaleway_vpc_private_network"
3+
description: |-
4+
Manages Scaleway VPC Private Networks.
5+
---
6+
7+
# scaleway_vpc_private_network
8+
9+
Creates and manages Scaleway VPC Private Networks. For more information, see
10+
[the documentation](https://developers.scaleway.com/en/products/vpc/api/#private-networks-ac2df4).
11+
12+
## Example
13+
14+
```hcl
15+
resource "scaleway_vpc_private_network" "pn_priv" {
16+
name = "subnet_demo"
17+
tags = ["demo", "tarraform"]
18+
}
19+
```
20+
21+
## Arguments Reference
22+
23+
The following arguments are supported:
24+
25+
- `name` - (Optional) The name of the private network. If not provided it will be randomly generated.
26+
- `tags` - (Optional) The tags associated with the private network.
27+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the private network should be created.
28+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the private network is associated with.
29+
30+
## Attributes Reference
31+
32+
In addition to all above arguments, the following attributes are exported:
33+
34+
- `id` - The ID of the private network.
35+
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the private network is associated with.
36+
37+
## Import
38+
39+
Private networks can be imported using the `{zone}/{id}`, e.g.
40+
41+
```bash
42+
$ terraform import scaleway_vpc_private_network.vpc_demo fr-par-1/11111111-1111-1111-1111-111111111111
43+
```

scaleway/data_source_account_ssh_key.go

+15-29
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,25 @@ import (
1111
)
1212

1313
func dataSourceScalewayAccountSSHKey() *schema.Resource {
14+
dsSchema := datasourceSchemaFromResourceSchema(resourceScalewayAccountSSKKey().Schema)
15+
addOptionalFieldsToSchema(dsSchema, "name")
16+
17+
dsSchema["name"].ConflictsWith = []string{"ssh_key_id"}
18+
dsSchema["ssh_key_id"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Optional: true,
21+
Description: "The ID of the SSH key",
22+
ValidateFunc: validationUUID(),
23+
}
24+
1425
return &schema.Resource{
1526
ReadContext: dataSourceScalewayAccountSSHKeyRead,
16-
Schema: map[string]*schema.Schema{
17-
"name": {
18-
Type: schema.TypeString,
19-
Optional: true,
20-
Computed: true,
21-
Description: "The name of the SSH key",
22-
},
23-
"ssh_key_id": {
24-
Type: schema.TypeString,
25-
Optional: true,
26-
Computed: true,
27-
Description: "The ID of the SSH key",
28-
ValidateFunc: validationUUIDorUUIDWithLocality(),
29-
},
30-
"public_key": {
31-
Type: schema.TypeString,
32-
Computed: true,
33-
Description: "The public SSH key",
34-
},
35-
"organization_id": organizationIDSchema(),
36-
"project_id": projectIDSchema(),
37-
},
27+
Schema: dsSchema,
3828
}
3929
}
4030

41-
func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
42-
accountAPI := accountAPI(m)
31+
func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
32+
accountAPI := accountAPI(meta)
4333

4434
var sshKey *account.SSHKey
4535
sshKeyID, ok := d.GetOk("ssh_key_id")
@@ -67,11 +57,7 @@ func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.Resource
6757
}
6858

6959
d.SetId(sshKey.ID)
70-
_ = d.Set("name", sshKey.Name)
7160
_ = d.Set("ssh_key_id", sshKey.ID)
72-
_ = d.Set("public_key", sshKey.PublicKey)
73-
_ = d.Set("organization_id", sshKey.OrganizationID)
74-
_ = d.Set("project_id", sshKey.ProjectID)
7561

76-
return nil
62+
return resourceScalewayAccountSSHKeyRead(ctx, d, meta)
7763
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package scaleway
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/scaleway/scaleway-sdk-go/api/vpc/v1"
10+
"github.com/scaleway/scaleway-sdk-go/scw"
11+
)
12+
13+
func dataSourceScalewayVPCPrivateNetwork() *schema.Resource {
14+
// Generate datasource schema from resource
15+
dsSchema := datasourceSchemaFromResourceSchema(resourceScalewayVPCPrivateNetwork().Schema)
16+
17+
// Set 'Optional' schema elements
18+
addOptionalFieldsToSchema(dsSchema, "name")
19+
20+
dsSchema["name"].ConflictsWith = []string{"private_network_id"}
21+
dsSchema["private_network_id"] = &schema.Schema{
22+
Type: schema.TypeString,
23+
Optional: true,
24+
Description: "The ID of the private network",
25+
ValidateFunc: validationUUIDorUUIDWithLocality(),
26+
ConflictsWith: []string{"name"},
27+
}
28+
29+
return &schema.Resource{
30+
Schema: dsSchema,
31+
ReadContext: dataSourceScalewayVPCPrivateNetworkRead,
32+
}
33+
}
34+
35+
func dataSourceScalewayVPCPrivateNetworkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
36+
meta := m.(*Meta)
37+
vpcAPI, zone, err := vpcAPIWithZone(d, meta)
38+
if err != nil {
39+
return diag.FromErr(err)
40+
}
41+
42+
privateNetworkID, ok := d.GetOk("private_network_id")
43+
if !ok {
44+
res, err := vpcAPI.ListPrivateNetworks(
45+
&vpc.ListPrivateNetworksRequest{
46+
Name: expandStringPtr(d.Get("name").(string)),
47+
Zone: zone,
48+
}, scw.WithContext(ctx))
49+
if err != nil {
50+
return diag.FromErr(err)
51+
}
52+
if res.TotalCount == 0 {
53+
return diag.FromErr(
54+
fmt.Errorf(
55+
"no private network found with the name %s",
56+
d.Get("name"),
57+
),
58+
)
59+
}
60+
if res.TotalCount > 1 {
61+
return diag.FromErr(
62+
fmt.Errorf(
63+
"%d private networks found with the name %s",
64+
res.TotalCount,
65+
d.Get("name"),
66+
),
67+
)
68+
}
69+
privateNetworkID = res.PrivateNetworks[0].ID
70+
}
71+
72+
zonedID := datasourceNewZonedID(privateNetworkID, zone)
73+
d.SetId(zonedID)
74+
_ = d.Set("private_network_id", zonedID)
75+
return resourceScalewayVPCPrivateNetworkRead(ctx, d, m)
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package scaleway
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
)
9+
10+
func TestAccScalewayDataSourceVPCPrivateNetwork_Basic(t *testing.T) {
11+
tt := NewTestTools(t)
12+
defer tt.Cleanup()
13+
pnName := "TestAccScalewayDataSourceVPCPrivateNetwork_Basic"
14+
resource.ParallelTest(t, resource.TestCase{
15+
PreCheck: func() { testAccPreCheck(t) },
16+
ProviderFactories: tt.ProviderFactories,
17+
CheckDestroy: testAccCheckScalewayVPCPrivateNetworkDestroy(tt),
18+
Steps: []resource.TestStep{
19+
{
20+
Config: fmt.Sprintf(`
21+
resource "scaleway_vpc_private_network" "pn_test" {
22+
name = "%s"
23+
}`, pnName),
24+
},
25+
{
26+
Config: fmt.Sprintf(`
27+
resource "scaleway_vpc_private_network" "pn_test" {
28+
name = "%s"
29+
}
30+
31+
data "scaleway_vpc_private_network" "pn_test_by_name" {
32+
name = "${scaleway_vpc_private_network.pn_test.name}"
33+
}
34+
35+
data "scaleway_vpc_private_network" "pn_test_by_id" {
36+
private_network_id = "${scaleway_vpc_private_network.pn_test.id}"
37+
}
38+
`, pnName),
39+
Check: resource.ComposeTestCheckFunc(
40+
testAccCheckScalewayVPCPrivateNetworkExists(tt, "scaleway_vpc_private_network.pn_test"),
41+
resource.TestCheckResourceAttrPair(
42+
"data.scaleway_vpc_private_network.pn_test_by_name", "name",
43+
"scaleway_vpc_private_network.pn_test", "name"),
44+
resource.TestCheckResourceAttrPair(
45+
"data.scaleway_vpc_private_network.pn_test_by_id", "private_network_id",
46+
"scaleway_vpc_private_network.pn_test", "id"),
47+
),
48+
},
49+
},
50+
})
51+
}

scaleway/helpers.go

+25
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ func parseLocalizedID(localizedID string) (locality string, ID string, err error
9090
return tab[0], tab[1], nil
9191
}
9292

93+
// parseLocalizedNestedID parses a localizedNestedID and extracts the resource locality, the inner and outer id.
94+
func parseLocalizedNestedID(localizedID string) (locality string, innerID, outerID string, err error) {
95+
tab := strings.SplitN(localizedID, "/", -1)
96+
if len(tab) != 3 {
97+
return "", "", localizedID, fmt.Errorf("cant parse localized id: %s", localizedID)
98+
}
99+
return tab[0], tab[1], tab[2], nil
100+
}
101+
93102
// parseZonedID parses a zonedID and extracts the resource zone and id.
94103
func parseZonedID(zonedID string) (zone scw.Zone, id string, err error) {
95104
locality, id, err := parseLocalizedID(zonedID)
@@ -101,6 +110,17 @@ func parseZonedID(zonedID string) (zone scw.Zone, id string, err error) {
101110
return
102111
}
103112

113+
// parseZonedNestedID parses a zonedNestedID and extracts the resource zone ,inner and outer ID.
114+
func parseZonedNestedID(zonedNestedID string) (zone scw.Zone, outerID, innerID string, err error) {
115+
locality, innerID, outerID, err := parseLocalizedNestedID(zonedNestedID)
116+
if err != nil {
117+
return
118+
}
119+
120+
zone, err = scw.ParseZone(locality)
121+
return
122+
}
123+
104124
// expandID returns the id whether it is a localizedID or a raw ID.
105125
func expandID(id interface{}) string {
106126
_, ID, err := parseLocalizedID(id.(string))
@@ -126,6 +146,11 @@ func newZonedIDString(zone scw.Zone, id string) string {
126146
return fmt.Sprintf("%s/%s", zone, id)
127147
}
128148

149+
// newZonedNestedIDString constructs a unique identifier based on resource zone, inner and outer IDs
150+
func newZonedNestedIDString(zone scw.Zone, outerID, innerID string) string {
151+
return fmt.Sprintf("%s/%s/%s", zone, outerID, innerID)
152+
}
153+
129154
// newRegionalIDString constructs a unique identifier based on resource region and id
130155
func newRegionalIDString(region scw.Region, id string) string {
131156
return fmt.Sprintf("%s/%s", region, id)

scaleway/helpers_instance.go

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func instanceAPIWithZoneAndID(m interface{}, zonedID string) (*instance.API, scw
4343
return instanceAPI, zone, ID, err
4444
}
4545

46+
// instanceAPIWithZoneAndNestedID returns an instance API with zone and inner/outer ID extracted from the state
47+
func instanceAPIWithZoneAndNestedID(m interface{}, zonedNestedID string) (*instance.API, scw.Zone, string, string, error) {
48+
meta := m.(*Meta)
49+
instanceAPI := instance.NewAPI(meta.scwClient)
50+
51+
zone, innerID, outerID, err := parseZonedNestedID(zonedNestedID)
52+
return instanceAPI, zone, innerID, outerID, err
53+
}
54+
4655
// hash hashes a string to a unique hashcode.
4756
//
4857
// crc32 returns a uint32, but for our use we need

0 commit comments

Comments
 (0)