Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion docs/resources/dedicated_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ resource "ovh_dedicated_server" "server" {
* `label` - (Required) Identifier of the resource
* `value` - (Required) Path to the resource in API.OVH.COM
* `service_name` - (Optional, Forces replacement) The service_name of your dedicated server. This field can be used to avoid ordering a dedicated server at creation and just create the resource using an already existing service
* `range` - (Optional) Range of the dedicated server to order. Can be `standard` or `eco`. Defaults to `standard`

~> **Note** To get the available plans, you can use the API console to first [create a cart](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#post-/order/cart) and then use the created cart ID to fetch the available plans using [the following call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers). Once you've found the right plan, you can use [this call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers/options) to get the available options for this plan.
~> **Note** To get the available plans, you can use the API console to first [create a cart](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#post-/order/cart) and then use the created cart ID to fetch the available plans using [the following call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers) (or `/order/cart/{cartId}/eco` for eco servers). Once you've found the right plan, you can use [this call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers/options) to get the available options for this plan.

### Editable fields of a dedicated server

Expand Down
5 changes: 5 additions & 0 deletions ovh/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ func testAccPreCheckOrderDedicatedServer(t *testing.T) {
checkEnvOrSkip(t, "OVH_TESTACC_ORDER_DEDICATED_SERVER")
}

func testAccPreCheckOrderDedicatedServerEco(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_TESTACC_ORDER_DEDICATED_SERVER_ECO")
}

func testAccPreCheckVPS(t *testing.T) {
testAccPreCheckCredentials(t)
checkEnvOrSkip(t, "OVH_VPS")
Expand Down
8 changes: 7 additions & 1 deletion ovh/resource_dedicated_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ func (r *dedicatedServerResource) Create(ctx context.Context, req resource.Creat
// If service_name is not provided, it means dedicated server has to be ordered
if data.ServiceName.IsNull() || data.ServiceName.IsUnknown() {
order := data.ToOrder()
if err := orderCreate(order, r.config, "baremetalServers", false, defaultOrderTimeout); err != nil {
// Map the user-facing "range" attribute to the API range type.
// "standard" (default) -> "baremetalServers", "eco" -> "eco"
rangeType := "baremetalServers"
if !data.Range.IsNull() && !data.Range.IsUnknown() && data.Range.ValueString() == "eco" {
rangeType = "eco"
}
if err := orderCreate(order, r.config, rangeType, false, defaultOrderTimeout); err != nil {
resp.Diagnostics.AddError("failed to create order", err.Error())
return
}
Expand Down
17 changes: 17 additions & 0 deletions ovh/resource_dedicated_server_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 147 additions & 1 deletion ovh/resource_dedicated_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,153 @@ func TestAccDedicatedServer_basic(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: "service_name",
ImportStateVerifyIgnore: []string{
"display_name", "order", "ovh_subsidiary", "plan", "plan_option",
"display_name", "order", "ovh_subsidiary", "plan", "plan_option", "range",
},
ImportStateIdFunc: func(s *terraform.State) (string, error) {
service, ok := s.RootModule().Resources["ovh_dedicated_server.server"]
if !ok {
return "", errors.New("ovh_dedicated_server.server not found")
}
return service.Primary.Attributes["service_name"], nil
},
},
},
})
}

func dedicatedServerEcoResourceTestConfig(updated bool) string {
var (
monitoring = true
noIntervention = false
operatingSystem = "debian11_64"
displayName = "First display name"
efiBootloaderPath = ""
)

if updated {
monitoring = false
noIntervention = true
operatingSystem = "debian12_64"
displayName = "Second display name"
efiBootloaderPath = `\\efi\\debian\\grubx64.efi`
}

return fmt.Sprintf(`
data "ovh_me" "account" {}

resource "ovh_dedicated_server" "server" {
ovh_subsidiary = data.ovh_me.account.ovh_subsidiary
range = "eco"
monitoring = %t
no_intervention = %t
os = "%s"
display_name = "%s"
efi_bootloader_path = "%s"
plan = [
{
plan_code = "24sys012"
duration = "P1M"
pricing_mode = "default"

configuration = [
{
label = "dedicated_datacenter"
value = "rbx"
},
{
label = "dedicated_os"
value = "none_64.en"
},
{
label = "region"
value = "europe"
}
]
}
]

plan_option = [
{
duration = "P1M"
plan_code = "softraid-2x512nvme-24sys"
pricing_mode = "default"
quantity = 1
},
{
duration = "P1M"
plan_code = "vrack-bandwidth-500-24sys"
pricing_mode = "default"
quantity = 1
},
{
duration = "P1M"
plan_code = "bandwidth-1000-24sys"
pricing_mode = "default"
quantity = 1
},
{
duration = "P1M"
plan_code = "ram-32g-ecc-2666-24sys"
pricing_mode = "default"
quantity = 1
}
]
}
`, monitoring, noIntervention, operatingSystem, displayName, efiBootloaderPath)
}

func TestAccDedicatedServer_eco(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckOrderDedicatedServerEco(t)
},
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: dedicatedServerEcoResourceTestConfig(false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "monitoring", "true"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "no_intervention", "false"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "display_name", "First display name"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "iam.display_name", "First display name"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "os", "debian11_64"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "efi_bootloader_path", ""),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "range", "eco"),
),
},
{
Config: dedicatedServerEcoResourceTestConfig(true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "monitoring", "false"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "no_intervention", "true"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "display_name", "Second display name"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "iam.display_name", "Second display name"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "os", "debian12_64"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "efi_bootloader_path", "\\efi\\debian\\grubx64.efi"),
resource.TestCheckResourceAttr(
"ovh_dedicated_server.server", "range", "eco"),
),
},
{
ResourceName: "ovh_dedicated_server.server",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIdentifierAttribute: "service_name",
ImportStateVerifyIgnore: []string{
"display_name", "order", "ovh_subsidiary", "plan", "plan_option", "range",
},
ImportStateIdFunc: func(s *terraform.State) (string, error) {
service, ok := s.RootModule().Resources["ovh_dedicated_server.server"]
Expand Down
3 changes: 2 additions & 1 deletion templates/resources/dedicated_server.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Use this resource to order and manage a dedicated server.
* `label` - (Required) Identifier of the resource
* `value` - (Required) Path to the resource in API.OVH.COM
* `service_name` - (Optional, Forces replacement) The service_name of your dedicated server. This field can be used to avoid ordering a dedicated server at creation and just create the resource using an already existing service
* `range` - (Optional) Range of the dedicated server to order. Can be `standard` or `eco`. Defaults to `standard`

~> **Note** To get the available plans, you can use the API console to first [create a cart](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#post-/order/cart) and then use the created cart ID to fetch the available plans using [the following call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers). Once you've found the right plan, you can use [this call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers/options) to get the available options for this plan.
~> **Note** To get the available plans, you can use the API console to first [create a cart](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#post-/order/cart) and then use the created cart ID to fetch the available plans using [the following call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers) (or `/order/cart/{cartId}/eco` for eco servers). Once you've found the right plan, you can use [this call](https://eu.api.ovh.com/console/?section=%2Forder&branch=v1#get-/order/cart/-cartId-/baremetalServers/options) to get the available options for this plan.

### Editable fields of a dedicated server

Expand Down