Skip to content

Commit

Permalink
added start script to create vm
Browse files Browse the repository at this point in the history
  • Loading branch information
JungleCatSW committed May 26, 2023
1 parent 569034b commit 206a1d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/resources/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ resource "cudo_vm" "my-vm" {
boot_disk_class = "network"
ssh_key_source = "custom"
ssh_keys_custom = ["custom-sshkey-1","custom-sshkey-2"]
start_script = <<EOF
touch /multiline-script.txt
echo $PWD > /current-dir.txt
EOF
}
```

Expand All @@ -47,6 +51,7 @@ resource "cudo_vm" "my-vm" {
- `password` (String) VM password
- `ssh_key_source` (String) Which SSH keys to add to the VM: user (default), project or custom
- `ssh_keys_custom` (List of String) List of custom SSH keys to add to the VM, ssh_key_source must be set to custom
- `start_script` (String) A script to run when VM boots

### Read-Only

Expand Down
4 changes: 4 additions & 0 deletions examples/resources/cudo_vm/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ resource "cudo_vm" "my-vm" {
boot_disk_class = "network"
ssh_key_source = "custom"
ssh_keys_custom = ["custom-sshkey-1","custom-sshkey-2"]
start_script = <<EOF
touch /multiline-script.txt
echo $PWD > /current-dir.txt
EOF
}
6 changes: 6 additions & 0 deletions internal/provider/vm_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type VMResourceModel struct {
VMId types.String `tfsdk:"vm_id"`
SSHKeySource types.String `tfsdk:"ssh_key_source"`
SSHKeysCustom []types.String `tfsdk:"ssh_keys_custom"`
StartScript types.String `tfsdk:"start_script"`
// Response
CPUModel types.String `tfsdk:"cpu_model"`
CreateBy types.String `tfsdk:"create_by"`
Expand Down Expand Up @@ -188,6 +189,10 @@ func (r *VMResource) Schema(ctx context.Context, req resource.SchemaRequest, res
MarkdownDescription: "List of custom SSH keys to add to the VM, ssh_key_source must be set to custom",
Optional: true,
},
"start_script": schema.StringAttribute{
MarkdownDescription: "A script to run when VM boots",
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -263,6 +268,7 @@ func (r *VMResource) Create(ctx context.Context, req resource.CreateRequest, res
VMID: state.VMId.ValueString(),
SSHKeySource: &ks,
CustomSSHKeys: customKeys,
StartScript: state.StartScript.ValueString(),
}

_, err := r.client.Client.Projects.CreateVM(params)
Expand Down

0 comments on commit 206a1d4

Please sign in to comment.