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_dashboard_grafana_managed_private_endpoint #27781

Merged
merged 11 commits into from
Nov 5, 2024

Conversation

djryanj
Copy link
Contributor

@djryanj djryanj commented Oct 27, 2024

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

This PR adds azurerm_dashboard_grafana_managed_private_endpoint as requested in #23950. Includes documentation and acceptance tests.

Note: auto-approval of the managed endpoints is not possible via this resource (and is noted in the documentation). Other resources are required for that, since the approval must happen on the destination resource.

Sidenote: This is a cleaner PR than one previously submitted.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
$ make acctests SERVICE='dashboard' TESTARGS='-run=TestAccDashboardGrafanaManagedPrivateEndpoint_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/dashboard -run=TestAccDashboardGrafanaManagedPrivateEndpoint_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_basic
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_basic (898.41s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport (815.96s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_complete
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_complete (759.32s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_update
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_update (787.92s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/dashboard     3261.616s

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #23950

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@djryanj
Copy link
Contributor Author

djryanj commented Oct 31, 2024

@stephybun I have updated everything requested. New acceptance tests output:

$ make acctests SERVICE='dashboard' TESTARGS='-run=TestAccDashboardGrafanaManagedPrivateEndpoint_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/dashboard -run=TestAccDashboardGrafanaManagedPrivateEndpoint_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_basic
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_basic (693.02s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport (753.50s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_complete
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_complete (654.78s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_update
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_update (751.20s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/dashboard     2852.512s

Thanks for the thorough review!

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

@djryanj it looks like some of the comments weren't resolved fully. I left another round of comments around consistency, once those are fixed up properly this should be good to go.

Comment on lines 250 to 258
properties := resp.Model

if metadata.ResourceData.HasChange("tags") {
properties.Tags = &model.Tags
}

if err := client.CreateThenPoll(ctx, *id, *properties); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

In nearly all cases the Model has a field called Properties which is why we follow the naming convention of model := resp.Model and props := model.Properties. For clarity and consistency can you please update this to

Suggested change
properties := resp.Model
if metadata.ResourceData.HasChange("tags") {
properties.Tags = &model.Tags
}
if err := client.CreateThenPoll(ctx, *id, *properties); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}
model := resp.Model
if metadata.ResourceData.HasChange("tags") {
model.Tags = &model.Tags
}
if err := client.CreateThenPoll(ctx, *id, *model); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stephybun I believe I have resolved this, but please double check; I had to modify the variable assigned to the model created in line 235. I hope this maintains consistency.

@djryanj
Copy link
Contributor Author

djryanj commented Nov 4, 2024

Updated per request; new acceptance test output:

$ make acctests SERVICE='dashboard' TESTARGS='-run=TestAccDashboardGrafanaManagedPrivateEndpoint_' TESTTIMEOUT='60m'
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test -v ./internal/services/dashboard -run=TestAccDashboardGrafanaManagedPrivateEndpoint_ -timeout 60m -ldflags="-X=github.com/hashicorp/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_basic
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_basic (744.02s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_requiresImport (668.98s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_complete
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_complete (653.80s)
=== RUN   TestAccDashboardGrafanaManagedPrivateEndpoint_update
--- PASS: TestAccDashboardGrafanaManagedPrivateEndpoint_update (671.82s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/dashboard     2738.636s

Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes @djryanj. Apologies if the review comments were confusing or unclear. A lot of this code is boilerplate and yet we unfortunately end up with a lot of variation within the provider. The contributor guide on adding a new resource or data source are good references to follow and contain the pattern that we expect to see in PRs.

The tests are passing so this looks ready to go in, LGTM 🍓

return err
}

var mpe ManagedPrivateEndpointModel
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be fixed now but for future reference, we usually instantiate the schema model as one of model, config, state

Comment on lines +244 to +247
model := resp.Model
if resp.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}
Copy link
Member

Choose a reason for hiding this comment

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

Also minor and doesn't need to be fixed now

Suggested change
model := resp.Model
if resp.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}
if resp.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}
model := resp.Model

Alternatively resp.Model can be assigned to payload instead of model

@stephybun stephybun merged commit 40d78f6 into hashicorp:main Nov 5, 2024
32 of 33 checks passed
@github-actions github-actions bot added this to the v4.9.0 milestone Nov 5, 2024
stephybun added a commit that referenced this pull request Nov 5, 2024
@djryanj
Copy link
Contributor Author

djryanj commented Nov 5, 2024

@stephybun thanks so much for your patience and guidance, it is very appreciated. Go isn't my strongest language, but as usual had I RTFM I think I would have had better success earlier on.

In terms of correcting those last few remaining items, I'm happy to open another PR with those few changes; it's not massive and if it's better for the project to maintain that consistency then I'm happy to do it.

@stephybun
Copy link
Member

You're welcome @djryanj! We would absolutely appreciate a PR to fix up those minor inconsistencies (it would also be acceptable to add it in to your other PR that you opened recently) but also not a huge deal if not. It'll be updated at some point when someone in the team comes across it.

Copy link

github-actions bot commented Dec 7, 2024

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 Dec 7, 2024
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.

Support for azurerm_dashboard_grafana managed private endpoints
3 participants