Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-yechenwei committed Jan 22, 2024
1 parent be19028 commit 908e523
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 40 deletions.
Expand Up @@ -223,9 +223,10 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"instance_count": {
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
},

"subnet_id": {
Expand Down Expand Up @@ -336,9 +337,10 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"instance_count": {
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
},

"subnet_id": {
Expand Down Expand Up @@ -449,9 +451,10 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"instance_count": {
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
},

"subnet_id": {
Expand Down Expand Up @@ -579,9 +582,10 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
},

"number_of_disks": {
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
Type: pluginsdk.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
},

"size_in_gb": {
Expand Down Expand Up @@ -947,10 +951,11 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
},

"transport_create_and_mount": {
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
ConflictsWith: []string{"three_tier_configuration.0.transport_mount"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"resource_group_id": {
Expand All @@ -971,10 +976,11 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Arguments() map[string]*pl
},

"transport_mount": {
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Type: pluginsdk.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
ConflictsWith: []string{"three_tier_configuration.0.transport_create_and_mount"},
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"file_share_id": {
Expand Down Expand Up @@ -1012,6 +1018,40 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Attributes() map[string]*p
return map[string]*pluginsdk.Schema{}
}

func (r WorkloadsSAPThreeTierVirtualInstanceResource) CustomizeDiff() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
rd := metadata.ResourceDiff

if v := rd.Get("three_tier_configuration.0.database_server_configuration.0.disk_volume_configuration"); v != nil {
diskVolumes := v.(*pluginsdk.Set).List()
if hasDuplicateVolumeName(diskVolumes) {
return fmt.Errorf("`volume_name` cannot be duplicated")
}
}

return nil
},
}
}

func hasDuplicateVolumeName(input []interface{}) bool {
seen := make(map[string]bool)

for _, v := range input {
diskVolume := v.(map[string]interface{})
volumeName := diskVolume["volume_name"].(string)

if seen[volumeName] {
return true
}
seen[volumeName] = true
}

return false
}

func (r WorkloadsSAPThreeTierVirtualInstanceResource) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 60 * time.Minute,
Expand Down Expand Up @@ -1159,11 +1199,7 @@ func (r WorkloadsSAPThreeTierVirtualInstanceResource) Read() sdk.ResourceFunc {

if config := props.Configuration; config != nil {
if v, ok := config.(sapvirtualinstances.DeploymentWithOSConfiguration); ok {
appLocation := ""
if appLocationVal := v.AppLocation; appLocationVal != nil {
appLocation = *v.AppLocation
}
state.AppLocation = location.Normalize(appLocation)
state.AppLocation = location.Normalize(pointer.From(v.AppLocation))

if osSapConfiguration := v.OsSapConfiguration; osSapConfiguration != nil {
state.SapFqdn = pointer.From(osSapConfiguration.SapFqdn)
Expand Down
Expand Up @@ -3,12 +3,12 @@ subcategory: "Workloads"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_workloads_sap_three_tier_virtual_instance"
description: |-
Manages an SAP Three Tier Virtual Instance with new SAP System.
Manages an SAP Three Tier Virtual Instance with a new SAP System.
---

# azurerm_workloads_sap_three_tier_virtual_instance

Manages an SAP Three Tier Virtual Instance with new SAP System.
Manages an SAP Three Tier Virtual Instance with a new SAP System.

-> **Note:** Before using this resource, it's required to submit the request of registering the Resource Provider with Azure CLI `az provider register --namespace "Microsoft.Workloads"`. The Resource Provider can take a while to register, you can check the status by running `az provider show --namespace "Microsoft.Workloads" --query "registrationState"`. Once this outputs "Registered" the Resource Provider is available for use.

Expand Down Expand Up @@ -318,19 +318,11 @@ The following arguments are supported:

---

A `deployer_virtual_machine_packages` block supports the following:

* `storage_account_id` - (Required) The ID of the deployer VM packages storage account. Changing this forces a new resource to be created.

* `url` - (Required) The URL of the deployer VM packages file. Changing this forces a new resource to be created.

---

A `disk_volume_configuration` block supports the following:

* `volume_name` - (Required) Specifies the volumn name of the database disk. Possible values are `backup`, `hana/data`, `hana/log`, `hana/shared`, `os` and `usr/sap`. Changing this forces a new resource to be created.

* `number_of_disks` - (Required) The total number of disks required for the concerned volume. Changing this forces a new resource to be created.
* `number_of_disks` - (Required) The total number of disks required for the concerned volume. Possible values are at least `1`. Changing this forces a new resource to be created.

* `size_in_gb` - (Required) The size of the Disk in GB. Changing this forces a new resource to be created.

Expand Down Expand Up @@ -392,7 +384,7 @@ A `three_tier_configuration` block supports the following:

* `transport_mount` - (Optional) A `transport_mount` block as defined below. Changing this forces a new resource to be created.

~> **Note:** The `Skip` configuration type would be enabled when the `transport_create_and_mount` and the `transport_mount` aren't set.
~> **Note:** The file share configuration uses `skip` by default If neither `transport_create_and_mount` nor `transport_mount` is set.

---

Expand All @@ -414,7 +406,7 @@ A `transport_mount` block supports the following:

An `application_server_configuration` block supports the following:

* `instance_count` - (Required) The number of instances for the Application Server. Changing this forces a new resource to be created.
* `instance_count` - (Required) The number of instances for the Application Server. Possible values are at least `1`. Changing this forces a new resource to be created.

* `subnet_id` - (Required) The resource ID of the Subnet for the Application Server. Changing this forces a new resource to be created.

Expand All @@ -424,7 +416,7 @@ An `application_server_configuration` block supports the following:

A `central_server_configuration` block supports the following:

* `instance_count` - (Required) The number of instances for the Central Server. Changing this forces a new resource to be created.
* `instance_count` - (Required) The number of instances for the Central Server. Possible values are at least `1`. Changing this forces a new resource to be created.

* `subnet_id` - (Required) The resource ID of the Subnet for the Central Server. Changing this forces a new resource to be created.

Expand All @@ -434,7 +426,7 @@ A `central_server_configuration` block supports the following:

A `database_server_configuration` block supports the following:

* `instance_count` - (Required) The number of instances for the Database Server. Changing this forces a new resource to be created.
* `instance_count` - (Required) The number of instances for the Database Server. Possible values are at least `1`. Changing this forces a new resource to be created.

* `subnet_id` - (Required) The resource ID of the Subnet for the Database Server. Changing this forces a new resource to be created.

Expand Down

0 comments on commit 908e523

Please sign in to comment.