-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_netapp_volume_group_sap_hana
(#21290)
- Loading branch information
1 parent
19511ae
commit 68ae4ad
Showing
45 changed files
with
6,307 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
285 changes: 285 additions & 0 deletions
285
internal/services/netapp/netapp_volume_group_sap_hana_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
internal/services/netapp/netapp_volume_group_sap_hana_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
Oops, something went wrong.