diff --git a/docs/data-sources/compute_instance.md b/docs/data-sources/compute_instance.md index 8498097..7f5504a 100644 --- a/docs/data-sources/compute_instance.md +++ b/docs/data-sources/compute_instance.md @@ -18,7 +18,6 @@ description: |- ### Optional - `disks` (Attributes List) (see [below for nested schema](#nestedatt--disks)) -- `maintenance_policy` (String) - `name` (String) - `project_id` (String) - `reservation_id` (String) diff --git a/docs/data-sources/instance_templates.md b/docs/data-sources/instance_templates.md index ab8b0e2..170f48e 100644 --- a/docs/data-sources/instance_templates.md +++ b/docs/data-sources/instance_templates.md @@ -35,7 +35,6 @@ Optional: - `ib_partition` (String) - `image` (String) - `location` (String) -- `maintenance_policy` (String) - `placement_policy` (String) - `project_id` (String) - `public_ip_address_type` (String) diff --git a/docs/resources/compute_instance.md b/docs/resources/compute_instance.md index 00916b7..14c575c 100644 --- a/docs/resources/compute_instance.md +++ b/docs/resources/compute_instance.md @@ -27,7 +27,6 @@ description: |- - `host_channel_adapters` (Attributes List) (see [below for nested schema](#nestedatt--host_channel_adapters)) - `image` (String) - `location` (String) -- `maintenance_policy` (String) - `network_interfaces` (Attributes List) (see [below for nested schema](#nestedatt--network_interfaces)) - `project_id` (String) - `reservation_id` (String) ID of the reservation to which the VM belongs. If not provided or null, the lowest-cost reservation will be used by default. To opt out of using a reservation, set this to an empty string. diff --git a/docs/resources/instance_template.md b/docs/resources/instance_template.md index 7a82715..7a436b9 100644 --- a/docs/resources/instance_template.md +++ b/docs/resources/instance_template.md @@ -28,7 +28,6 @@ description: |- - `ib_partition` (String) - `image` (String) - `location` (String) -- `maintenance_policy` (String) - `placement_policy` (String) - `project_id` (String) - `public_ip_address_type` (String) diff --git a/internal/instance_template/instance_template_data_source.go b/internal/instance_template/instance_template_data_source.go index 1d3d01e..19059c1 100644 --- a/internal/instance_template/instance_template_data_source.go +++ b/internal/instance_template/instance_template_data_source.go @@ -39,7 +39,6 @@ type instanceTemplatesModel struct { IBPartition string `tfsdk:"ib_partition"` Disks []diskModel `tfsdk:"disks"` PlacementPolicy string `tfsdk:"placement_policy"` - MaintenancePolicy string `tfsdk:"maintenance_policy"` } func NewInstanceTemplatesDataSource() datasource.DataSource { @@ -132,10 +131,6 @@ func (ds *instanceTemplatesDataSource) Schema(ctx context.Context, request datas Optional: true, Computed: true, }, - "maintenance_policy": schema.StringAttribute{ - Optional: true, - Computed: true, - }, }, }, }, @@ -173,20 +168,19 @@ func (ds *instanceTemplatesDataSource) Read(ctx context.Context, req datasource. var state instanceTemplatesDataSourceModel for i := range dataResp.Items { state.InstanceTemplates = append(state.InstanceTemplates, instanceTemplatesModel{ - ID: dataResp.Items[i].Id, - Name: dataResp.Items[i].Name, - Type: dataResp.Items[i].Type_, - SSHKey: dataResp.Items[i].SshPublicKey, - Location: dataResp.Items[i].Location, - ImageName: dataResp.Items[i].ImageName, - StartupScript: dataResp.Items[i].StartupScript, - ShutdownScript: dataResp.Items[i].ShutdownScript, - SubnetId: dataResp.Items[i].SubnetId, - IBPartition: dataResp.Items[i].IbPartitionId, - ProjectID: dataResp.Items[i].ProjectId, - Disks: disks, - PlacementPolicy: dataResp.Items[i].PlacementPolicy, - MaintenancePolicy: dataResp.Items[i].MaintenancePolicy, + ID: dataResp.Items[i].Id, + Name: dataResp.Items[i].Name, + Type: dataResp.Items[i].Type_, + SSHKey: dataResp.Items[i].SshPublicKey, + Location: dataResp.Items[i].Location, + ImageName: dataResp.Items[i].ImageName, + StartupScript: dataResp.Items[i].StartupScript, + ShutdownScript: dataResp.Items[i].ShutdownScript, + SubnetId: dataResp.Items[i].SubnetId, + IBPartition: dataResp.Items[i].IbPartitionId, + ProjectID: dataResp.Items[i].ProjectId, + Disks: disks, + PlacementPolicy: dataResp.Items[i].PlacementPolicy, }) } diff --git a/internal/instance_template/instance_template_resource.go b/internal/instance_template/instance_template_resource.go index be77389..fa48b30 100644 --- a/internal/instance_template/instance_template_resource.go +++ b/internal/instance_template/instance_template_resource.go @@ -22,9 +22,8 @@ import ( ) const ( - spreadPlacementPolicy = "spread" - unspecifiedPolicy = "unspecified" - stopVMPolicy = "stop-vm" + spreadPlacementPolicy = "spread" + unspecifiedPlacementPolicy = "unspecified" ) type instanceTemplateResource struct { @@ -47,7 +46,6 @@ type instanceTemplateResourceModel struct { DisksToCreate types.Set `tfsdk:"disks"` ReservationID types.String `tfsdk:"reservation_id"` PlacementPolicy types.String `tfsdk:"placement_policy"` - MaintenancePolicy types.String `tfsdk:"maintenance_policy"` } type diskToCreateResourceModel struct { @@ -177,15 +175,8 @@ func (r *instanceTemplateResource) Schema(ctx context.Context, req resource.Sche "placement_policy": schema.StringAttribute{ Optional: true, Computed: true, - Default: stringdefault.StaticString(unspecifiedPolicy), - Validators: []validator.String{stringvalidator.OneOf(spreadPlacementPolicy, unspecifiedPolicy)}, - PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace(), stringplanmodifier.UseStateForUnknown()}, // cannot be updated in place - }, - "maintenance_policy": schema.StringAttribute{ - Optional: true, - Computed: true, - Default: stringdefault.StaticString(unspecifiedPolicy), - Validators: []validator.String{stringvalidator.OneOf(unspecifiedPolicy, stopVMPolicy)}, + Default: stringdefault.StaticString("unspecified"), + Validators: []validator.String{stringvalidator.OneOf(spreadPlacementPolicy, unspecifiedPlacementPolicy)}, PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace(), stringplanmodifier.UseStateForUnknown()}, // cannot be updated in place }, }, @@ -248,7 +239,6 @@ func (r *instanceTemplateResource) Create(ctx context.Context, req resource.Crea PublicIpAddressType: plan.PublicIpAddressType.ValueString(), ReservationId: plan.ReservationID.ValueString(), PlacementPolicy: plan.PlacementPolicy.ValueString(), - MaintenancePolicy: plan.MaintenancePolicy.ValueString(), }, projectID) if err != nil { resp.Diagnostics.AddError("Failed to create instance template", @@ -265,7 +255,6 @@ func (r *instanceTemplateResource) Create(ctx context.Context, req resource.Crea plan.Image = types.StringValue(dataResp.ImageName) plan.PlacementPolicy = types.StringValue(dataResp.PlacementPolicy) plan.ReservationID = types.StringValue(dataResp.ReservationId) - plan.MaintenancePolicy = types.StringValue(dataResp.MaintenancePolicy) disksToCreateResource := make([]diskToCreateResourceModel, 0, len(dataResp.Disks)) for _, diskToCreate := range disksToCreate { @@ -333,7 +322,6 @@ func (r *instanceTemplateResource) Read(ctx context.Context, req resource.ReadRe state.ProjectID = types.StringValue(instanceTemplate.ProjectId) state.PublicIpAddressType = types.StringValue(instanceTemplate.PublicIpAddressType) state.ID = types.StringValue(instanceTemplate.Id) - state.MaintenancePolicy = types.StringValue(instanceTemplate.MaintenancePolicy) if instanceTemplate.IbPartitionId != "" { state.IBPartition = types.StringValue(instanceTemplate.IbPartitionId) diff --git a/internal/vm/util.go b/internal/vm/util.go index c8bd016..30d5ae2 100644 --- a/internal/vm/util.go +++ b/internal/vm/util.go @@ -241,7 +241,6 @@ func vmToTerraformResourceModel(instance *swagger.InstanceV1Alpha5, state *vmRes networkInterfaces, _ := vmNetworkInterfacesToTerraformResourceModel(instance.NetworkInterfaces) state.NetworkInterfaces = networkInterfaces state.ReservationID = types.StringValue(instance.ReservationId) - state.MaintenancePolicy = types.StringValue(instance.MaintenancePolicy) if len(instance.Disks) > 0 { disks := make([]vmDiskResourceModel, 0, len(instance.Disks)) diff --git a/internal/vm/vm_data_source.go b/internal/vm/vm_data_source.go index b5fbdd4..b105abe 100644 --- a/internal/vm/vm_data_source.go +++ b/internal/vm/vm_data_source.go @@ -27,7 +27,6 @@ type vmDataSourceFilter struct { Type *string `tfsdk:"type"` Disks []vmDiskResourceModel `tfsdk:"disks"` NetworkInterfaces []vmNetworkInterfaceDataModel `tfsdk:"network_interfaces"` - MaintenancePolicy *string `tfsdk:"maintenance_policy"` } type vmNetworkInterfaceDataModel struct { @@ -136,9 +135,6 @@ func (ds *vmDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, re "reservation_id": schema.StringAttribute{ Optional: true, }, - "maintenance_policy": schema.StringAttribute{ - Optional: true, - }, }, } } @@ -186,7 +182,6 @@ func (ds *vmDataSource) Read(ctx context.Context, req datasource.ReadRequest, re state.ProjectID = &vm.ProjectId state.Name = &vm.Name state.Type = &vm.Type_ - state.MaintenancePolicy = &vm.MaintenancePolicy attachedDisks := make([]vmDiskResourceModel, 0, len(vm.Disks)) for _, disk := range vm.Disks { attachedDisks = append(attachedDisks, vmDiskResourceModel{ diff --git a/internal/vm/vm_resource.go b/internal/vm/vm_resource.go index bd05bb9..ab4afc8 100644 --- a/internal/vm/vm_resource.go +++ b/internal/vm/vm_resource.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" @@ -13,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" @@ -25,11 +23,6 @@ import ( var errProjectNotFound = errors.New("project for instance not found") -const ( - unspecifiedPolicy = "unspecified" - stopVMPolicy = "stop-vm" -) - type vmResource struct { client *swagger.APIClient } @@ -49,7 +42,6 @@ type vmResourceModel struct { NetworkInterfaces types.List `tfsdk:"network_interfaces"` HostChannelAdapters types.List `tfsdk:"host_channel_adapters"` ReservationID types.String `tfsdk:"reservation_id"` - MaintenancePolicy types.String `tfsdk:"maintenance_policy"` } type vmNetworkInterfaceResourceModel struct { @@ -250,16 +242,9 @@ func (r *vmResource) Schema(ctx context.Context, req resource.SchemaRequest, res "reservation_id": schema.StringAttribute{ Optional: true, Computed: true, - PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}, // maintain across updates + PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}, // cannot be updated in place Description: "ID of the reservation to which the VM belongs. If not provided or null, the lowest-cost reservation will be used by default. To opt out of using a reservation, set this to an empty string.", }, - "maintenance_policy": schema.StringAttribute{ - Optional: true, - Computed: true, - PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}, // maintain across updates - Default: stringdefault.StaticString(unspecifiedPolicy), - Validators: []validator.String{stringvalidator.OneOf(unspecifiedPolicy, stopVMPolicy)}, - }, }, } } @@ -369,7 +354,6 @@ func (r *vmResource) Create(ctx context.Context, req resource.CreateRequest, res Disks: diskIds, HostChannelAdapters: hostChannelAdapters, ReservationSpecification: reservationSpecification, - MaintenancePolicy: plan.MaintenancePolicy.ValueString(), }, projectID) if err != nil { resp.Diagnostics.AddError("Failed to create instance", @@ -392,7 +376,6 @@ func (r *vmResource) Create(ctx context.Context, req resource.CreateRequest, res plan.ReservationID = types.StringValue(instance.ReservationId) plan.FQDN = types.StringValue(fmt.Sprintf("%s.%s.compute.internal", instance.Name, instance.Location)) plan.ProjectID = types.StringValue(projectID) - plan.MaintenancePolicy = types.StringValue(instance.MaintenancePolicy) networkInterfaces, networkDiags := vmNetworkInterfacesToTerraformResourceModel(instance.NetworkInterfaces) resp.Diagnostics.Append(networkDiags...) @@ -692,37 +675,6 @@ func (r *vmResource) Update(ctx context.Context, req resource.UpdateRequest, res return } - - // handle updating maintenance policy - if !plan.MaintenancePolicy.IsUnknown() { - patchResp, httpResp, err := r.client.VMsApi.UpdateInstance(ctx, - swagger.InstancesPatchRequestV1Alpha5{ - Action: "UPDATE", - MaintenancePolicy: plan.MaintenancePolicy.ValueString(), - }, - plan.ProjectID.ValueString(), - plan.ID.ValueString(), - ) - if err != nil { - resp.Diagnostics.AddError("Failed to update instance maintenance policy", - fmt.Sprintf("There was an error requesting to update the instance's maintenance policy: %v", err)) - - return - } - defer httpResp.Body.Close() - - _, err = common.AwaitOperation(ctx, patchResp.Operation, state.ProjectID.ValueString(), r.client.VMOperationsApi.GetComputeVMsInstancesOperation) - if err != nil { - resp.Diagnostics.AddError("Failed to update instance maintenance policy", - fmt.Sprintf("There was an error updating the instance's maintenance policy: %s", common.UnpackAPIError(err))) - - return - } - - state.MaintenancePolicy = plan.MaintenancePolicy - diags = resp.State.Set(ctx, &state) - resp.Diagnostics.Append(diags...) - } } //nolint:gocritic // Implements Terraform defined interface