New data source: azurerm_dynatrace_monitor#28381
Conversation
jackofallops
left a comment
There was a problem hiding this comment.
Hi @jiaweitao001 - Thanks for the PR. Some comments to take a look at below if you could please?
| "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, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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{})), |
There was a problem hiding this comment.
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.
| first_name = "Alice" | ||
| last_name = "Bobab" | ||
| email = "agarwald@microsoft.com" | ||
| phone_number = "123456" | ||
| country = "westus" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Right, it was for local testing, will remove them.
|
|
||
| --- | ||
|
|
||
| A `user` block supports the following: |
There was a problem hiding this comment.
and here
| A `user` block supports the following: | |
| A `user` block exports the following: |
|
|
||
| --- | ||
|
|
||
| A `plan` block supports the following: |
There was a problem hiding this comment.
same here
| A `plan` block supports the following: | |
| A `plan` block exports the following: |
|
|
||
| --- | ||
|
|
||
| A `identity` block supports the following: |
There was a problem hiding this comment.
Since this block is computed only, it's exports rather than supports.
| A `identity` block supports the following: | |
| An `identity` block exports the following: |
|
|
||
| A `identity` block supports the following: | ||
|
|
||
| * `type` - The type of identity used for the resource. Only possible value is `SystemAssigned`. |
There was a problem hiding this comment.
Since this is computed only, we don't specify possible values.
| * `type` - The type of identity used for the resource. Only possible value is `SystemAssigned`. | |
| * `type` - The type of identity used for the resource. |
There was a problem hiding this comment.
@jackofallops / @jiaweitao001, should we even expose type if the only valid value is SystemAssigned?
There was a problem hiding this comment.
@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! 🚀
| 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), | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
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)?
| 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 | |
| } |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Make sense. I'll combine these functions.
WodansSon
left a comment
There was a problem hiding this comment.
@jiaweitao001, thanks for pushing those changes, this LGTM now! 🚀
* New data source: azurerm_dynatrace_monitor * Remove deprecated method * address comments * Address comment on collapsing flatten func
|
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. |

Community Note
Description
PR Checklist
For example: “
resource_name_here- description of change e.g. adding propertynew_property_name_here”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_dynatrace_monitor[GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #0000
Note
If this PR changes meaningfully during the course of review please update the title and description as required.