Skip to content

Commit

Permalink
make computed properties required
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuolun-citrix committed Aug 21, 2024
1 parent 8d68ef5 commit a37d26f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 65 deletions.
45 changes: 22 additions & 23 deletions internal/daas/machine_catalog/machine_catalog_resource_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ import (

"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"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"
Expand Down Expand Up @@ -453,9 +449,10 @@ func (MachineCatalogResourceModel) GetSchema() schema.Schema {
},
"description": schema.StringAttribute{
Description: "Description of the machine catalog.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Required: true,
// Optional: true,
// Computed: true,
// Default: stringdefault.StaticString(""),
},
"is_power_managed": schema.BoolAttribute{
Description: "Specify if the machines in the machine catalog will be power managed.",
Expand Down Expand Up @@ -537,26 +534,28 @@ func (MachineCatalogResourceModel) GetSchema() schema.Schema {
},
"minimum_functional_level": schema.StringAttribute{
Description: "Specifies the minimum functional level for the VDA machines in the catalog. Defaults to `L7_20`.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString("L7_20"),
Validators: []validator.String{
stringvalidator.OneOfCaseInsensitive(util.GetAllowedFunctionalLevelValues()...),
},
Required: true,
// Optional: true,
// Computed: true,
// Default: stringdefault.StaticString("L7_20"),
// Validators: []validator.String{
// stringvalidator.OneOfCaseInsensitive(util.GetAllowedFunctionalLevelValues()...),
// },
},
"scopes": schema.SetAttribute{
ElementType: types.StringType,
Description: "The IDs of the scopes for the machine catalog to be a part of.",
Optional: true,
Computed: true,
Default: setdefault.StaticValue(types.SetValueMust(types.StringType, []attr.Value{})),
Validators: []validator.Set{
setvalidator.ValueStringsAre(
validator.String(
stringvalidator.RegexMatches(regexp.MustCompile(util.GuidRegex), "must be specified with ID in GUID format"),
),
),
},
Required: true,
// Optional: true,
// Computed: true,
// Default: setdefault.StaticValue(types.SetValueMust(types.StringType, []attr.Value{})),
// Validators: []validator.Set{
// setvalidator.ValueStringsAre(
// validator.String(
// stringvalidator.RegexMatches(regexp.MustCompile(util.GuidRegex), "must be specified with ID in GUID format"),
// ),
// ),
// },
},
"provisioning_scheme": ProvisioningSchemeModel{}.GetSchema(),
},
Expand Down
7 changes: 4 additions & 3 deletions internal/daas/machine_catalog/machine_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func (AzureMachineConfigModel) GetSchema() schema.SingleNestedAttribute {
"azure_master_image": AzureMasterImageModel{}.GetSchema(),
"master_image_note": schema.StringAttribute{
Description: "The note for the master image.",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Required: true,
// Optional: true,
// Computed: true,
// Default: stringdefault.StaticString(""),
},
"image_update_reboot_options": ImageUpdateRebootOptionsModel{}.GetSchema(),
"storage_type": schema.StringAttribute{
Expand Down
72 changes: 36 additions & 36 deletions internal/test/azure_mcs_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,43 +235,43 @@ func TestAzureMcs(t *testing.T) {
),
},
// ImportState testing - MCS AD
// {
// ResourceName: "citrix_machine_catalog.testMachineCatalog",
// ImportState: true,
// ImportStateVerify: true,
// // The last_updated attribute does not exist in the Orchestration
// // API, therefore there is no value for it during import.
// ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache", "provisioning_scheme.machine_domain_identity.service_account", "provisioning_scheme.machine_config.service_account_password"},
// },
{
ResourceName: "citrix_machine_catalog.testMachineCatalog",
ImportState: true,
ImportStateVerify: true,
// The last_updated attribute does not exist in the Orchestration
// API, therefore there is no value for it during import.
ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache", "provisioning_scheme.machine_domain_identity.service_account", "provisioning_scheme.machine_config.service_account_password"},
},
// ImportState testing - MCS HybridAAD
// {
// ResourceName: "citrix_machine_catalog.testMachineCatalog-HybAAD",
// ImportState: true,
// ImportStateVerify: true,
// // The last_updated attribute does not exist in the Orchestration
// // API, therefore there is no value for it during import.
// ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache", "provisioning_scheme.machine_domain_identity.service_account", "provisioning_scheme.machine_config.service_account_password"},
// },
// // ImportState testing - MCS AAD
// {
// ResourceName: "citrix_machine_catalog.testMachineCatalog-AAD",
// ImportState: true,
// ImportStateVerify: true,
// // The last_updated attribute does not exist in the Orchestration
// // API, therefore there is no value for it during import.
// ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache"},
// SkipFunc: skipForOnPrem(isOnPremises),
// },
// // ImportState testing
// {
// ResourceName: "citrix_machine_catalog.testMachineCatalog-WG",
// ImportState: true,
// ImportStateVerify: true,
// // The last_updated attribute does not exist in the Orchestration
// // API, therefore there is no value for it during import.
// ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache"},
// SkipFunc: skipForOnPrem(isOnPremises),
// },
{
ResourceName: "citrix_machine_catalog.testMachineCatalog-HybAAD",
ImportState: true,
ImportStateVerify: true,
// The last_updated attribute does not exist in the Orchestration
// API, therefore there is no value for it during import.
ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache", "provisioning_scheme.machine_domain_identity.service_account", "provisioning_scheme.machine_config.service_account_password"},
},
// ImportState testing - MCS AAD
{
ResourceName: "citrix_machine_catalog.testMachineCatalog-AAD",
ImportState: true,
ImportStateVerify: true,
// The last_updated attribute does not exist in the Orchestration
// API, therefore there is no value for it during import.
ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache"},
SkipFunc: skipForOnPrem(isOnPremises),
},
// ImportState testing
{
ResourceName: "citrix_machine_catalog.testMachineCatalog-WG",
ImportState: true,
ImportStateVerify: true,
// The last_updated attribute does not exist in the Orchestration
// API, therefore there is no value for it during import.
ImportStateVerifyIgnore: []string{"provisioning_scheme.network_mapping", "provisioning_scheme.azure_machine_config.writeback_cache"},
SkipFunc: skipForOnPrem(isOnPremises),
},
// ImportState testing - Manual Power Managed
{
ResourceName: "citrix_machine_catalog.testMachineCatalogManualPowerManaged",
Expand Down
15 changes: 12 additions & 3 deletions internal/test/machine_catalog_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
container = "%s"
master_image = "%s"
}
master_image_note = "test image note"
storage_type = "Standard_LRS"
use_managed_disks = true
writeback_cache = {
Expand All @@ -1535,7 +1536,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
naming_scheme_type ="Numeric"
}
}
scopes = []
zone = citrix_zone.test.id
}
`
Expand Down Expand Up @@ -1564,6 +1565,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
container = "%s"
master_image = "%s"
}
master_image_note = "test image note"
storage_type = "Standard_LRS"
use_managed_disks = true
writeback_cache = {
Expand All @@ -1589,6 +1591,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
naming_scheme_type ="Numeric"
}
}
scopes = []
zone = citrix_zone.test.id
}
`
Expand Down Expand Up @@ -1617,9 +1620,9 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
container = "%s"
master_image = "%s"
}
master_image_note = "test image note"
storage_type = "Standard_LRS"
use_managed_disks = true
writeback_cache = {
wbc_disk_storage_type = "Standard_LRS"
persist_wbc = true
Expand All @@ -1643,6 +1646,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
naming_scheme_type ="Numeric"
}
}
scopes = []
zone = citrix_zone.test.id
}
`
Expand Down Expand Up @@ -1756,6 +1760,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
allocation_type = "Random"
session_support = "MultiSession"
provisioning_type = "MCS"
minimum_functional_level = "L7_9"
provisioning_scheme = {
hypervisor = citrix_azure_hypervisor.testHypervisor.id
hypervisor_resource_pool = citrix_azure_hypervisor_resource_pool.testHypervisorResourcePool.id
Expand Down Expand Up @@ -1786,7 +1791,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
naming_scheme_type ="Numeric"
}
}
scopes = []
zone = citrix_zone.test.id
}
`
Expand All @@ -1797,6 +1802,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
allocation_type = "Random"
session_support = "MultiSession"
provisioning_type = "MCS"
minimum_functional_level = "L7_9"
provisioning_scheme = {
hypervisor = citrix_azure_hypervisor.testHypervisor.id
hypervisor_resource_pool = citrix_azure_hypervisor_resource_pool.testHypervisorResourcePool.id
Expand Down Expand Up @@ -1828,6 +1834,7 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
naming_scheme_type ="Numeric"
}
}
scopes = []
zone = citrix_zone.test.id
}
`
Expand Down Expand Up @@ -2260,6 +2267,8 @@ resource "citrix_machine_catalog" "testMachineCatalog%s" {
]
}
]
scopes = []
minimum_functional_level = "L7_9"
}
`

Expand Down

0 comments on commit a37d26f

Please sign in to comment.