Skip to content
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

feat(instance): add support for project_id #609

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/data-sources/instance_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ In addition to all above arguments, the following attributes are exported:

- `organization_id` - The ID of the organization the image is associated with.

- `project_id` - The ID of the project the image is associated with.

- `creation_date` - Date of the image creation.

- `modification_date` - Date of image latest update.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/instance_security_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ In addition to all above arguments, the following attributes are exported:

- `organization_id` - The ID of the organization the security group is associated with.

- `project_id` - The ID of the project the security group is associated with.

- `inbound_default_policy` - The default policy on incoming traffic. Possible values are: `accept` or `drop`.

- `outbound_default_policy` - The default policy on outgoing traffic. Possible values are: `accept` or `drop`.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/instance_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ You find all the available types on the [pricing page](https://www.scaleway.com/

- `organization_id` - The ID of the organization the server is associated with.

- `project_id` - The ID of the project the server is associated with.

- `tags` - The tags associated with the server.

- `security_group_id` - The [security group](https://developers.scaleway.com/en/products/instance/api/#security-groups-8d7f89) the server is attached to.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/instance_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ data "scaleway_instance_volume" "my_volume" {

- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the server is associated with.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is associated with.

## Attributes Reference

In addition to all above arguments, the following attributes are exported:
Expand Down
1 change: 1 addition & 0 deletions docs/resources/instance_ip.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The following arguments are supported:

- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the IP is associated with.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the IP is associated with.

## Attributes Reference

Expand Down
3 changes: 2 additions & 1 deletion docs/resources/instance_placement_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ The following arguments are supported:
- `policy_type` - (Defaults to `max_availability`) The [policy type](https://developers.scaleway.com/en/products/instance/api/#placement-groups-d8f653) of the placement group. Possible values are: `low_latency` or `max_availability`.
- `policy_mode` - (Defaults to `optional`) The [policy mode](https://developers.scaleway.com/en/products/instance/api/#placement-groups-d8f653) of the placement group. Possible values are: `optional` or `enforced`.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the placement group should be created.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the project the placement group is associated with.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the placement group is associated with.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the placement group is associated with.

## Attributes Reference

Expand Down
4 changes: 3 additions & 1 deletion docs/resources/instance_security_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ The following arguments are supported:

- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the security group should be created.

- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the project the security group is associated with.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the security group is associated with.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the security group is associated with.


The `inbound_rule` and `outbound_rule` block supports:
Expand Down
5 changes: 4 additions & 1 deletion docs/resources/instance_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ attached to the server. Updates to this field will trigger a stop/start of the s

- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the server should be created.

- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the server is associated with. If you intend to deploy your instance in another project than the default one use your `project_id` instead of the organization id.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the server is associated with.
If you intend to deploy your instance in another project than the default one use your `project_id` instead of the organization id.

- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the server is associated with.


## Attributes Reference
Expand Down
1 change: 1 addition & 0 deletions docs/resources/instance_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following arguments are supported:
- `name` - (Optional) The name of the volume. If not provided it will be randomly generated.
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the volume should be created.
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the volume is associated with.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the volume is associated with.

## Attributes Reference

Expand Down
10 changes: 7 additions & 3 deletions scaleway/data_source_instance_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func dataSourceScalewayInstanceImage() *schema.Resource {
},
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),

"public": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -100,9 +101,11 @@ func dataSourceScalewayInstanceImageRead(d *schema.ResourceData, m interface{})
imageID, ok := d.GetOk("image_id")
if !ok { // Get instance by name, zone, and arch.
res, err := instanceAPI.ListImages(&instance.ListImagesRequest{
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Arch: expandStringPtr(d.Get("architecture")),
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Arch: expandStringPtr(d.Get("architecture")),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
}, scw.WithAllPages())
if err != nil {
return err
Expand Down Expand Up @@ -149,6 +152,7 @@ func dataSourceScalewayInstanceImageRead(d *schema.ResourceData, m interface{})
}

_ = d.Set("organization_id", resp.Image.Organization)
_ = d.Set("project_id", resp.Image.Project)
_ = d.Set("architecture", resp.Image.Arch)
_ = d.Set("name", resp.Image.Name)

Expand Down
6 changes: 4 additions & 2 deletions scaleway/data_source_instance_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ func dataSourceScalewayInstanceSecurityGroupRead(d *schema.ResourceData, m inter
securityGroupID, ok := d.GetOk("security_group_id")
if !ok {
res, err := instanceAPI.ListSecurityGroups(&instance.ListSecurityGroupsRequest{
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
}, scw.WithAllPages())
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions scaleway/data_source_instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func dataSourceScalewayInstanceServerRead(d *schema.ResourceData, m interface{})
serverID, ok := d.GetOk("server_id")
if !ok {
res, err := instanceAPI.ListServers(&instance.ListServersRequest{
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
})
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions scaleway/data_source_instance_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func dataSourceScalewayInstanceVolumeRead(d *schema.ResourceData, m interface{})
volumeID, ok := d.GetOk("volume_id")
if !ok { // Get volumes by zone and name.
res, err := instanceAPI.ListVolumes(&instance.ListVolumesRequest{
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Zone: zone,
Name: expandStringPtr(d.Get("name")),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
})
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions scaleway/resource_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func resourceScalewayInstanceIP() *schema.Resource {
},
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),
},
}
}
Expand All @@ -50,6 +51,7 @@ func resourceScalewayInstanceIPCreate(d *schema.ResourceData, m interface{}) err
res, err := instanceAPI.CreateIP(&instance.CreateIPRequest{
Zone: zone,
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
})
if err != nil {
return err
Expand Down Expand Up @@ -82,6 +84,7 @@ func resourceScalewayInstanceIPRead(d *schema.ResourceData, m interface{}) error
_ = d.Set("address", res.IP.Address.String())
_ = d.Set("zone", string(zone))
_ = d.Set("organization_id", res.IP.Organization)
_ = d.Set("project_id", res.IP.Project)
_ = d.Set("reverse", res.IP.Reverse)

return nil
Expand Down
3 changes: 3 additions & 0 deletions scaleway/resource_instance_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func resourceScalewayInstancePlacementGroup() *schema.Resource {
},
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),
},
}
}
Expand All @@ -64,6 +65,7 @@ func resourceScalewayInstancePlacementGroupCreate(d *schema.ResourceData, m inte
Zone: zone,
Name: expandOrGenerateString(d.Get("name"), "pg"),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
PolicyMode: instance.PlacementGroupPolicyMode(d.Get("policy_mode").(string)),
PolicyType: instance.PlacementGroupPolicyType(d.Get("policy_type").(string)),
})
Expand Down Expand Up @@ -97,6 +99,7 @@ func resourceScalewayInstancePlacementGroupRead(d *schema.ResourceData, m interf
_ = d.Set("name", res.PlacementGroup.Name)
_ = d.Set("zone", string(zone))
_ = d.Set("organization_id", res.PlacementGroup.Organization)
_ = d.Set("project_id", res.PlacementGroup.Project)
_ = d.Set("policy_mode", res.PlacementGroup.PolicyMode.String())
_ = d.Set("policy_type", res.PlacementGroup.PolicyType.String())
_ = d.Set("policy_respected", res.PlacementGroup.PolicyRespected)
Expand Down
3 changes: 3 additions & 0 deletions scaleway/resource_instance_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func resourceScalewayInstanceSecurityGroup() *schema.Resource {
},
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),
},
}
}
Expand All @@ -95,6 +96,7 @@ func resourceScalewayInstanceSecurityGroupCreate(d *schema.ResourceData, m inter
Name: expandOrGenerateString(d.Get("name"), "sg"),
Zone: zone,
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
Description: d.Get("description").(string),
Stateful: d.Get("stateful").(bool),
InboundDefaultPolicy: instance.SecurityGroupPolicy(d.Get("inbound_default_policy").(string)),
Expand Down Expand Up @@ -133,6 +135,7 @@ func resourceScalewayInstanceSecurityGroupRead(d *schema.ResourceData, m interfa

_ = d.Set("zone", zone)
_ = d.Set("organization_id", res.SecurityGroup.Organization)
_ = d.Set("project_id", res.SecurityGroup.Project)
_ = d.Set("name", res.SecurityGroup.Name)
_ = d.Set("stateful", res.SecurityGroup.Stateful)
_ = d.Set("description", res.SecurityGroup.Description)
Expand Down
4 changes: 4 additions & 0 deletions scaleway/resource_instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func resourceScalewayInstanceServer() *schema.Resource {
},
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),

// Deprecated and removed.
"disable_public_ip": {
Expand Down Expand Up @@ -247,6 +248,7 @@ func resourceScalewayInstanceServerCreate(d *schema.ResourceData, m interface{})
Zone: zone,
Name: expandOrGenerateString(d.Get("name"), "srv"),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
Image: image.ID,
CommercialType: commercialType,
EnableIPv6: d.Get("enable_ipv6").(bool),
Expand Down Expand Up @@ -361,6 +363,8 @@ func resourceScalewayInstanceServerRead(d *schema.ResourceData, m interface{}) e
_ = d.Set("security_group_id", newZonedID(zone, response.Server.SecurityGroup.ID).String())
_ = d.Set("enable_ipv6", response.Server.EnableIPv6)
_ = d.Set("enable_dynamic_ip", response.Server.DynamicIPRequired)
_ = d.Set("organization_id", response.Server.Organization)
_ = d.Set("project_id", response.Server.Project)

// Image could be empty in an import context.
image := expandRegionalID(d.Get("image").(string))
Expand Down
3 changes: 3 additions & 0 deletions scaleway/resource_instance_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func resourceScalewayInstanceVolume() *schema.Resource {
Description: "The server associated with this volume",
},
"organization_id": organizationIDSchema(),
"project_id": projectIDSchema(),
"zone": zoneSchema(),
},
}
Expand All @@ -82,6 +83,7 @@ func resourceScalewayInstanceVolumeCreate(d *schema.ResourceData, m interface{})
Name: expandOrGenerateString(d.Get("name"), "vol"),
VolumeType: instance.VolumeVolumeType(d.Get("type").(string)),
Organization: expandStringPtr(d.Get("organization_id")),
Project: expandStringPtr(d.Get("project_id")),
}

if size, ok := d.GetOk("size_in_gb"); ok {
Expand Down Expand Up @@ -127,6 +129,7 @@ func resourceScalewayInstanceVolumeRead(d *schema.ResourceData, m interface{}) e

_ = d.Set("name", res.Volume.Name)
_ = d.Set("organization_id", res.Volume.Organization)
_ = d.Set("project_id", res.Volume.Project)
_ = d.Set("zone", string(zone))
_ = d.Set("type", res.Volume.VolumeType.String())
_ = d.Set("size_in_gb", uint64(res.Volume.Size/scw.GB))
Expand Down