Skip to content

Commit

Permalink
changes requested
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Apr 15, 2021
1 parent c59c4f8 commit dfa8059
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
2 changes: 1 addition & 1 deletion azurerm/internal/services/compute/managed_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func resourceManagedDisk() *schema.Resource {
string(compute.AllowAll),
string(compute.AllowPrivate),
string(compute.DenyAll),
}, true),
}, false),
},

"disk_access_id": {
Expand Down
53 changes: 11 additions & 42 deletions azurerm/internal/services/compute/managed_disk_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package compute_test
import (
"context"
"fmt"
"net/http"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-12-01/compute"
Expand Down Expand Up @@ -331,7 +330,7 @@ func TestAccAzureRMManagedDisk_create_withNetworkPolicy(t *testing.T) {
{
Config: testAccAzureRMManagedDisk_create_withNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
Expand All @@ -345,14 +344,14 @@ func TestAccAzureRMManagedDisk_update_withNetworkPolicy(t *testing.T) {
{
Config: testAccAzureRMManagedDisk_create_withNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
resource.TestCheckResourceAttr(data.ResourceName, "network_access_policy", "DenyAll"),
),
},
{
Config: testAccAzureRMManagedDisk_update_withNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
resource.TestCheckResourceAttr(data.ResourceName, "network_access_policy", "DenyAll"),
),
},
Expand All @@ -367,7 +366,7 @@ func TestAccAzureRMManagedDisk_import_withNetworkPolicy(t *testing.T) {
{
Config: testAccAzureRMManagedDisk_create_withNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
Expand All @@ -385,9 +384,10 @@ func TestAccAzureRMManagedDisk_create_withAllowPrivateNetworkPolicy(t *testing.T
{
Config: testAccAzureRMManagedDisk_create_withAllowPrivateNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

Expand All @@ -399,17 +399,19 @@ func TestAccAzureRMManagedDisk_update_withAllowPrivateNetworkPolicy(t *testing.T
{
Config: testAccAzureRMManagedDisk_create_withAllowPrivateNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
resource.TestCheckResourceAttr(data.ResourceName, "network_access_policy", "AllowPrivate"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMManagedDisk_update_withAllowPrivateNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
resource.TestCheckResourceAttr(data.ResourceName, "network_access_policy", "AllowPrivate"),
),
},
data.ImportStep(),
})
}

Expand All @@ -421,7 +423,7 @@ func TestAccAzureRMManagedDisk_import_withAllowPrivateNetworkPolicy(t *testing.T
{
Config: testAccAzureRMManagedDisk_create_withAllowPrivateNetworkPolicy(data),
Check: resource.ComposeTestCheckFunc(
testCheckManagedDiskExists(data.ResourceName, true),
check.That(data.ResourceName).ExistsInAzure(r),
),
},
{
Expand All @@ -431,39 +433,6 @@ func TestAccAzureRMManagedDisk_import_withAllowPrivateNetworkPolicy(t *testing.T
})
}

// nolint unparam
func testCheckManagedDiskExists(resourceName string, shouldExist bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Compute.DisksClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext

rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return fmt.Errorf("Not found: %s", resourceName)
}

dName := rs.Primary.Attributes["name"]
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
if !hasResourceGroup {
return fmt.Errorf("Bad: no resource group found in state for disk: %s", dName)
}

resp, err := client.Get(ctx, resourceGroup, dName)
if err != nil {
return fmt.Errorf("Bad: Get on diskClient: %+v", err)
}

if resp.StatusCode == http.StatusNotFound && shouldExist {
return fmt.Errorf("Bad: ManagedDisk %q (resource group %q) does not exist", dName, resourceGroup)
}
if resp.StatusCode != http.StatusNotFound && !shouldExist {
return fmt.Errorf("Bad: ManagedDisk %q (resource group %q) still exists", dName, resourceGroup)
}

return nil
}
}

func (ManagedDiskResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.ManagedDiskID(state.ID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ output "id" {

* `zones` - A list of Availability Zones where the Managed Disk exists.

* `network_access_policy` - Policy for accessing the disk via network. Accepted values: AllowAll, AllowPrivate, DenyAll
* `network_access_policy` - Policy for accessing the disk via network.

* `disk_access_id` - The ID of the disk access resource for using private endpoints on disks.

Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The following arguments are supported:

* `disk_encryption_set_id` - (Optional) The ID of a Disk Encryption Set which should be used to encrypt this Managed Disk.

-> **NOTE:** The Disk Encryption Set must have the `Reader` Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault
~> **NOTE:** The Disk Encryption Set must have the `Reader` Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault

~> **NOTE:** Disk Encryption Sets are in Public Preview in a limited set of regions

Expand Down Expand Up @@ -121,11 +121,13 @@ The following arguments are supported:

* `zones` - (Optional) A collection containing the availability zone to allocate the Managed Disk in.

* `network_access_policy` - Policy for accessing the disk via network. Accepted values: AllowAll, AllowPrivate, DenyAll
~> **Note**: Availability Zones are [only supported in select regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview).

* `network_access_policy` - Policy for accessing the disk via network. Allowed values are `AllowAll`, `AllowPrivate`, and `DenyAll`.

* `disk_access_id` - The ID of the disk access resource for using private endpoints on disks.

-> **Note**: Availability Zones are [only supported in select regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview).
~> **Note**: `disk_access_id` is only supported when `network_access_policy` is set to `AllowPrivate`.

For more information on managed disks, such as sizing options and pricing, please check out the [Azure Documentation](https://docs.microsoft.com/en-us/azure/storage/storage-managed-disks-overview).

Expand Down

0 comments on commit dfa8059

Please sign in to comment.