CodeBleu commented on code in PR #138: URL: https://github.com/apache/cloudstack-terraform-provider/pull/138#discussion_r1885480207
########## cloudstack/service_offering_schema.go: ########## @@ -0,0 +1,248 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +// Nested schema attributes arent validated +// disk_offering, disk_hypervisor, disk_storage +// ref: https://github.com/hashicorp/terraform-plugin-framework/issues/805 + +package cloudstack + +import ( + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func serviceOfferingMergeCommonSchema(s1 map[string]schema.Attribute) map[string]schema.Attribute { + common := map[string]schema.Attribute{ + "deployment_planner": schema.StringAttribute{ + Description: "The deployment planner for the service offering", + Optional: true, + }, + "disk_offering_id": schema.StringAttribute{ + Description: "The ID of the disk offering", + Optional: true, + }, + "display_text": schema.StringAttribute{ + Description: "The display text of the service offering", + Required: true, + }, + "domain_ids": schema.SetAttribute{ + Description: "the ID of the containing domain(s), null for public offerings", + Optional: true, + ElementType: types.StringType, + }, + "dynamic_scaling_enabled": schema.BoolAttribute{ + Description: "Enable dynamic scaling of the service offering", + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.RequiresReplace(), + }, + Default: booldefault.StaticBool(false), + }, + "host_tags": schema.StringAttribute{ + Description: "The host tag for this service offering", + Optional: true, + }, + "id": schema.StringAttribute{ + Description: "uuid of service offering", + Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "is_volatile": schema.BoolAttribute{ + Description: "Service offering is volatile", + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.RequiresReplace(), + }, + Default: booldefault.StaticBool(false), + }, + "limit_cpu_use": schema.BoolAttribute{ + Description: "Restrict the CPU usage to committed service offering", + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.RequiresReplace(), + }, + Default: booldefault.StaticBool(false), + }, + "name": schema.StringAttribute{ + Description: "The name of the service offering", + Required: true, + }, + "network_rate": schema.Int32Attribute{ + Description: "Data transfer rate in megabits per second", + Optional: true, + }, + "offer_ha": schema.BoolAttribute{ + Description: "The HA for the service offering", + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.RequiresReplace(), + }, + Default: booldefault.StaticBool(false), + }, + "zone_ids": schema.SetAttribute{ + Description: "The ID of the zone(s)", + Optional: true, + ElementType: types.StringType, + }, + "disk_offering": schema.SingleNestedAttribute{ + Optional: true, + Attributes: map[string]schema.Attribute{ + "cache_mode": schema.StringAttribute{ + Description: "the cache mode to use for this disk offering. none, writeback or writethrough", + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "disk_offering_strictness": schema.BoolAttribute{ + Description: "True/False to indicate the strictness of the disk offering association with the compute offering. When set to true, override of disk offering is not allowed when VM is deployed and change disk offering is not allowed for the ROOT disk after the VM is deployed", + Required: true, + PlanModifiers: []planmodifier.Bool{ + boolplanmodifier.RequiresReplace(), + }, + }, + "provisioning_type": schema.StringAttribute{ + Description: "provisioning type used to create volumes. Valid values are thin, sparse, fat.", + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, + "root_disk_size": schema.Int64Attribute{ + Description: "the Root disk size in GB.", + Required: true, Review Comment: @poddm I believe this is what is needed to resolve the issue when trying to create offerings with not specifying a `root_disk_size` or needing it to be `0`. I made this change locally and tested and it worked. ```suggestion Optional: true, ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org