Skip to content

New data source: azurerm_dynatrace_monitor#28381

Merged
WodansSon merged 4 commits intohashicorp:mainfrom
jiaweitao001:dynatrace_datasource
Feb 15, 2025
Merged

New data source: azurerm_dynatrace_monitor#28381
WodansSon merged 4 commits intohashicorp:mainfrom
jiaweitao001:dynatrace_datasource

Conversation

@jiaweitao001
Copy link
Collaborator

@jiaweitao001 jiaweitao001 commented Dec 25, 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

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

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevent documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

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)

image

Change Log

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

  • New Data Source: azurerm_dynatrace_monitor [GH-00000]

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 #0000

Note

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

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Hi @jiaweitao001 - Thanks for the PR. Some comments to take a look at below if you could please?

Comment on lines +133 to +152
"environment_properties": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"environment_info": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"environment_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
},
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we're doing 2 levels of nesting here for a single value? Can this just be flattened to the top level?

Also, this property doesn't appear to be supported by the related resource, should it even be included here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'd better not flatten this because according to the service team, there are a bunch of other attributes under environment_properties and environment_info, but they do not want them on TF right now. We will have to onboard them once they request in the future.

This property is not supported by the related resource is because it's an optional + computed attribute and its value comes from the API response only, that's why we will have to onboard the data source first. Then I'll add it to the related resource.

Identity: identityProps,
EnvironmentProperties: FlattenDynatraceEnvironmentProperties(props.DynatraceEnvironmentProperties),
PlanData: FlattenDynatracePlanData(props.PlanData),
UserInfo: FlattenDynatraceUserInfo(metadata.ResourceData.Get("user").([]interface{})),
Copy link
Member

Choose a reason for hiding this comment

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

This is computed only, so we cannot "Get" it here, if this is not returned by the API, it cannot be included in the Data Source as it will always be empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.

Comment on lines +158 to +162
first_name = "Alice"
last_name = "Bobab"
email = "agarwald@microsoft.com"
phone_number = "123456"
country = "westus"
Copy link
Member

Choose a reason for hiding this comment

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

Why are we now supplying data directly here? This looks like it might actually be a real email (or could be in future?) Is this a mistake from local testing that should be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, it was for local testing, will remove them.


---

A `user` block supports the following:
Copy link
Member

Choose a reason for hiding this comment

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

and here

Suggested change
A `user` block supports the following:
A `user` block exports the following:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.


---

A `plan` block supports the following:
Copy link
Member

Choose a reason for hiding this comment

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

same here

Suggested change
A `plan` block supports the following:
A `plan` block exports the following:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.


---

A `identity` block supports the following:
Copy link
Member

Choose a reason for hiding this comment

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

Since this block is computed only, it's exports rather than supports.

Suggested change
A `identity` block supports the following:
An `identity` block exports the following:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.


A `identity` block supports the following:

* `type` - The type of identity used for the resource. Only possible value is `SystemAssigned`.
Copy link
Member

Choose a reason for hiding this comment

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

Since this is computed only, we don't specify possible values.

Suggested change
* `type` - The type of identity used for the resource. Only possible value is `SystemAssigned`.
* `type` - The type of identity used for the resource.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jackofallops / @jiaweitao001, should we even expose type if the only valid value is SystemAssigned?

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@jiaweitao001, Thank you for this PR! I have given it a look, while it mostly LGTM I did leave a comment with some questions about the implementation. If you can take a look at that, I will be happy to look again once that is addressed. Thanks! 🚀

Comment on lines +39 to +63
func FlattenDynatraceEnvironmentProperties(input *monitors.DynatraceEnvironmentProperties) []EnvironmentProperties {
if input == nil {
return []EnvironmentProperties{}
}

environmentInfo := FlattenDynatraceEnvironmentInfo(input.EnvironmentInfo)

return []EnvironmentProperties{
{
EnvironmentInfo: environmentInfo,
},
}
}

func FlattenDynatraceEnvironmentInfo(input *monitors.EnvironmentInfo) []EnvironmentInfo {
if input == nil {
return []EnvironmentInfo{}
}

return []EnvironmentInfo{
{
EnvironmentId: pointer.From(input.EnvironmentId),
},
}
}
Copy link
Collaborator

@WodansSon WodansSon Feb 14, 2025

Choose a reason for hiding this comment

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

Couldn't these two functions be collapsed into a single function (e.g., FlattenDynatraceEnvironmentProperties)? I don't understand why we need the second FlattenDynatraceEnvironmentInfo function unless it is called from another resource? Also, should these be public functions vs. a private function (e.g., FlattenDynatraceEnvironmentProperties vs. flattenDynatraceEnvironmentProperties)?

Suggested change
func FlattenDynatraceEnvironmentProperties(input *monitors.DynatraceEnvironmentProperties) []EnvironmentProperties {
if input == nil {
return []EnvironmentProperties{}
}
environmentInfo := FlattenDynatraceEnvironmentInfo(input.EnvironmentInfo)
return []EnvironmentProperties{
{
EnvironmentInfo: environmentInfo,
},
}
}
func FlattenDynatraceEnvironmentInfo(input *monitors.EnvironmentInfo) []EnvironmentInfo {
if input == nil {
return []EnvironmentInfo{}
}
return []EnvironmentInfo{
{
EnvironmentId: pointer.From(input.EnvironmentId),
},
}
}
func FlattenDynatraceEnvironmentProperties(input *monitors.DynatraceEnvironmentProperties) []EnvironmentProperties {
result := []EnvironmentProperties{
EnvironmentInfo: pointer.To([]EnvironmentInfo{}),
}
if input == nil {
return result
}
if input.EnvironmentInfo.EnvironmentId != nil {
result.EnvironmentInfo.EnvironmentId = pointer.From(input.EnvironmentInfo.EnvironmentId)
}
return result
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@WodansSon , I'm not combining these 2 functions because there're other attributes under this EnvironmentProperties as well as EnvironmentInfo, the service said they will give us more details on how to configure them recently so I'll leave the functions uncollapsed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jiaweitao001, I understand that, however, as more and more child EnvironmentProperties are exposed by the service team we would just need to inline those blocks into the one flatten function (e.g, flattenDynatraceEnvironmentsProperties), making the code much easier to read/understand and maintain moving forward for repo maintainers. If we end up with 12 flatten functions that get called from the parent flatten function it becomes exponentially more complicated to understand what the code is doing and review.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense. I'll combine these functions.

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@jiaweitao001, thanks for pushing those changes, this LGTM now! 🚀

@WodansSon
Copy link
Collaborator

Tests Pass?:
image

@WodansSon WodansSon merged commit 3cd63a3 into hashicorp:main Feb 15, 2025
36 checks passed
@github-actions github-actions bot added this to the v4.20.0 milestone Feb 15, 2025
WodansSon added a commit that referenced this pull request Feb 15, 2025
hqhqhqhqhqhqhqhqhqhqhq pushed a commit to hqhqhqhqhqhqhqhqhqhqhq/terraform-provider-azurerm that referenced this pull request Feb 26, 2025
* New data source: azurerm_dynatrace_monitor

* Remove deprecated method

* address comments

* Address comment on collapsing flatten func
@github-actions
Copy link
Contributor

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 Mar 18, 2025
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.

4 participants