Skip to content

Commit dc1995d

Browse files
authored
Merge pull request #937 from ovh/dev/aamstutz/backport-baremetal-1.8.0
Dev/aamstutz/backport baremetal 1.8.0
2 parents 4f26d42 + 0be9364 commit dc1995d

9 files changed

+633
-876
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
page_title: "Migrating dedicated servers from previous versions to v2.2.0"
3+
---
4+
5+
Version v2.0.0 of OVHcloud Terraform provider introduced a breaking change on the resources related to dedicated servers, mainly:
6+
- Deletion of resource `ovh_dedicated_server_install_task` that has been replaced by a new resource `ovh_dedicated_server_reinstall_task`
7+
- The parameters of resource `ovh_dedicated_server` have been updated to reflect the changes on parameters needed to reinstall a dedicated server
8+
9+
The complete changelog can be found [here](https://github.com/ovh/terraform-provider-ovh/releases/tag/v2.0.0).
10+
11+
This guide explains how to migrate your existing configuration relying on resource `ovh_dedicated_server_install_task` to a new configuration compatible with version v2.2.0 of the provider without triggering a reinstallation of your dedicated servers.
12+
13+
!> This documentation presents a direct migration path between v1.6.0 and v2.2.0. To make this transition easier, we released a version v1.8.0 of the provider that includes both deprecated resources and the new ones. The migration steps are the same, but this version allows a more gradual shift towards v2.2.0.
14+
15+
## First step: import your dedicated servers in the state
16+
17+
From version v2.0.0 and later, the preferred way to manage dedicated servers installation details is through usage of resource `ovh_dedicated_server`. As a result, if you don't already have your dedicated servers declared in your Terraform configuration, you must import them.
18+
19+
You can use an `import` block like the following:
20+
21+
```terraform
22+
import {
23+
id = "nsxxxxxxx.ip-xx-xx-xx.eu"
24+
to = ovh_dedicated_server.srv
25+
}
26+
27+
resource "ovh_dedicated_server" "srv" {}
28+
```
29+
30+
-> If you are doing a first migration to v1.8.0, you should add the following parameter `prevent_install_on_import = true` to the dedicated server resource. This guarantees you that the server won't be reinstalled after import, even if you have a diff on the reinstall-related parameters.
31+
32+
To finish importing the resource into your Terraform state, you should run:
33+
34+
```sh
35+
terraform apply
36+
```
37+
38+
## Second step: backport your previous task details into the imported resource
39+
40+
This step is manual and requires you to convert the previous installation details from resource `ovh_dedicated_server_install_task` to the new fields of resource `ovh_dedicated_server`: `os`, `customizations`, `properties` and `storage`.
41+
42+
Let's take an example: if you previously used the following configuration:
43+
44+
```terraform
45+
resource "ovh_dedicated_server_install_task" "server_install" {
46+
service_name = "nsxxxxxxx.ip-xx-xx-xx.eu"
47+
template_name = "debian12_64"
48+
details {
49+
custom_hostname = "mytest"
50+
}
51+
user_metadata {
52+
key = "sshKey"
53+
value = "ssh-ed25519 AAAAC3..."
54+
}
55+
user_metadata {
56+
key = "postInstallationScript"
57+
value = <<-EOF
58+
#!/bin/bash
59+
echo "coucou postInstallationScript" > /opt/coucou
60+
cat /etc/machine-id >> /opt/coucou
61+
date "+%Y-%m-%d %H:%M:%S" --utc >> /opt/coucou
62+
EOF
63+
}
64+
}
65+
```
66+
67+
You can replace it by the following one:
68+
69+
```terraform
70+
resource "ovh_dedicated_server" "srv" {
71+
customizations = {
72+
hostname = "mytest"
73+
post_installation_script = "IyEvYmluL2Jhc2gKZWNobyAiY291Y291IHBvc3RJbnN0YWxsYXRpb25TY3JpcHQiID4gL29wdC9jb3Vjb3UKY2F0IC9ldGMvbWFjaGluZS1pZCAgPj4gL29wdC9jb3Vjb3UKZGF0ZSAiKyVZLSVtLSVkICVIOiVNOiVTIiAtLXV0YyA+PiAvb3B0L2NvdWNvdQo="
74+
ssh_key = "ssh-ed25519 AAAAC3..."
75+
}
76+
os = "debian12_64"
77+
properties = null
78+
storage = null
79+
}
80+
```
81+
82+
You can check the documentation of resource `ovh_dedicated_server` to see what inputs are available for the reinstallation-related fields.
83+
The documentation of resource `ovh_dedicated_server_reinstall_task` also includes several examples of configuration.
84+
85+
## Third step: make sure your server is not reinstalled unintentionally
86+
87+
You should add the following piece of configuration in the declaration of your dedicated server resource in order to avoid a reinstallation on the next `terraform apply`:
88+
89+
```terraform
90+
resource "ovh_dedicated_server" "srv" {
91+
#
92+
# ... resource fields
93+
#
94+
95+
lifecycle {
96+
ignore_changes = [os, customizations, properties, storage]
97+
}
98+
}
99+
```
100+
101+
This is needed because there is no API endpoint that returns the previous installation parameters of a dedicated server. The goal here is to migrate your old configuration to the new format without triggering a reinstallation.
102+
103+
## Fourth step: remove the lifecycle block
104+
105+
After a while, whenever you need to trigger a reinstallation of your dedicated server, you can just remove the `lifecycle` field from your configuration and run `terraform apply`.

docs/resources/dedicated_server.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ resource "ovh_dedicated_server" "server" {
9090
* `configuration` - Representation of a configuration item to personalize product
9191
* `label` - (Required) Identifier of the resource
9292
* `value` - (Required) Path to the resource in API.OVH.COM
93+
* `service_name` - (Optional) 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
9394

9495
### Editable fields of a dedicated server
9596

@@ -103,40 +104,47 @@ resource "ovh_dedicated_server" "server" {
103104
* `state` - All states a Dedicated can in (error, hacked, hackedBlocked, ok)
104105

105106
### Arguments used to reinstall a dedicated server
107+
106108
* `os` - Operating System to install
107109
* `customizations` - Customization of the OS configuration
108-
* `configDriveUserData` -Config Drive UserData
109-
* `efiBootloaderPath` - Path of the EFI bootloader from the OS installed on the server
110+
* `config_drive_user_data` - Config Drive UserData
111+
* `efi_bootloader_path` - Path of the EFI bootloader from the OS installed on the server
110112
* `hostname` - Custom hostname
111-
* `httpHeaders` - Image HTTP Headers
112-
* `imageCheckSum` - Image checksum
113-
* `imageCheckSumType` - Checksum type
114-
* `imageType` - Image Type
115-
* `imageURL` - Image URL
113+
* `http_headers` - Image HTTP Headers
114+
* `image_check_sum` - Image checksum
115+
* `image_check_sum_type` - Checksum type
116+
* `image_type` - Image Type
117+
* `image_url` - Image URL
116118
* `language` - Display Language
117-
* `postInstallationScript` - Post-Installation Script
118-
* `postInstallationScriptExtension` - Post-Installation Script File Extension
119-
* `sshKey` - SSH Public Key
119+
* `post_installation_script` - Post-Installation Script
120+
* `post_installation_script_extension` - Post-Installation Script File Extension
121+
* `ssh_key` - SSH Public Key
120122
* `storage` - Storage customization
121-
* `diskGroupId` - Disk group id
122-
* `hardwareRaid` - Hardware Raid configurations
123+
* `disk_group_id` - Disk group id
124+
* `hardware_raid` - Hardware Raid configurations
123125
* `arrays` - Number of arrays
124126
* `disks` - Total number of disks in the disk group involved in the hardware raid configuration
125-
* `raidLevel` - Hardware raid type
127+
* `raid_level` - Hardware raid type
126128
* `spares` - Number of disks in the disk group involved in the spare
127129
* `partitioning` - Partitioning configuration
128130
* `disks` - Total number of disks in the disk group involved in the partitioning configuration
129131
* `layout` - Custom partitioning layout
130132
* `extras` - Partition extras parameters
131133
* `lv` - LVM-specific parameters
132134
* `zp` - ZFS-specific parameters
133-
* `fileSystem` - File system type
134-
* `mountPoint` - Mount point
135-
* `raidLevel` - Software raid type
135+
* `file_system` - File system type
136+
* `mount_point` - Mount point
137+
* `raid_level` - Software raid type
136138
* `size` - Partition size in MiB
137-
* `schemeName` - Partitioning scheme (if applicable with selected operating system)
139+
* `scheme_name` - Partitioning scheme (if applicable with selected operating system)
138140
* `properties` - Arbitrary properties to pass to cloud-init's config drive datasource
139141

142+
### Arguments used to control the lifecycle of a dedicated server
143+
144+
* `keep_service_after_destroy` - Avoid termination of the service when deleting the resource (when using this parameter, make sure to apply your configuration before running the destroy so that the value is set in the state)
145+
* `prevent_install_on_create` - Prevent server installation after it has been delivered
146+
* `prevent_install_on_import` - Defines whether a reinstallation of the server is allowed after importing it if there is a modification on the installation parameters
147+
140148
## Attributes Reference
141149

142150
* `service_name` - The service_name of your dedicated server

docs/resources/dedicated_server_reinstall_task.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,3 @@ The following attributes are exported:
282282
* `function` - Function name (should be `hardInstall`).
283283
* `start_date` - Task creation date in RFC3339 format.
284284
* `status` - Task status (should be `done`)
285-
286-
## Import
287-
288-
Installation task can be imported using the `service_name` (`nsXXXX.ip...`) of the baremetal server, the `operating_system` used and ths `task_id`, separated by "/" E.g.,
289-
290-
```bash
291-
terraform import ovh_dedicated_server_reinstall_task nsXXXX.ipXXXX/operating_system/12345
292-
```

ovh/order_resource_gen.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)