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 azurerm_managed_disk_sas_token to manage disk exports #15558

Merged
merged 12 commits into from May 9, 2022

Conversation

harshavmb
Copy link
Contributor

@harshavmb harshavmb commented Feb 22, 2022

New resource azurerm_disk_export to manage disk exports.
This PR is inspired from azurerm_storage_account_blob_container_sas datasource

Few details about disk access grants here :: https://docs.microsoft.com/en-us/rest/api/compute/disks/grant-access
https://docs.microsoft.com/en-us/rest/api/compute/disks/revoke-access

With the help of this disk export sas token, we could copy data from disks onto storage blobs or elsewhere without the need of azcopy

Looking forward to hear from you.

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @harshavmb - it looks like there are some issues with the test:

[](https://ci-oss.hashicorp.engineering/viewLog.html?buildId=260323&buildTypeId=TerraformOpenSource_TerraformProviders_AzureRMPublic_AZURERM_SERVICE_PUBLIC_COMPUTE#)------- Stdout: -------
=== RUN   TestAccDataSourceDiskExportSas_basic
=== PAUSE TestAccDataSourceDiskExportSas_basic
=== CONT  TestAccDataSourceDiskExportSas_basic
    testcase.go:110: Step 1/1 error: Check failed: Check 1/4 error: data.azurerm_managed_disk_export.test: Attribute 'managed_disk_id' expected "/subscriptions/42cbb0b8a331-abaf-4e69-8d8f-14b86a40/resourceGroups/disksrg/providers/Microsoft.Compute/disks/disk1", got "/subscriptions/*******/resourceGroups/acctestRG-disk-220223000403491059/providers/Microsoft.Compute/disks/acctestsadsq8vx2"
    testing_new.go:70: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: deleting Managed Disk "acctestsadsq8vx2" (Resource Group "acctestRG-disk-220223000403491059"): compute.DisksClient#Delete: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="OperationNotAllowed" Message="There is an active shared access signature outstanding for disk acctestsadsq8vx2. Call EndGetAccess before attaching or deleting the disk. Learn more here: aka.ms/revokeaccessapi."
        
--- FAIL: TestAccDataSourceDiskExportSas_basic (45.57s)
FAIL

@github-actions github-actions bot added size/XL and removed size/L labels Feb 23, 2022
@harshavmb harshavmb changed the title New datasource azurerm_managed_disk_export for managed disk exports New datasources azurerm_managed_disk_export and azurerm_managed_disk_export_revoke for managed disk exports Feb 23, 2022
@harshavmb
Copy link
Contributor Author

Thanks @harshavmb - it looks like there are some issues with the test:

[](https://ci-oss.hashicorp.engineering/viewLog.html?buildId=260323&buildTypeId=TerraformOpenSource_TerraformProviders_AzureRMPublic_AZURERM_SERVICE_PUBLIC_COMPUTE#)------- Stdout: -------
=== RUN   TestAccDataSourceDiskExportSas_basic
=== PAUSE TestAccDataSourceDiskExportSas_basic
=== CONT  TestAccDataSourceDiskExportSas_basic
    testcase.go:110: Step 1/1 error: Check failed: Check 1/4 error: data.azurerm_managed_disk_export.test: Attribute 'managed_disk_id' expected "/subscriptions/42cbb0b8a331-abaf-4e69-8d8f-14b86a40/resourceGroups/disksrg/providers/Microsoft.Compute/disks/disk1", got "/subscriptions/*******/resourceGroups/acctestRG-disk-220223000403491059/providers/Microsoft.Compute/disks/acctestsadsq8vx2"
    testing_new.go:70: Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: deleting Managed Disk "acctestsadsq8vx2" (Resource Group "acctestRG-disk-220223000403491059"): compute.DisksClient#Delete: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=<nil> Code="OperationNotAllowed" Message="There is an active shared access signature outstanding for disk acctestsadsq8vx2. Call EndGetAccess before attaching or deleting the disk. Learn more here: aka.ms/revokeaccessapi."
        
--- FAIL: TestAccDataSourceDiskExportSas_basic (45.57s)
FAIL

Hi @katbyte ,

Thanks for the review. Indeed, it was something I missed. I added another data source to revoke the granted access on the disk.
Tested locally, it worked. Please rereview this..

Copy link
Member

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @harshavmb

Thanks for this PR

Taking a look through here since these are creating and subsequently revoking resources on the Azure side these want to be a single Resource rather than two Data Sources here - so can we update this to be a single Resource rather than two Data Sources?

Thanks!

@github-actions github-actions bot added size/L and removed size/XL labels Feb 25, 2022
@harshavmb harshavmb changed the title New datasources azurerm_managed_disk_export and azurerm_managed_disk_export_revoke for managed disk exports New resource azurerm_disk_export to manage disk exports Feb 25, 2022
@harshavmb
Copy link
Contributor Author

hi @harshavmb

Thanks for this PR

Taking a look through here since these are creating and subsequently revoking resources on the Azure side these want to be a single Resource rather than two Data Sources here - so can we update this to be a single Resource rather than two Data Sources?

Thanks!

Hi @tombuildsstuff

I've added a new resource as you suggested. Changes LGTM, tested locally.

Please re-review.

@harshavmb

This comment was marked as off-topic.

Copy link
Member

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @harshavmb

Thanks for this PR - apologies for the delayed re-review here.

I've taken a look through and left some more comments inline, in particular I can't see this defined as a "Disk Export" within Azure, since this is a SAS Token for a Managed Disk, I'm thinking that this resource would make more sense with that name -WDYT?

Thanks!

internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
Comment on lines 82 to 88
diskName := parsedManagedDiskId.DiskName
resourceGroupName := parsedManagedDiskId.ResourceGroup

grantAccessData := compute.GrantAccessData{
Access: compute.AccessLevel(access),
DurationInSeconds: &durationInSeconds,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're missing a Requires Import check here, we need to check if the Disk already has an Export and if so, raise a "this should be imported" error, (as below) it appears that this can be accessed by retrieving the disk and checking if it has a DiskAccess URI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tombuildsstuff ,

I think disk access is more related to private links. I did check the API again here. diskAccessId existed only for disks with private endpoints.

Having said that, I found diskState parameter which will be ActiveSAS when the disk export is active. I'll check this parameter.

internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_export_resource_test.go Outdated Show resolved Hide resolved
internal/services/compute/registration.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added size/XL and removed size/L labels Apr 24, 2022
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, just some minor comments i've left inline and this should be good!

website/docs/r/disk_export.html.markdown Outdated Show resolved Hide resolved
internal/services/compute/disk_sas_token_resource.go Outdated Show resolved Hide resolved
internal/services/compute/disk_sas_token_resource_test.go Outdated Show resolved Hide resolved
website/docs/r/disk_export.html.markdown Outdated Show resolved Hide resolved

* `create` - (Defaults to 30 minutes) Used when creating the Disk.
* `read` - (Defaults to 5 minutes) Used when retrieving the Disk.
* `delete` - (Defaults to 30 minutes) Used when deleting the Disk.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should include how to import the resource here?

Copy link
Contributor Author

@harshavmb harshavmb May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SAS tokens are ephemeral, I don't know how useful it would be to import the disk here.

I'm just importing the managed disk resource id. Hope that's okay..

@harshavmb harshavmb requested a review from katbyte May 6, 2022 09:17
@harshavmb
Copy link
Contributor Author

Thanks, just some minor comments i've left inline and this should be good!

Thank you, I've made changes as requested. Let me know if there is something I need to change

@katbyte katbyte changed the title New resource azurerm_disk_export to manage disk exports New resource azurerm_managed_disk_sas_token to manage disk exports May 8, 2022
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @harshavmb ! LGTM 🦀

@katbyte katbyte merged commit 0b4c283 into hashicorp:main May 9, 2022
@github-actions github-actions bot added this to the v3.6.0 milestone May 9, 2022
katbyte added a commit that referenced this pull request May 9, 2022
@github-actions
Copy link

This functionality has been released in v3.6.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants