-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
There was a problem hiding this 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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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:
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("bad: cannot revoke SAS on the snapshot: %+v", err) | |
return fmt.Errorf("revoking SAS on %s: %+v", snapshotId, err) |
if props.OsType != nil { | ||
d.Set("os_type", string(*props.OsType)) | ||
} |
There was a problem hiding this comment.
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:
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) |
if accountId := data.StorageAccountId; accountId != nil { | ||
d.Set("storage_account_id", accountId) | ||
} |
There was a problem hiding this comment.
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
if props.DiskSizeGB != nil { | ||
d.Set("disk_size_gb", int(*props.DiskSizeGB)) | ||
} |
There was a problem hiding this comment.
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
if *securityProfile.SecurityType == snapshots.DiskSecurityTypesTrustedLaunch { | ||
trustedLaunchEnabled = true | ||
} |
There was a problem hiding this comment.
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:
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("deleting Snapshot: %+v", err) | |
return fmt.Errorf("deleting %s: %+v", *id, err) |
rawState["id"] = oldId.ID() | ||
return rawState, nil | ||
} | ||
} |
There was a problem hiding this comment.
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?
Hi @tombuildsstuff thanks for reviewing the pr! I've updated the pr to resolve your comments, please take a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎵
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! |
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. |
azurerm_snapshot
to use go-azure-sdk.azurerm_managed_disk
inazurerm_managed_disk
- add state upgrader from V0 to V1 to fix ID issue #18885, snapshot requires a state migration function as well to resolve the enhanced ID validation ofMicrosoft.Compute
vsMicrosoft.compute
in the new sdk.