diff --git a/docs/data-sources/baremetal_server.md b/docs/data-sources/baremetal_server.md index b15227c74b..9d7d8d64a0 100644 --- a/docs/data-sources/baremetal_server.md +++ b/docs/data-sources/baremetal_server.md @@ -35,4 +35,6 @@ In addition to all above arguments, the following attributes are exported: - `id` - The ID of the server. +The `scaleway_baremetal_server` data source exports certain attributes once the baremetal server information is retrieved. These attributes can be referenced in other parts of your Terraform configuration. The exported attributes are those that come from the `scaleway_baremetal_server` [resource](../resources/baremetal_server.md) + ~> **Important:** Baremetal servers' IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111` diff --git a/docs/resources/baremetal_server.md b/docs/resources/baremetal_server.md index 90bc276066..35f5cc4d46 100644 --- a/docs/resources/baremetal_server.md +++ b/docs/resources/baremetal_server.md @@ -316,6 +316,7 @@ In addition to all arguments above, the following attributes are exported: - `os_name` - The name of the os. - `private_network` - The private networks attached to the server. - `id` - The ID of the private network. + - `mapping_id` - The ID of the Server-to-Private Network mapping. - `vlan` - The VLAN ID associated to the private network. - `status` - The private network status. - `created_at` - The date and time of the creation of the private network. diff --git a/docs/resources/vpc_route.md b/docs/resources/vpc_route.md index d23e6ebfe4..dad715edab 100644 --- a/docs/resources/vpc_route.md +++ b/docs/resources/vpc_route.md @@ -10,7 +10,7 @@ For more information, see [the main documentation](https://www.scaleway.com/en/d ## Example Usage -### Basic +### With Instance ```terraform resource "scaleway_vpc" "vpc01" { @@ -45,6 +45,64 @@ resource "scaleway_vpc_route" "rt01" { } ``` +### With Baremetal + +```terraform +resource "scaleway_vpc" "vpc01" { + name = "tf-vpc-vpn" +} + +resource "scaleway_vpc_private_network" "pn01" { + name = "tf-pn-vpn" + ipv4_subnet { + subnet = "172.16.64.0/22" + } + vpc_id = scaleway_vpc.vpc01.id +} + +data "scaleway_baremetal_os" "my_os" { + zone = "fr-par-2" + name = "Ubuntu" + version = "22.04 LTS (Jammy Jellyfish)" +} + +data "scaleway_baremetal_offer" "my_offer" { + zone = "fr-par-2" + name = "EM-B112X-SSD" +} + +data "scaleway_baremetal_option" "private_network" { + zone = "fr-par-2" + name = "Private Network" +} + +data "scaleway_iam_ssh_key" "my_key" { + name = "main" +} + +resource "scaleway_baremetal_server" "my_server" { + zone = "fr-par-2" + offer = data.scaleway_baremetal_offer.my_offer.offer_id + os = data.scaleway_baremetal_os.my_os.os_id + ssh_key_ids = [data.scaleway_iam_ssh_key.my_key.id] + + options { + id = data.scaleway_baremetal_option.private_network.option_id + } + private_network { + id = scaleway_vpc_private_network.pn01.id + } +} + +resource "scaleway_vpc_route" "rt01" { + vpc_id = scaleway_vpc.vpc01.id + description = "tf-route-vpn" + tags = ["tf", "route"] + destination = "10.0.0.0/24" + nexthop_resource_id = scaleway_baremetal_server.my_server.private_network.0.mapping_id +} +``` + ## Argument Reference The following arguments are supported: diff --git a/internal/services/baremetal/server.go b/internal/services/baremetal/server.go index 4413ca9198..ed27a9df1d 100644 --- a/internal/services/baremetal/server.go +++ b/internal/services/baremetal/server.go @@ -217,13 +217,18 @@ If this behaviour is wanted, please set 'reinstall_on_ssh_key_changes' argument Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Description: "The private network ID", + Description: "The ID of the private network to associate with the server", Required: true, ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(), StateFunc: func(i interface{}) string { return locality.ExpandID(i.(string)) }, }, + "mapping_id": { + Type: schema.TypeString, + Description: "The ID of the Server-to-Private Network mapping", + Computed: true, + }, "ipam_ip_ids": { Type: schema.TypeList, Optional: true, diff --git a/internal/services/baremetal/types.go b/internal/services/baremetal/types.go index 1165eecccb..3085f0a57c 100644 --- a/internal/services/baremetal/types.go +++ b/internal/services/baremetal/types.go @@ -195,6 +195,7 @@ func flattenPrivateNetworks(region scw.Region, privateNetworks []*baremetalV3.Se for _, privateNetwork := range privateNetworks { flattenedPrivateNetworks = append(flattenedPrivateNetworks, map[string]interface{}{ "id": regional.NewIDString(region, privateNetwork.PrivateNetworkID), + "mapping_id": regional.NewIDString(region, privateNetwork.ID), "ipam_ip_ids": regional.NewRegionalIDs(region, privateNetwork.IpamIPIDs), "vlan": types.FlattenUint32Ptr(privateNetwork.Vlan), "status": privateNetwork.Status,