Skip to content

Commit

Permalink
New Resource: azurerm_netapp_volume_group_sap_hana (#21290)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarquesc authored and tombuildsstuff committed Apr 27, 2023
1 parent 19511ae commit 68ae4ad
Show file tree
Hide file tree
Showing 45 changed files with 6,307 additions and 267 deletions.
1 change: 1 addition & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
mssql.Registration{},
mssqlmanagedinstance.Registration{},
network.Registration{},
netapp.Registration{},
nginx.Registration{},
policy.Registration{},
privatednsresolver.Registration{},
Expand Down
6 changes: 6 additions & 0 deletions internal/services/netapp/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/netappaccounts"
"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/volumes"
"github.com/hashicorp/go-azure-sdk/resource-manager/netapp/2022-05-01/volumesreplication"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand All @@ -14,6 +15,7 @@ type Client struct {
AccountClient *netappaccounts.NetAppAccountsClient
PoolClient *capacitypools.CapacityPoolsClient
VolumeClient *volumes.VolumesClient
VolumeGroupClient *volumegroups.VolumeGroupsClient
VolumeReplicationClient *volumesreplication.VolumesReplicationClient
SnapshotClient *snapshots.SnapshotsClient
SnapshotPoliciesClient *snapshotpolicy.SnapshotPolicyClient
Expand All @@ -29,6 +31,9 @@ func NewClient(o *common.ClientOptions) *Client {
volumeClient := volumes.NewVolumesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&volumeClient.Client, o.ResourceManagerAuthorizer)

volumeGroupClient := volumegroups.NewVolumeGroupsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&volumeGroupClient.Client, o.ResourceManagerAuthorizer)

volumeReplicationClient := volumesreplication.NewVolumesReplicationClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&volumeReplicationClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -42,6 +47,7 @@ func NewClient(o *common.ClientOptions) *Client {
AccountClient: &accountClient,
PoolClient: &poolClient,
VolumeClient: &volumeClient,
VolumeGroupClient: &volumeGroupClient,
VolumeReplicationClient: &volumeReplicationClient,
SnapshotClient: &snapshotClient,
SnapshotPoliciesClient: &snapshotPoliciesClient,
Expand Down
285 changes: 285 additions & 0 deletions internal/services/netapp/netapp_volume_group_sap_hana_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
package netapp

import (
"context"
"fmt"
"net/http"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"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"
"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{}

func (r NetAppVolumeGroupSapHanaDataSource) ResourceType() string {
return "azurerm_netapp_volume_group_sap_hana"
}

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

func (r NetAppVolumeGroupSapHanaDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return volumegroups.ValidateVolumeGroupID
}

func (r NetAppVolumeGroupSapHanaDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
},

"resource_group_name": commonschema.ResourceGroupName(),

"account_name": {
Type: pluginsdk.TypeString,
Required: true,
},
}
}

func (r NetAppVolumeGroupSapHanaDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"location": commonschema.LocationComputed(),

"group_description": {
Type: pluginsdk.TypeString,
Computed: true,
},

"application_identifier": {
Type: pluginsdk.TypeString,
Computed: true,
},

"volume": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"capacity_pool_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"proximity_placement_group_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"volume_spec_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"volume_path": {
Type: pluginsdk.TypeString,
Computed: true,
},

"service_level": {
Type: pluginsdk.TypeString,
Computed: true,
},

"subnet_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"protocols": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"security_style": {
Type: pluginsdk.TypeString,
Computed: true,
},

"storage_quota_in_gb": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"throughput_in_mibps": {
Type: pluginsdk.TypeFloat,
Required: true,
},

"export_policy_rule": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"rule_index": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"allowed_clients": {
Type: pluginsdk.TypeString,
Computed: true,
},

"nfsv3_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"nfsv41_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"unix_read_only": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"unix_read_write": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"root_access_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
},
},
},

"tags": commonschema.TagsDataSource(),

"snapshot_directory_visible": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"mount_ip_addresses": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

"data_protection_replication": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"endpoint_type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"remote_volume_location": commonschema.LocationComputed(),

"remote_volume_resource_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"replication_frequency": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"data_protection_snapshot_policy": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"snapshot_policy_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
},
},
},
}
}

func (r NetAppVolumeGroupSapHanaDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {

client := metadata.Client.NetApp.VolumeGroupClient

var state NetAppVolumeGroupSapHanaDataSourceModel
if err := metadata.Decode(&state); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

id := volumegroups.NewVolumeGroupID(metadata.Client.Account.SubscriptionId, state.ResourceGroupName, state.AccountName, state.Name)

resp, err := client.VolumeGroupsGet(ctx, id)
if err != nil {
if resp.HttpResponse.StatusCode == http.StatusNotFound {
return metadata.MarkAsGone(id)
}
return fmt.Errorf("retrieving %s: %v", id, err)
}

model := resp.Model
if model == nil {
return fmt.Errorf("retrieving %s: model was nil", id)
}

state.Location = location.Normalize(pointer.From(model.Location))
state.ApplicationIdentifier = pointer.From(model.Properties.GroupMetaData.ApplicationIdentifier)
state.GroupDescription = pointer.From(model.Properties.GroupMetaData.GroupDescription)

volumes, err := flattenNetAppVolumeGroupVolumes(ctx, model.Properties.Volumes, metadata)
if err != nil {
return fmt.Errorf("setting `volume`: %+v", err)
}

state.Volumes = volumes

metadata.SetID(id)

return metadata.Encode(&state)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package netapp_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type NetAppVolumeGroupSapHanaDataSource struct{}

func TestAccNetAppVolumeGroupSapHanaDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_netapp_volume_group_sap_hana", "test")
d := NetAppVolumeGroupSapHanaDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("name").Exists(),
check.That(data.ResourceName).Key("resource_group_name").Exists(),
check.That(data.ResourceName).Key("volume.1.volume_spec_name").HasValue("log"),
),
},
})
}

func (d NetAppVolumeGroupSapHanaDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_netapp_volume_group_sap_hana" "test" {
name = azurerm_netapp_volume_group_sap_hana.test.name
resource_group_name = azurerm_netapp_volume_group_sap_hana.test.resource_group_name
account_name = azurerm_netapp_volume_group_sap_hana.test.account_name
}
`, NetAppVolumeGroupSapHanaResource{}.basic(data))
}
Loading

0 comments on commit 68ae4ad

Please sign in to comment.