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

r\shared_image: Add support for support_accelerated_network #15562

Merged
merged 5 commits into from
Mar 22, 2022

Conversation

myc2h6o
Copy link
Contributor

@myc2h6o myc2h6o commented Feb 23, 2022

Fix #15441

  • Add new gallery image feature support_accelerated_network

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Feb 23, 2022

$ TF_ACC=1 go test -v ./internal/services/compute -run='TestAccSharedImage_' -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc" === RUN TestAccSharedImage_basic
=== PAUSE TestAccSharedImage_basic
=== RUN TestAccSharedImage_basic_hyperVGeneration_V2
=== PAUSE TestAccSharedImage_basic_hyperVGeneration_V2
=== RUN TestAccSharedImage_requiresImport
=== PAUSE TestAccSharedImage_requiresImport
=== RUN TestAccSharedImage_complete
=== PAUSE TestAccSharedImage_complete
=== RUN TestAccSharedImage_specialized
=== PAUSE TestAccSharedImage_specialized
=== RUN TestAccSharedImage_withTrustedLaunchEnabled
=== PAUSE TestAccSharedImage_withTrustedLaunchEnabled
=== RUN TestAccSharedImage_withSupportAcceleratedNetwork
=== PAUSE TestAccSharedImage_withSupportAcceleratedNetwork
=== CONT TestAccSharedImage_basic
=== CONT TestAccSharedImage_specialized
=== CONT TestAccSharedImage_withSupportAcceleratedNetwork
=== CONT TestAccSharedImage_withTrustedLaunchEnabled
=== CONT TestAccSharedImage_requiresImport
=== CONT TestAccSharedImage_basic_hyperVGeneration_V2
=== CONT TestAccSharedImage_complete
--- PASS: TestAccSharedImage_specialized (353.76s)
--- PASS: TestAccSharedImage_complete (354.88s)
--- PASS: TestAccSharedImage_basic_hyperVGeneration_V2 (355.80s)
--- PASS: TestAccSharedImage_withTrustedLaunchEnabled (356.04s)
--- PASS: TestAccSharedImage_withSupportAcceleratedNetwork (357.06s)
--- PASS: TestAccSharedImage_basic (358.17s)
--- PASS: TestAccSharedImage_requiresImport (383.54s)
PASS
ok github.com/hashicorp/terraform-provider-azurerm/internal/services/compute 384.237s

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.

hi @myc2h6o

Thanks for this PR.

I've taken a look through and left some comments inline, but if we can address those then we should be able to take another look.

Thanks!

Comment on lines 190 to 196
var features []compute.GalleryImageFeature
if d.Get("trusted_launch_enabled").(bool) {
features = append(features, compute.GalleryImageFeature{
Name: utils.String("SecurityType"),
Value: utils.String("TrustedLaunch"),
})
}
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 remove the expand function here and leave this as it was (adding the new field) - passing values out of d in functions makes it more likely we'll introduce bugs when refactoring etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, moved to Create.

Comment on lines 436 to 443
if d.Get("trusted_launch_enabled").(bool) {
features = append(features, compute.GalleryImageFeature{
Name: utils.String("SecurityType"),
Value: utils.String("TrustedLaunch"),
})
}

if d.Get("support_accelerated_network").(bool) {
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) can we move this into the Create function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return &features
}

func flattenAndSetGalleryImageFeatures(d *pluginsdk.ResourceData, features *[]compute.GalleryImageFeature) {
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) can we move this into the read function - AndSet functions make it easier for bugs to be introduced

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 458 to 471
featuresMap := make(map[string]string, len(*features))
for _, feature := range *features {
if feature.Name != nil && feature.Value != nil {
featuresMap[*feature.Name] = *feature.Value
}
}

if featuresMap["SecurityType"] == "TrustedLaunch" {
trustedLaunchEnabled = true
}

if strings.EqualFold(featuresMap["IsAcceleratedNetworkSupported"], "true") {
supportAcceleratedNetwork = true
}
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
featuresMap := make(map[string]string, len(*features))
for _, feature := range *features {
if feature.Name != nil && feature.Value != nil {
featuresMap[*feature.Name] = *feature.Value
}
}
if featuresMap["SecurityType"] == "TrustedLaunch" {
trustedLaunchEnabled = true
}
if strings.EqualFold(featuresMap["IsAcceleratedNetworkSupported"], "true") {
supportAcceleratedNetwork = true
}
for _, feature := range *features {
if feature.Name == nil || feature.Value == nil {
continue
}
if strings.EqualFold(*feature.Name, "SecurityType") {
trustedLaunchEnabled = strings.EqualFold(*feature.Value, "TrustedLaunch")
}
if strings.EqualFold(*feature.Name, "IsAcceleratedNetworkSupported") {
supportAcceleratedNetwork = strings.EqualFold(*feature.Value, "true")
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Looks more straightforward since we will probably not having too many features here

@@ -160,6 +161,12 @@ func resourceSharedImage() *pluginsdk.Resource {
ForceNew: true,
},

"support_accelerated_network": {
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 document this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, forgot the doc. Added

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Feb 24, 2022

Hi @tombuildsstuff I've updated the pr, please take a look

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Feb 24, 2022

New test result after change:
image

@@ -82,6 +82,8 @@ The following arguments are supported:

* `trusted_launch_enabled` - (Optional) Specifies if Trusted Launch has to be enabled for the Virtual Machine created from the Shared Image. Defaults to `false`. Changing this forces a new resource to be created.

* `support_accelerated_network` - (Optional) Specifies if the Shared Image supports Accelerated Network. Defaults to `false`. Changing this forces a new resource to be created.
Copy link
Collaborator

Choose a reason for hiding this comment

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

as this is a bool, could we change this to

Suggested change
* `support_accelerated_network` - (Optional) Specifies if the Shared Image supports Accelerated Network. Defaults to `false`. Changing this forces a new resource to be created.
* `accelerated_network_support_enabled` - (Optional) Specifies if the Shared Image supports Accelerated Network. Defaults to `false`. Changing this forces a new resource to be created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Mar 4, 2022

Test result after update
image

@myc2h6o
Copy link
Contributor Author

myc2h6o commented Mar 4, 2022

Hi @katbyte I've updated the field name, could you take another 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.

Thanks @myc2h6o - LGTM 🏗️

@katbyte katbyte merged commit de095a1 into hashicorp:main Mar 22, 2022
@github-actions github-actions bot added this to the v3.0.0 milestone Mar 22, 2022
katbyte added a commit that referenced this pull request Mar 22, 2022
@myc2h6o myc2h6o deleted the image_acc_network branch March 23, 2022 05:35
@github-actions
Copy link

This functionality has been released in v3.0.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 Apr 24, 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.

r/shared_image: support for advanced_networking_enabled
3 participants