-
Notifications
You must be signed in to change notification settings - Fork 130
feat(vpc): add support for private network, private nic #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d81682e
feat(vpc): add v1 support (#644)
7b4bf01
chore(vpc): add support for cassettes based testing
remyleone 579786f
Fix
remyleone ddf2bbd
feat(vpc): update private network casettes tests
8d03e22
add organization id in docs
remyleone 805a2f6
Fix
remyleone 0f3b920
Move organization id after the computed
remyleone 8e3b99e
Add sweeper accross zones
remyleone a6b5246
fix testSweepInstancePrivateNic
remyleone 8f28949
Put all fields in the req
remyleone c5e3d73
Fix mac_address attribute setting
remyleone b4606cd
Fix
remyleone 22a199b
Fix tests
remyleone ffdbc0b
Fix
remyleone 88f7503
Fix
remyleone 77d60e2
Merge branch 'master' into support_vpc
remyleone b8b93c1
Merge branch 'master' into support_vpc
remyleone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
page_title: "Scaleway: scaleway_vpc_private_network" | ||
description: |- | ||
Get information about Scaleway VPC Private Networks. | ||
--- | ||
|
||
# scaleway_vpc_private_network | ||
|
||
Gets information about a private network. | ||
|
||
## Example Usage | ||
|
||
N/A, the usage will be meaningful in the next releases of VPC. | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Exact name of the private network. | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to the ID of the found private network. Addition attributes are | ||
exported. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
page_title: "Scaleway: scaleway_instance_private_nic" | ||
description: |- | ||
Manages Scaleway Compute Instance Private NICs. | ||
--- | ||
|
||
# scaleway_instance_private_nic | ||
|
||
Creates and manages Scaleway Instance Private NICs. For more information, see | ||
[the documentation](https://developers.scaleway.com/en/products/instance/api/#private-nics-a42eea). | ||
|
||
## Example | ||
|
||
```hcl | ||
resource "scaleway_instance_private_nic" "pnic01" { | ||
server_id = "fr-par-1/11111111-1111-1111-1111-111111111111" | ||
private_network_id = "fr-par-1/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" | ||
} | ||
``` | ||
|
||
## Arguments Reference | ||
|
||
The following arguments are required: | ||
|
||
- `server_id` - (Required) The ID of the server associated with. | ||
- `private_network_id` - (Required) The ID of the private network attached to. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all above arguments, the following attributes are exported: | ||
|
||
- `id` - The ID of the private NIC. | ||
|
||
## Import | ||
|
||
Private NICs can be imported using the `{zone}/{server_id}/{private_nic_id}`, e.g. | ||
|
||
```bash | ||
$ terraform import scaleway_instance_volume.server_volume fr-par-1/11111111-1111-1111-1111-111111111111/22222222-2222-2222-2222-222222222222 | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
page_title: "Scaleway: scaleway_vpc_private_network" | ||
description: |- | ||
Manages Scaleway VPC Private Networks. | ||
--- | ||
|
||
# scaleway_vpc_private_network | ||
|
||
Creates and manages Scaleway VPC Private Networks. For more information, see | ||
[the documentation](https://developers.scaleway.com/en/products/vpc/api/#private-networks-ac2df4). | ||
|
||
## Example | ||
|
||
```hcl | ||
resource "scaleway_vpc_private_network" "pn_priv" { | ||
name = "subnet_demo" | ||
tags = ["demo", "tarraform"] | ||
} | ||
``` | ||
|
||
## Arguments Reference | ||
|
||
The following arguments are supported: | ||
|
||
- `name` - (Optional) The name of the private network. If not provided it will be randomly generated. | ||
- `tags` - (Optional) The tags associated with the private network. | ||
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the private network should be created. | ||
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the private network is associated with. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all above arguments, the following attributes are exported: | ||
|
||
- `id` - The ID of the private network. | ||
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the private network is associated with. | ||
|
||
## Import | ||
|
||
Private networks can be imported using the `{zone}/{id}`, e.g. | ||
|
||
```bash | ||
$ terraform import scaleway_vpc_private_network.vpc_demo fr-par-1/11111111-1111-1111-1111-111111111111 | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package scaleway | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/scaleway/scaleway-sdk-go/api/vpc/v1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
func dataSourceScalewayVPCPrivateNetwork() *schema.Resource { | ||
// Generate datasource schema from resource | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceScalewayVPCPrivateNetwork().Schema) | ||
|
||
// Set 'Optional' schema elements | ||
addOptionalFieldsToSchema(dsSchema, "name") | ||
|
||
dsSchema["name"].ConflictsWith = []string{"private_network_id"} | ||
dsSchema["private_network_id"] = &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The ID of the private network", | ||
ValidateFunc: validationUUIDorUUIDWithLocality(), | ||
ConflictsWith: []string{"name"}, | ||
} | ||
|
||
return &schema.Resource{ | ||
Schema: dsSchema, | ||
ReadContext: dataSourceScalewayVPCPrivateNetworkRead, | ||
} | ||
} | ||
|
||
func dataSourceScalewayVPCPrivateNetworkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
meta := m.(*Meta) | ||
vpcAPI, zone, err := vpcAPIWithZone(d, meta) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
privateNetworkID, ok := d.GetOk("private_network_id") | ||
if !ok { | ||
res, err := vpcAPI.ListPrivateNetworks( | ||
&vpc.ListPrivateNetworksRequest{ | ||
Name: expandStringPtr(d.Get("name").(string)), | ||
Zone: zone, | ||
}, scw.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
if res.TotalCount == 0 { | ||
return diag.FromErr( | ||
fmt.Errorf( | ||
"no private network found with the name %s", | ||
d.Get("name"), | ||
), | ||
) | ||
} | ||
if res.TotalCount > 1 { | ||
return diag.FromErr( | ||
fmt.Errorf( | ||
"%d private networks found with the name %s", | ||
res.TotalCount, | ||
d.Get("name"), | ||
), | ||
) | ||
} | ||
privateNetworkID = res.PrivateNetworks[0].ID | ||
} | ||
|
||
zonedID := datasourceNewZonedID(privateNetworkID, zone) | ||
d.SetId(zonedID) | ||
_ = d.Set("private_network_id", zonedID) | ||
return resourceScalewayVPCPrivateNetworkRead(ctx, d, m) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package scaleway | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccScalewayDataSourceVPCPrivateNetwork_Basic(t *testing.T) { | ||
tt := NewTestTools(t) | ||
defer tt.Cleanup() | ||
pnName := "TestAccScalewayDataSourceVPCPrivateNetwork_Basic" | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: tt.ProviderFactories, | ||
CheckDestroy: testAccCheckScalewayVPCPrivateNetworkDestroy(tt), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource "scaleway_vpc_private_network" "pn_test" { | ||
name = "%s" | ||
}`, pnName), | ||
}, | ||
{ | ||
Config: fmt.Sprintf(` | ||
resource "scaleway_vpc_private_network" "pn_test" { | ||
name = "%s" | ||
} | ||
|
||
data "scaleway_vpc_private_network" "pn_test_by_name" { | ||
name = "${scaleway_vpc_private_network.pn_test.name}" | ||
} | ||
|
||
data "scaleway_vpc_private_network" "pn_test_by_id" { | ||
private_network_id = "${scaleway_vpc_private_network.pn_test.id}" | ||
} | ||
`, pnName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckScalewayVPCPrivateNetworkExists(tt, "scaleway_vpc_private_network.pn_test"), | ||
resource.TestCheckResourceAttrPair( | ||
"data.scaleway_vpc_private_network.pn_test_by_name", "name", | ||
"scaleway_vpc_private_network.pn_test", "name"), | ||
resource.TestCheckResourceAttrPair( | ||
"data.scaleway_vpc_private_network.pn_test_by_id", "private_network_id", | ||
"scaleway_vpc_private_network.pn_test", "id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package scaleway | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
vpc "github.com/scaleway/scaleway-sdk-go/api/vpc/v1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
// vpcAPIWithZone returns a new VPC API and the zone for a Create request | ||
func vpcAPIWithZone(d *schema.ResourceData, m interface{}) (*vpc.API, scw.Zone, error) { | ||
meta := m.(*Meta) | ||
vpcAPI := vpc.NewAPI(meta.scwClient) | ||
|
||
zone, err := extractZone(d, meta) | ||
return vpcAPI, zone, err | ||
} | ||
|
||
// vpcAPIWithZoneAndID | ||
func vpcAPIWithZoneAndID(m interface{}, id string) (*vpc.API, scw.Zone, string, error) { | ||
meta := m.(*Meta) | ||
vpcAPI := vpc.NewAPI(meta.scwClient) | ||
|
||
zone, ID, err := parseZonedID(id) | ||
return vpcAPI, zone, ID, err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.