Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Resource/Data Source: netapp_volume_quota_rule #23042

Merged
merged 21 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/services/netapp/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/snapshotpolicy"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/snapshots"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumegroups"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumequotarules"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumes"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumesreplication"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand All @@ -22,6 +23,7 @@ type Client struct {
VolumeClient *volumes.VolumesClient
VolumeGroupClient *volumegroups.VolumeGroupsClient
VolumeReplicationClient *volumesreplication.VolumesReplicationClient
VolumeQuotaRules *volumequotarules.VolumeQuotaRulesClient
SnapshotClient *snapshots.SnapshotsClient
SnapshotPoliciesClient *snapshotpolicy.SnapshotPolicyClient
}
Expand Down Expand Up @@ -57,6 +59,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
return nil, fmt.Errorf("building VolumeReplicationClient client: %+v", err)
}

volumeQuotaRuleClient, err := volumequotarules.NewVolumeQuotaRulesClientWithBaseURI(o.Environment.ResourceManager)
o.Configure(volumeQuotaRuleClient.Client, o.Authorizers.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building VolumeQuotaRuleClient client: %+v", err)
}

snapshotClient, err := snapshots.NewSnapshotsClientWithBaseURI(o.Environment.ResourceManager)
o.Configure(snapshotClient.Client, o.Authorizers.ResourceManager)
if err != nil {
Expand All @@ -75,6 +83,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
VolumeClient: volumeClient,
VolumeGroupClient: volumeGroupClient,
VolumeReplicationClient: volumeReplicationClient,
VolumeQuotaRules: volumeQuotaRuleClient,
SnapshotClient: snapshotClient,
SnapshotPoliciesClient: snapshotPoliciesClient,
}, nil
Expand Down
104 changes: 104 additions & 0 deletions internal/services/netapp/models/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package models

const (
MaxQuotaTargetIDSizeInKiB int64 = 4294967295
)

type NetAppVolumeGroupVolume struct {
Id string `tfschema:"id"`
Name string `tfschema:"name"`
VolumePath string `tfschema:"volume_path"`
ServiceLevel string `tfschema:"service_level"`
SubnetId string `tfschema:"subnet_id"`
Protocols []string `tfschema:"protocols"`
SecurityStyle string `tfschema:"security_style"`
StorageQuotaInGB int64 `tfschema:"storage_quota_in_gb"`
ThroughputInMibps float64 `tfschema:"throughput_in_mibps"`
Tags map[string]string `tfschema:"tags"`
SnapshotDirectoryVisible bool `tfschema:"snapshot_directory_visible"`
CapacityPoolId string `tfschema:"capacity_pool_id"`
ProximityPlacementGroupId string `tfschema:"proximity_placement_group_id"`
VolumeSpecName string `tfschema:"volume_spec_name"`
ExportPolicy []ExportPolicyRule `tfschema:"export_policy_rule"`
MountIpAddresses []string `tfschema:"mount_ip_addresses"`
DataProtectionReplication []DataProtectionReplication `tfschema:"data_protection_replication"`
DataProtectionSnapshotPolicy []DataProtectionSnapshotPolicy `tfschema:"data_protection_snapshot_policy"`
}

type NetAppVolumeGroupSapHanaModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
AccountName string `tfschema:"account_name"`
GroupDescription string `tfschema:"group_description"`
ApplicationIdentifier string `tfschema:"application_identifier"`
Volumes []NetAppVolumeGroupVolume `tfschema:"volume"`
}

type NetAppVolumeGroupSapHanaDataSourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
AccountName string `tfschema:"account_name"`
GroupDescription string `tfschema:"group_description"`
ApplicationIdentifier string `tfschema:"application_identifier"`
Volumes []NetAppVolumeGroupVolume `tfschema:"volume"`
}

type ExportPolicyRule struct {
RuleIndex int `tfschema:"rule_index"`
AllowedClients string `tfschema:"allowed_clients"`
Nfsv3Enabled bool `tfschema:"nfsv3_enabled"`
Nfsv41Enabled bool `tfschema:"nfsv41_enabled"`
UnixReadOnly bool `tfschema:"unix_read_only"`
UnixReadWrite bool `tfschema:"unix_read_write"`
RootAccessEnabled bool `tfschema:"root_access_enabled"`
}

type DataProtectionReplication struct {
EndpointType string `tfschema:"endpoint_type"`
RemoteVolumeLocation string `tfschema:"remote_volume_location"`
RemoteVolumeResourceId string `tfschema:"remote_volume_resource_id"`
ReplicationFrequency string `tfschema:"replication_frequency"`
}

type DataProtectionSnapshotPolicy struct {
DataProtectionSnapshotPolicy string `tfschema:"snapshot_policy_id"`
}

type ReplicationSchedule string

const (
ReplicationSchedule10Minutes ReplicationSchedule = "10minutes"
ReplicationScheduleDaily ReplicationSchedule = "daily"
ReplicationScheduleHourly ReplicationSchedule = "hourly"
)

func PossibleValuesForReplicationSchedule() []string {
return []string{
string(ReplicationSchedule10Minutes),
string(ReplicationScheduleDaily),
string(ReplicationScheduleHourly),
}
}

type NetAppVolumeQuotaRuleModel struct {
Name string `tfschema:"name"`
Location string `tfschema:"location"`
VolumeID string `tfschema:"volume_id"`
QuotaTarget string `tfschema:"quota_target"`
QuotaSizeInKiB int64 `tfschema:"quota_size_in_kib"`
QuotaType string `tfschema:"quota_type"`
}

type NetAppVolumeQuotaRuleDataSourceModel struct {
Name string `tfschema:"name"`
Location string `tfschema:"location"`
VolumeID string `tfschema:"volume_id"`
QuotaTarget string `tfschema:"quota_target"`
QuotaSizeInKiB int64 `tfschema:"quota_size_in_kib"`
QuotaType string `tfschema:"quota_type"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,10 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumegroups"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
netAppModels "github.com/hashicorp/terraform-provider-azurerm/internal/services/netapp/models"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

type NetAppVolumeGroupSapHanaDataSourceModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
AccountName string `tfschema:"account_name"`
GroupDescription string `tfschema:"group_description"`
ApplicationIdentifier string `tfschema:"application_identifier"`
Volumes []NetAppVolumeGroupVolume `tfschema:"volume"`
}

var _ sdk.DataSource = NetAppVolumeGroupSapHanaDataSource{}

type NetAppVolumeGroupSapHanaDataSource struct{}
Expand All @@ -36,7 +27,7 @@ func (r NetAppVolumeGroupSapHanaDataSource) ResourceType() string {
}

func (r NetAppVolumeGroupSapHanaDataSource) ModelObject() interface{} {
return &NetAppVolumeGroupSapHanaDataSourceModel{}
return &netAppModels.NetAppVolumeGroupSapHanaDataSourceModel{}
}

func (r NetAppVolumeGroupSapHanaDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
Expand Down Expand Up @@ -249,7 +240,7 @@ func (r NetAppVolumeGroupSapHanaDataSource) Read() sdk.ResourceFunc {

client := metadata.Client.NetApp.VolumeGroupClient

var state NetAppVolumeGroupSapHanaDataSourceModel
var state netAppModels.NetAppVolumeGroupSapHanaDataSourceModel
if err := metadata.Decode(&state); err != nil {
return fmt.Errorf("decoding: %+v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumesreplication"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
netAppModels "github.com/hashicorp/terraform-provider-azurerm/internal/services/netapp/models"
netAppValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/netapp/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand All @@ -29,20 +30,10 @@ import (

type NetAppVolumeGroupSapHanaResource struct{}

type NetAppVolumeGroupSapHanaModel struct {
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Location string `tfschema:"location"`
AccountName string `tfschema:"account_name"`
GroupDescription string `tfschema:"group_description"`
ApplicationIdentifier string `tfschema:"application_identifier"`
Volumes []NetAppVolumeGroupVolume `tfschema:"volume"`
}

var _ sdk.Resource = NetAppVolumeGroupSapHanaResource{}

func (r NetAppVolumeGroupSapHanaResource) ModelObject() interface{} {
return &NetAppVolumeGroupSapHanaModel{}
return &netAppModels.NetAppVolumeGroupSapHanaModel{}
}

func (r NetAppVolumeGroupSapHanaResource) ResourceType() string {
Expand Down Expand Up @@ -274,7 +265,7 @@ func (r NetAppVolumeGroupSapHanaResource) Arguments() map[string]*pluginsdk.Sche
"replication_frequency": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(PossibleValuesForReplicationSchedule(), false),
ValidateFunc: validation.StringInSlice(netAppModels.PossibleValuesForReplicationSchedule(), false),
},
},
},
Expand Down Expand Up @@ -313,7 +304,7 @@ func (r NetAppVolumeGroupSapHanaResource) Create() sdk.ResourceFunc {

subscriptionId := metadata.Client.Account.SubscriptionId

var model NetAppVolumeGroupSapHanaModel
var model netAppModels.NetAppVolumeGroupSapHanaModel
if err := metadata.Decode(&model); err != nil {
return fmt.Errorf("decoding: %+v", err)
}
Expand Down Expand Up @@ -439,7 +430,7 @@ func (r NetAppVolumeGroupSapHanaResource) Update() sdk.ResourceFunc {
}

metadata.Logger.Infof("Decoding state for %s", id)
var state NetAppVolumeGroupSapHanaModel
var state netAppModels.NetAppVolumeGroupSapHanaModel
if err := metadata.Decode(&state); err != nil {
return err
}
Expand Down Expand Up @@ -562,7 +553,7 @@ func (r NetAppVolumeGroupSapHanaResource) Read() sdk.ResourceFunc {
}

metadata.Logger.Infof("Decoding state for %s", id)
var state NetAppVolumeGroupSapHanaModel
var state netAppModels.NetAppVolumeGroupSapHanaModel
if err := metadata.Decode(&state); err != nil {
return err
}
Expand All @@ -577,7 +568,7 @@ func (r NetAppVolumeGroupSapHanaResource) Read() sdk.ResourceFunc {

metadata.SetID(id)

model := NetAppVolumeGroupSapHanaModel{
model := netAppModels.NetAppVolumeGroupSapHanaModel{
Name: id.VolumeGroupName,
AccountName: id.NetAppAccountName,
Location: location.NormalizeNilable(existing.Model.Location),
Expand Down
Loading