diff --git a/docs/index.md b/docs/index.md index 06d34fa..0562c8f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,7 +16,7 @@ description: |- terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } diff --git a/docs/resources/vm.md b/docs/resources/vm.md index 52fdca4..2e46f6c 100644 --- a/docs/resources/vm.md +++ b/docs/resources/vm.md @@ -16,7 +16,7 @@ Vm resource terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } @@ -40,6 +40,7 @@ resource "crunchloop_vm" "default" { cores = 1 memory_megabytes = 1024 root_volume_size_gigabytes = 10 + user_data = "echo 'Hello, World!'" } ``` @@ -53,6 +54,7 @@ resource "crunchloop_vm" "default" { - `memory_megabytes` (Number) Vm memory in megabytes - `name` (String) Vm name - `root_volume_size_gigabytes` (Number) Vm root volume size in gigabytes +- `user_data` (String) Vm cloud init user data - `vmi_id` (Number) Vm Vmi id ### Read-Only diff --git a/docs/resources/vm_state.md b/docs/resources/vm_state.md index 9f652ea..abbcad0 100644 --- a/docs/resources/vm_state.md +++ b/docs/resources/vm_state.md @@ -16,7 +16,7 @@ Vm state resource terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 0769ae2..241d18d 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,7 +1,7 @@ terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } diff --git a/examples/resources/crunchloop_vm/resource.tf b/examples/resources/crunchloop_vm/resource.tf index 8ba22cc..5b8be08 100644 --- a/examples/resources/crunchloop_vm/resource.tf +++ b/examples/resources/crunchloop_vm/resource.tf @@ -1,7 +1,7 @@ terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } @@ -25,4 +25,5 @@ resource "crunchloop_vm" "default" { cores = 1 memory_megabytes = 1024 root_volume_size_gigabytes = 10 + user_data = "echo 'Hello, World!'" } diff --git a/examples/resources/crunchloop_vm_state/resource.tf b/examples/resources/crunchloop_vm_state/resource.tf index 8a36ae5..122b323 100644 --- a/examples/resources/crunchloop_vm_state/resource.tf +++ b/examples/resources/crunchloop_vm_state/resource.tf @@ -1,7 +1,7 @@ terraform { required_providers { crunchloop = { - source = "registry.terraform.io/crunchloop/crunchloop" + source = "bilby91/crunchloop" } } } diff --git a/internal/client/client.gen.go b/internal/client/client.gen.go index 508495a..7f4e4ad 100644 --- a/internal/client/client.gen.go +++ b/internal/client/client.gen.go @@ -131,6 +131,7 @@ type CreateVmJSONBody struct { Name string `json:"name"` RootVolumeSizeGigabytes int `json:"root_volume_size_gigabytes"` SshKey *string `json:"ssh_key,omitempty"` + UserData *string `json:"user_data,omitempty"` VmiId int `json:"vmi_id"` } diff --git a/internal/client/openapi.yaml b/internal/client/openapi.yaml index dfa41f2..9e60d36 100644 --- a/internal/client/openapi.yaml +++ b/internal/client/openapi.yaml @@ -44,6 +44,8 @@ paths: ssh_key: type: string example: ssh-rsa AAAAB3NzaC1y.... + user_data: + type: string required: - name - host_id diff --git a/internal/provider/vm_resource.go b/internal/provider/vm_resource.go index 0532a29..239ccf1 100644 --- a/internal/provider/vm_resource.go +++ b/internal/provider/vm_resource.go @@ -39,6 +39,7 @@ type VmResourceModel struct { VmiId types.Int64 `tfsdk:"vmi_id"` HostId types.Int64 `tfsdk:"host_id"` RootVolumeSizeGigabytes types.Int64 `tfsdk:"root_volume_size_gigabytes"` + UserData types.String `tfsdk:"user_data"` } func (r *VmResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -100,6 +101,13 @@ func (r *VmResource) Schema(ctx context.Context, req resource.SchemaRequest, res int64planmodifier.RequiresReplace(), }, }, + "user_data": schema.StringAttribute{ + Required: true, + MarkdownDescription: "Vm cloud init user data", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, }, } } @@ -143,6 +151,10 @@ func (r *VmResource) Create(ctx context.Context, req resource.CreateRequest, res RootVolumeSizeGigabytes: int(data.RootVolumeSizeGigabytes.ValueInt64()), } + if data.UserData.ValueString() != "" { + createOptions.UserData = data.UserData.ValueStringPointer() + } + vm, err := r.client.CreateVmWithResponse(ctx, createOptions) if err != nil { resp.Diagnostics.AddError( diff --git a/main.go b/main.go index 5a7af01..c8b0eba 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func main() { flag.Parse() opts := providerserver.ServeOpts{ - Address: "registry.terraform.io/crunchloop/crunchloop", + Address: "registry.terraform.io/bilby91/crunchloop", Debug: debug, }