Skip to content

Commit

Permalink
validation
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm committed Mar 23, 2023
1 parent 0982e4a commit d94f9c3
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 68 deletions.
12 changes: 12 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ func DataSourceIBMIsBareMetalServer() *schema.Resource {
Computed: true,
Description: "The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes",
},
isBareMetalServerTrustedPlatformModuleEnabled: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether the trusted platform module is enabled.",
},
isBareMetalServerTrustedPlatformModuleSupportedModes: {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
Computed: true,
Description: "The trusted platform module (TPM) mode:: disabled: No TPM functionality, tpm_2: TPM 2.0. The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered. Enum: [ disabled, tpm_2 ]",
},
},
},
},
Expand Down
12 changes: 12 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ func DataSourceIBMIsBareMetalServers() *schema.Resource {
Computed: true,
Description: "The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes",
},
isBareMetalServerTrustedPlatformModuleEnabled: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether the trusted platform module is enabled.",
},
isBareMetalServerTrustedPlatformModuleSupportedModes: {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
Computed: true,
Description: "The trusted platform module (TPM) mode:: disabled: No TPM functionality, tpm_2: TPM 2.0. The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered. Enum: [ disabled, tpm_2 ]",
},
},
},
},
Expand Down
150 changes: 88 additions & 62 deletions ibm/service/vpc/resource_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,64 @@ import (
)

const (
isBareMetalServerAction = "action"
isBareMetalServerEnableSecureBoot = "enable_secure_boot"
isBareMetalServerTrustedPlatformModule = "trusted_platform_module"
isBareMetalServerTrustedPlatformModuleMode = "mode"
isBareMetalServerBandwidth = "bandwidth"
isBareMetalServerBootTarget = "boot_target"
isBareMetalServerCreatedAt = "created_at"
isBareMetalServerCPU = "cpu"
isBareMetalServerCPUArchitecture = "architecture"
isBareMetalServerCPUCoreCount = "core_count"
isBareMetalServerCpuSocketCount = "socket_count"
isBareMetalServerCpuThreadPerCore = "threads_per_core"
isBareMetalServerCRN = "crn"
isBareMetalServerDisks = "disks"
isBareMetalServerDiskID = "id"
isBareMetalServerDiskSize = "size"
isBareMetalServerDiskName = "name"
isBareMetalServerDiskInterfaceType = "interface_type"
isBareMetalServerHref = "href"
isBareMetalServerMemory = "memory"
isBareMetalServerTags = "tags"
isBareMetalServerName = "name"
isBareMetalServerNetworkInterfaces = "network_interfaces"
isBareMetalServerPrimaryNetworkInterface = "primary_network_interface"
isBareMetalServerProfile = "profile"
isBareMetalServerResourceGroup = "resource_group"
isBareMetalServerResourceType = "resource_type"
isBareMetalServerStatus = "status"
isBareMetalServerStatusReasons = "status_reasons"
isBareMetalServerVPC = "vpc"
isBareMetalServerZone = "zone"
isBareMetalServerStatusReasonsCode = "code"
isBareMetalServerStatusReasonsMessage = "message"
isBareMetalServerStatusReasonsMoreInfo = "more_info"
isBareMetalServerDeleteType = "delete_type"
isBareMetalServerImage = "image"
isBareMetalServerKeys = "keys"
isBareMetalServerUserData = "user_data"
isBareMetalServerNicName = "name"
isBareMetalServerNicPortSpeed = "port_speed"
isBareMetalServerNicAllowIPSpoofing = "allow_ip_spoofing"
isBareMetalServerNicSecurityGroups = "security_groups"
isBareMetalServerNicSubnet = "subnet"
isBareMetalServerUserAccounts = "user_accounts"
isBareMetalServerActionDeleting = "deleting"
isBareMetalServerActionDeleted = "deleted"
isBareMetalServerActionStatusStopping = "stopping"
isBareMetalServerActionStatusStopped = "stopped"
isBareMetalServerActionStatusStarting = "starting"
isBareMetalServerStatusRunning = "running"
isBareMetalServerStatusPending = "pending"
isBareMetalServerStatusRestarting = "restarting"
isBareMetalServerStatusFailed = "failed"
isBareMetalServerAccessTags = "access_tags"
isBareMetalServerUserTagType = "user"
isBareMetalServerAccessTagType = "access"
isBareMetalServerAction = "action"
isBareMetalServerEnableSecureBoot = "enable_secure_boot"
isBareMetalServerTrustedPlatformModule = "trusted_platform_module"
isBareMetalServerTrustedPlatformModuleMode = "mode"
isBareMetalServerTrustedPlatformModuleEnabled = "enabled"
isBareMetalServerTrustedPlatformModuleSupportedModes = "supported_modes"
isBareMetalServerBandwidth = "bandwidth"
isBareMetalServerBootTarget = "boot_target"
isBareMetalServerCreatedAt = "created_at"
isBareMetalServerCPU = "cpu"
isBareMetalServerCPUArchitecture = "architecture"
isBareMetalServerCPUCoreCount = "core_count"
isBareMetalServerCpuSocketCount = "socket_count"
isBareMetalServerCpuThreadPerCore = "threads_per_core"
isBareMetalServerCRN = "crn"
isBareMetalServerDisks = "disks"
isBareMetalServerDiskID = "id"
isBareMetalServerDiskSize = "size"
isBareMetalServerDiskName = "name"
isBareMetalServerDiskInterfaceType = "interface_type"
isBareMetalServerHref = "href"
isBareMetalServerMemory = "memory"
isBareMetalServerTags = "tags"
isBareMetalServerName = "name"
isBareMetalServerNetworkInterfaces = "network_interfaces"
isBareMetalServerPrimaryNetworkInterface = "primary_network_interface"
isBareMetalServerProfile = "profile"
isBareMetalServerResourceGroup = "resource_group"
isBareMetalServerResourceType = "resource_type"
isBareMetalServerStatus = "status"
isBareMetalServerStatusReasons = "status_reasons"
isBareMetalServerVPC = "vpc"
isBareMetalServerZone = "zone"
isBareMetalServerStatusReasonsCode = "code"
isBareMetalServerStatusReasonsMessage = "message"
isBareMetalServerStatusReasonsMoreInfo = "more_info"
isBareMetalServerDeleteType = "delete_type"
isBareMetalServerImage = "image"
isBareMetalServerKeys = "keys"
isBareMetalServerUserData = "user_data"
isBareMetalServerNicName = "name"
isBareMetalServerNicPortSpeed = "port_speed"
isBareMetalServerNicAllowIPSpoofing = "allow_ip_spoofing"
isBareMetalServerNicSecurityGroups = "security_groups"
isBareMetalServerNicSubnet = "subnet"
isBareMetalServerUserAccounts = "user_accounts"
isBareMetalServerActionDeleting = "deleting"
isBareMetalServerActionDeleted = "deleted"
isBareMetalServerActionStatusStopping = "stopping"
isBareMetalServerActionStatusStopped = "stopped"
isBareMetalServerActionStatusStarting = "starting"
isBareMetalServerStatusRunning = "running"
isBareMetalServerStatusPending = "pending"
isBareMetalServerStatusRestarting = "restarting"
isBareMetalServerStatusFailed = "failed"
isBareMetalServerAccessTags = "access_tags"
isBareMetalServerUserTagType = "user"
isBareMetalServerAccessTagType = "access"
)

func ResourceIBMIsBareMetalServer() *schema.Resource {
Expand Down Expand Up @@ -140,9 +142,22 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
isBareMetalServerTrustedPlatformModuleMode: {
Type: schema.TypeString,
Optional: true,
Description: "The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validate.InvokeValidator("ibm_is_bare_metal_server", isBareMetalServerTrustedPlatformModuleMode),
Description: "The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes",
},
isBareMetalServerTrustedPlatformModuleEnabled: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether the trusted platform module is enabled.",
},
isBareMetalServerTrustedPlatformModuleSupportedModes: {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: flex.ResourceIBMVPCHash,
Computed: true,
Description: "The trusted platform module (TPM) mode:: disabled: No TPM functionality, tpm_2: TPM 2.0. The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered. Enum: [ disabled, tpm_2 ]",
},
},
},
Expand Down Expand Up @@ -613,6 +628,7 @@ func ResourceIBMIsBareMetalServer() *schema.Resource {

func ResourceIBMIsBareMetalServerValidator() *validate.ResourceValidator {
bareMetalServerActions := "start, restart, stop"
tpmModes := "disabled, tpm_2"
interface_types := "pci, hipersocket"
validateSchema := make([]validate.ValidateSchema, 1)

Expand Down Expand Up @@ -651,6 +667,13 @@ func ResourceIBMIsBareMetalServerValidator() *validate.ResourceValidator {
Type: validate.TypeString,
Required: true,
AllowedValues: bareMetalServerActions})
validateSchema = append(validateSchema,
validate.ValidateSchema{
Identifier: isBareMetalServerTrustedPlatformModuleMode,
ValidateFunctionIdentifier: validate.ValidateAllowedStringValue,
Type: validate.TypeString,
Required: true,
AllowedValues: tpmModes})

validateSchema = append(validateSchema,
validate.ValidateSchema{
Expand Down Expand Up @@ -2793,11 +2816,14 @@ func resourceIBMIsBareMetalServerMapToBareMetalServerTrustedPlatformModuleProtot

func resourceIBMIsBareMetalServerBareMetalServerTrustedPlatformModulePrototypeToMap(model *vpcv1.BareMetalServerTrustedPlatformModule) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
// if model.Enabled != nil {
// modelMap[isBareMetalServerTrustedPlatformModuleEnabled] = model.Enabled
// }
if model.Enabled != nil {
modelMap[isBareMetalServerTrustedPlatformModuleEnabled] = model.Enabled
}
if model.Mode != nil {
modelMap[isBareMetalServerTrustedPlatformModuleMode] = model.Mode
}
if model.SupportedModes != nil {
modelMap[isBareMetalServerTrustedPlatformModuleSupportedModes] = model.SupportedModes
}
return modelMap, nil
}
12 changes: 9 additions & 3 deletions website/docs/d/is_bare_metal_server.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,16 @@ In addition to all argument reference list, you can access the following attribu
- `message` - (String) An explanation of the status reason
- `more_info` - (String) Link to documentation about this status reason
- `tags` - (Array) Tags associated with the instance.
- `trusted_platform_module` - (List) trusted platform module (TPM) configuration for the bare metals server
- `trusted_platform_module` - (List) trusted platform module (TPM) configuration for this bare metal server

Nested scheme for **trusted_platform_module**:
- `mode` - (String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes.
Nested scheme for **trusted_platform_module**:

- `enabled` - (Boolean) Indicates whether the trusted platform module is enabled.
- `mode` - (String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes. Updating trusted_platform_module mode would require the server to be stopped then started again.
- Constraints: Allowable values are: `disabled`, `tpm_2`.
- `supported_modes` - (Array) The trusted platform module (TPM) mode:
- **disabled: No TPM functionality**
- **tpm_2: TPM 2.0**
- The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered.
- `vpc` - (String) The VPC this bare metal server resides in.
- `zone` - (String) The zone this bare metal server resides in.
12 changes: 9 additions & 3 deletions website/docs/d/is_bare_metal_servers.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ Review the attribute references that you can access after you retrieve your data
- `message` - (String) An explanation of the status reason
- `more_info` - (String) Link to documentation about this status reason
- `tags` - (Array) Tags associated with the instance.
- `trusted_platform_module` - (List) trusted platform module (TPM) configuration for the bare metals server
- `trusted_platform_module` - (List) trusted platform module (TPM) configuration for this bare metal server

Nested scheme for **trusted_platform_module**:
- `mode` - (String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes.
Nested scheme for **trusted_platform_module**:

- `enabled` - (Boolean) Indicates whether the trusted platform module is enabled.
- `mode` - (String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes. Updating trusted_platform_module mode would require the server to be stopped then started again.
- Constraints: Allowable values are: `disabled`, `tpm_2`.
- `supported_modes` - (Array) The trusted platform module (TPM) mode:
- **disabled: No TPM functionality**
- **tpm_2: TPM 2.0**
- The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered.
- `vpc` - (String) The VPC this bare metal server resides in.
- `zone` - (String) The zone this bare metal server resides in.
11 changes: 11 additions & 0 deletions website/docs/r/is_bare_metal_server.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Review the argument references that you can specify for your resource.
- `trusted_platform_module` - (Optional, List) trusted platform module (TPM) configuration for the bare metals server

Nested scheme for **trusted_platform_module**:

- `mode` - (Optional, String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes. Updating trusted_platform_module mode would require the server to be stopped then started again.
- Constraints: Allowable values are: `disabled`, `tpm_2`.
- `user_data` - (Optional, String) User data to transfer to the server bare metal server.
Expand Down Expand Up @@ -209,7 +210,17 @@ In addition to all argument reference list, you can access the following attribu
- `code` - (String) The status reason code
- `message` - (String) An explanation of the status reason
- `more_info` - (String) Link to documentation about this status reason
- `trusted_platform_module` - (List) trusted platform module (TPM) configuration for this bare metal server

Nested scheme for **trusted_platform_module**:

- `enabled` - (Boolean) Indicates whether the trusted platform module is enabled.
- `mode` - (String) The trusted platform module mode to use. The specified value must be listed in the bare metal server profile's supported_trusted_platform_module_modes. Updating trusted_platform_module mode would require the server to be stopped then started again.
- Constraints: Allowable values are: `disabled`, `tpm_2`.
- `supported_modes` - (Array) The trusted platform module (TPM) mode:
- **disabled: No TPM functionality**
- **tpm_2: TPM 2.0**
- The enumerated values for this property are expected to expand in the future. When processing this property, check for and log unknown values. Optionally halt processing and surface the error, or bypass the resource on which the unexpected property value was encountered.

## Import

Expand Down

0 comments on commit d94f9c3

Please sign in to comment.