Skip to content

Commit

Permalink
Merge pull request #710 from ovh/update_dedicated_postInstallScript
Browse files Browse the repository at this point in the history
Update dedicated post install script
  • Loading branch information
amstuta authored Aug 29, 2024
2 parents 93f6445 + beec70f commit d7186ad
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 80 deletions.
10 changes: 0 additions & 10 deletions ovh/data_me_installation_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ func dataSourceMeInstallationTemplate() *schema.Resource {
Computed: true,
Description: "Set up the server using the provided hostname instead of the default hostname",
},
"post_installation_script_link": {
Type: schema.TypeString,
Computed: true,
Description: "Indicate the URL where your postinstall customisation script is located",
},
"post_installation_script_return": {
Type: schema.TypeString,
Computed: true,
Description: "Indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'",
},
},
},
},
Expand Down
12 changes: 0 additions & 12 deletions ovh/resource_dedicated_server_install_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ func resourceDedicatedServerInstallTask() *schema.Resource {
ForceNew: true,
Description: "",
},
"post_installation_script_link": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Indicate the URL where your postinstall customisation script is located",
},
"post_installation_script_return": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'",
},
"soft_raid_devices": {
Type: schema.TypeInt,
Optional: true,
Expand Down
10 changes: 0 additions & 10 deletions ovh/resource_me_installation_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ func resourceMeInstallationTemplate() *schema.Resource {
Optional: true,
Description: "Set up the server using the provided hostname instead of the default hostname",
},
"post_installation_script_link": {
Type: schema.TypeString,
Optional: true,
Description: "Indicate the URL where your postinstall customisation script is located",
},
"post_installation_script_return": {
Type: schema.TypeString,
Optional: true,
Description: "indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'",
},
},
},
},
Expand Down
12 changes: 0 additions & 12 deletions ovh/resource_me_installation_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,6 @@ func TestAccMeInstallationTemplateResource_customization(t *testing.T) {
"customization.0.custom_hostname",
"mytest",
),
resource.TestCheckResourceAttr(
"ovh_me_installation_template.template",
"customization.0.post_installation_script_link",
"http://mylink.org",
),
resource.TestCheckResourceAttr(
"ovh_me_installation_template.template",
"customization.0.post_installation_script_return",
"returned_string",
),
resource.TestCheckResourceAttrSet(
"ovh_me_installation_template.template",
"family",
Expand All @@ -142,8 +132,6 @@ resource "ovh_me_installation_template" "template" {
customization {
custom_hostname = "mytest"
post_installation_script_link = "http://mylink.org"
post_installation_script_return = "returned_string"
}
}
`
12 changes: 4 additions & 8 deletions ovh/types_dedicated_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,16 @@ func (opts *DedicatedServerInstallTaskCreateOpts) FromResource(d *schema.Resourc
}

type DedicatedServerInstallTaskDetails struct {
CustomHostname *string `json:"customHostname,omitempty"`
DiskGroupId *int64 `json:"diskGroupId,omitempty"`
NoRaid *bool `json:"noRaid,omitempty"`
PostInstallationScriptLink *string `json:"postInstallationScriptLink,omitempty"`
PostInstallationScriptReturn *string `json:"postInstallationScriptReturn,omitempty"`
SoftRaidDevices *int64 `json:"softRaidDevices,omitempty"`
CustomHostname *string `json:"customHostname,omitempty"`
DiskGroupId *int64 `json:"diskGroupId,omitempty"`
NoRaid *bool `json:"noRaid,omitempty"`
SoftRaidDevices *int64 `json:"softRaidDevices,omitempty"`
}

func (opts *DedicatedServerInstallTaskDetails) FromResource(d *schema.ResourceData, parent string) *DedicatedServerInstallTaskDetails {
opts.CustomHostname = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.custom_hostname", parent))
opts.DiskGroupId = helpers.GetNilInt64PointerFromData(d, fmt.Sprintf("%s.disk_group_id", parent))
opts.NoRaid = helpers.GetNilBoolPointerFromData(d, fmt.Sprintf("%s.no_raid", parent))
opts.PostInstallationScriptLink = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.post_installation_script_link", parent))
opts.PostInstallationScriptReturn = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.post_installation_script_return", parent))
opts.SoftRaidDevices = helpers.GetNilInt64PointerFromData(d, fmt.Sprintf("%s.soft_raid_devices", parent))

return opts
Expand Down
21 changes: 2 additions & 19 deletions ovh/types_installation_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type InstallationTemplate struct {
EndOfInstall string `json:"endOfInstall,omitempty"`
Family string `json:"family,omitempty"`
Filesystems []string `json:"filesystems"`
HardRaidConfiguration bool `json:"hardRaidConfiguration,omitempty"`
Inputs []InstallationTemplateInputs `json:"inputs,omitempty"`
License *InstallationTemplateLicense `json:"license,omitempty"`
LvmReady *bool `json:"lvmReady,omitempty"`
Expand Down Expand Up @@ -48,8 +47,6 @@ func (v InstallationTemplate) ToMap() map[string]interface{} {
obj["family"] = v.Family
obj["filesystems"] = v.Filesystems

obj["hard_raid_configuration"] = v.HardRaidConfiguration

if v.Inputs != nil {
inputs := make([]interface{}, len(v.Inputs))
for i, input := range v.Inputs {
Expand Down Expand Up @@ -107,10 +104,8 @@ func (opts *InstallationTemplateUpdateOpts) FromResource(d *schema.ResourceData)
}

type InstallationTemplateCustomization struct {
CustomHostname *string `json:"customHostname,omitempty"`
PostInstallationScriptLink *string `json:"postInstallationScriptLink,omitempty"`
PostInstallationScriptReturn *string `json:"postInstallationScriptReturn,omitempty"`
SshKeyName *string `json:"sshKeyName,omitempty"`
CustomHostname *string `json:"customHostname,omitempty"`
SshKeyName *string `json:"sshKeyName,omitempty"`
}

func (v InstallationTemplateCustomization) ToMap() map[string]interface{} {
Expand All @@ -122,16 +117,6 @@ func (v InstallationTemplateCustomization) ToMap() map[string]interface{} {
custom_attr_set = true
}

if v.PostInstallationScriptLink != nil {
obj["post_installation_script_link"] = *v.PostInstallationScriptLink
custom_attr_set = true
}

if v.PostInstallationScriptReturn != nil {
obj["post_installation_script_return"] = *v.PostInstallationScriptReturn
custom_attr_set = true
}

// dont return an object if nothing is set
if custom_attr_set {
return obj
Expand Down Expand Up @@ -216,8 +201,6 @@ func (v InstallationTemplateProjectItem) ToMap() map[string]interface{} {

func (opts *InstallationTemplateCustomization) FromResource(d *schema.ResourceData, parent string) *InstallationTemplateCustomization {
opts.CustomHostname = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.custom_hostname", parent))
opts.PostInstallationScriptLink = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.post_installation_script_link", parent))
opts.PostInstallationScriptReturn = helpers.GetNilStringPointerFromData(d, fmt.Sprintf("%s.post_installation_script_return", parent))
return opts
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/dedicated_server_boots.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data "ovh_dedicated_server_boots" "netboots" {

* `service_name` - (Required) The internal name of your dedicated server.

* `boot_type` - (Optional) Filter the value of bootType property (harddisk, rescue, ipxeCustomerScript, internal, network)
* `boot_type` - (Optional) Filter the value of bootType property (harddisk, rescue, internal, network)

* `kernel` - (Optional) Filter the value of kernel property (iPXE script name)

Expand Down
2 changes: 0 additions & 2 deletions website/docs/d/me_installation_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ The following attributes are exported:
* `category`: Category of this template (informative only).
* `customization`:
* `custom_hostname`: Set up the server using the provided hostname instead of the default hostname.
* `post_installation_script_link`: Indicate the URL where your postinstall customisation script is located.
* `post_installation_script_return`: Indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'.
* `description`: Information about this template.
* `distribution`: Distribution this template is based on.
* `end_of_install` - End of install date of the template.
Expand Down
22 changes: 18 additions & 4 deletions website/docs/r/dedicated_server_install_task.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ resource "ovh_me_installation_template" "debian" {
base_template_name = "debian12_64"
template_name = "mydebian12"
customization {
post_installation_script_link = "http://test"
post_installation_script_return = "ok"
custom_hostname = "mytest"
}
}
Expand All @@ -40,6 +39,15 @@ resource "ovh_dedicated_server_install_task" "server_install" {
key = "sshKey"
value = "ssh-ed25519 AAAAC3..."
}
user_metadata {
key = "postInstallationScript"
value = <<-EOF
#!/bin/bash
echo "coucou postInstallationScript" > /opt/coucou
cat /etc/machine-id >> /opt/coucou
date "+%Y-%m-%d %H:%M:%S" --utc >> /opt/coucou
EOF
}
}
```

Expand Down Expand Up @@ -116,6 +124,14 @@ resource "ovh_dedicated_server_install_task" "server_install" {
key = "language"
value ="fr-fr"
}
user_metadata {
key = "postInstallationScript"
value = <<-EOF
coucou postInstallationScriptPowerShell" | Out-File -FilePath "c:\ovhupd\script\coucou.txt"
(Get-ItemProperty -LiteralPath "Registry::HKLM\SOFTWARE\Microsoft\Cryptography" -Name "MachineGuid").MachineGuid | Out-File -FilePath "c:\ovhupd\script\coucou.txt" -Append
(Get-Date).ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss") | Out-File -FilePath "c:\ovhupd\script\coucou.txt" -Append
EOF
}
}
```
Expand All @@ -138,8 +154,6 @@ The `details` block supports:
* `disk_group_id` - Disk group id.
* `language` - Deprecated, will be removed in next release.
* `no_raid` - Set to true to disable RAID.
* `post_installation_script_link` - Indicate the URL where your postinstall customisation script is located.
* `post_installation_script_return` - Indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'.
* `soft_raid_devices` - soft raid devices.
* `use_spla` - Deprecated, will be removed in next release.

Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/me_installation_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ resource "ovh_me_installation_template" "mytemplate" {
* `category`: Category of this template (informative only). (basic, customer, hosting, other, readyToUse, virtualisation).
* `customization`:
* `custom_hostname`: Set up the server using the provided hostname instead of the default hostname.
* `post_installation_script_link`: Indicate the URL where your postinstall customisation script is located.
* `post_installation_script_return`: indicate the string returned by your postinstall customisation script on successful execution. Advice: your script should return a unique validation string in case of succes. A good example is 'loh1Xee7eo OK OK OK UGh8Ang1Gu'.
* `description`: information about this template.
* `distribution`: the distribution this template is based on.
* `family`: this template family type.
Expand Down

0 comments on commit d7186ad

Please sign in to comment.