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

azurerm_snapshot - switch to go-azure-sdk #18957

Merged
merged 4 commits into from
Oct 26, 2022
Merged

Conversation

myc2h6o
Copy link
Contributor

@myc2h6o myc2h6o commented Oct 25, 2022

Copy link
Contributor

@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.

hey @myc2h6o

Thanks for this PR - I've taken a look through and left some comments inline, but this is off to a good start - if we can fix those up then we should be able to take another look and get this merged.

Thanks!

Computed: true,
},

"encryption_settings": encryptionSettingsSchema(),
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a point-in-time reference so needs to be in-lined else it'll fall out of sync

Copy link
Contributor Author

@myc2h6o myc2h6o Oct 26, 2022

Choose a reason for hiding this comment

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

Understood, I've copied the schema to this file. As the schema function checks feature flag, I'm still putting it in the function snapshotEncryptionSettingsSchemaV0

--Update
I've removed the feature flag in it and copy the schema inline per #18993 (comment)

return rawState, err
}

rawState["id"] = oldId.ID()
Copy link
Contributor

Choose a reason for hiding this comment

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

we should log the new ID:

Suggested change
rawState["id"] = oldId.ID()
newId := oldId.ID()
log.Printf("[DEBUG] Updating the ID from %q to %q", oldIdRaw, newId)
rawState["id"] = newId


func (SnapshotV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId, err := snapshots.ParseSnapshotIDInsensitively(rawState["id"].(string))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
oldId, err := snapshots.ParseSnapshotIDInsensitively(rawState["id"].(string))
oldIdRaw := rawState["id"].(string)
oldId, err := snapshots.ParseSnapshotIDInsensitively(oldIdRaw)

future, err := client.Compute.SnapshotsClient.RevokeAccess(ctx, resourceGroup, snapShotName)
if err != nil {
snapshotId := snapshots.NewSnapshotID(subscriptionId, resourceGroup, snapShotName)
if err := client.Compute.SnapshotsClient.RevokeAccessThenPoll(ctx, snapshotId); err != nil {
return fmt.Errorf("bad: cannot revoke SAS on the snapshot: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("bad: cannot revoke SAS on the snapshot: %+v", err)
return fmt.Errorf("revoking SAS on %s: %+v", snapshotId, err)

Comment on lines 136 to 138
if props.OsType != nil {
d.Set("os_type", string(*props.OsType))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this should always have a value:

Suggested change
if props.OsType != nil {
d.Set("os_type", string(*props.OsType))
}
osType := ""
if props.OsType != nil {
osType = string(*props.OsType)
}
d.Set("os_type", osType)

Comment on lines 212 to 214
if accountId := data.StorageAccountId; accountId != nil {
d.Set("storage_account_id", accountId)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) this can always be set

Comment on lines 216 to 218
if props.DiskSizeGB != nil {
d.Set("disk_size_gb", int(*props.DiskSizeGB))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) this can always be set

Comment on lines 226 to 228
if *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch {
trustedLaunchEnabled = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) this can be reduced to:

Suggested change
if *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch {
trustedLaunchEnabled = true
}
trustedLaunchEnabled = *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch

}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
if err := client.DeleteThenPoll(ctx, *id); err != nil {
return fmt.Errorf("deleting Snapshot: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("deleting Snapshot: %+v", err)
return fmt.Errorf("deleting %s: %+v", *id, err)

rawState["id"] = oldId.ID()
return rawState, nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also remove the old Resource ID Type from resourceids.go and the generated ID Parsers/Validators?

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Oct 26, 2022

Hi @tombuildsstuff thanks for reviewing the pr! I've updated the pr to resolve your comments, please take a look.

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.

LGTM 🎵

@katbyte katbyte merged commit 2034046 into hashicorp:main Oct 26, 2022
katbyte added a commit that referenced this pull request Oct 26, 2022
@github-actions github-actions bot added this to the v3.29.0 milestone Oct 26, 2022
@myc2h6o myc2h6o deleted the snapshot_sdk branch October 27, 2022 02:04
@github-actions
Copy link

This functionality has been released in v3.29.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 Nov 27, 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