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_hdinsight_cluster_pool #25937

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jiaweitao001
Copy link
Contributor

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 "+1" or "me too" comments, they generate extra noise for PR followers and do not help prioritize for review

Description

Add support for azurerm_hdinsight_cluster_pool.

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)
--- PASS: TestAccHDInsightClusterPools_Update (1390.31s)
--- PASS: TestAccHDInsightClusterPools_complete (1627.15s)
--- PASS: TestAccHDInsightClusterPools_basic (1055.77s)
--- PASS: TestAccHDInsightClusterPools_requiresImport (1043.13s)

Change Log

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

  • New Resource: azurerm_hdinsight_cluster_pool

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
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 opening the PR. It mostly looks good however I have left a couple of suggestions and a question or two that I would like clarification on. If we get those straightened out we can move the PR to the next step. 🚀

Required: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"cluster_pool_version": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the parent field is already called cluster_pool_profile, would it make sense to shorten the name of the child element name to just version to avoid redundancy?

Suggested change
"cluster_pool_version": {
"version": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

Optional: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"log_analytics_profile_enabled": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, since the parent is called log_analytics_profile we can assume the the child fields refer to it so the prefix of this field name seems not needed, what do you think?

Suggested change
"log_analytics_profile_enabled": {
"enabled": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

ValidateFunc: commonids.ValidateSubnetID,
},

"private_api_server_enabled": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name of the field is confusing, is this referring to a private link?

Suggested change
"private_api_server_enabled": {
"private_link_enabled": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

return fmt.Errorf("reading %s: %+v", *id, err)
}

model := existing.Model
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we check to see if the model is nil before we start accessing it's members?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will change.

Comment on lines +356 to +464
}

func expandComputeProfile(profiles []ComputeProfile) hdinsights.ClusterPoolComputeProfile {
result := hdinsights.ClusterPoolComputeProfile{
VMSize: profiles[0].VmSize,
}
return result
}

func expandLogAnalyticsProfile(profiles []LogAnalyticsProfile) *hdinsights.ClusterPoolLogAnalyticsProfile {
if len(profiles) == 0 {
return nil
}

result := hdinsights.ClusterPoolLogAnalyticsProfile{
Enabled: profiles[0].LogAnalyticsProfileEnabled,
WorkspaceId: pointer.To(profiles[0].WorkspaceId),
}
return &result
}

func expandNetworkProfile(profiles []NetworkProfile) *hdinsights.ClusterPoolNetworkProfile {
if len(profiles) == 0 {
return nil
}

result := hdinsights.ClusterPoolNetworkProfile{
SubnetId: profiles[0].SubnetId,
}

if profiles[0].PrivateApiServerEnabled {
result.EnablePrivateApiServer = pointer.To(true)
}

if profiles[0].OutboundType != "" {
result.OutboundType = pointer.To(hdinsights.OutboundType(profiles[0].OutboundType))
}
return &result
}

func flattenClusterPoolProfile(input *hdinsights.ClusterPoolProfile) []ClusterPoolProfile {
result := make([]ClusterPoolProfile, 0)
if input == nil {
return result
}

profile := ClusterPoolProfile{
ClusterPoolVersion: input.ClusterPoolVersion,
}
result = append(result, profile)

return result
}

func flattenComputeProfile(input hdinsights.ClusterPoolComputeProfile) []ComputeProfile {
result := make([]ComputeProfile, 0)
profile := ComputeProfile{
VmSize: input.VMSize,
}
result = append(result, profile)

return result
}

func flattenLogAnalyticsProfile(input *hdinsights.ClusterPoolLogAnalyticsProfile) []LogAnalyticsProfile {
result := make([]LogAnalyticsProfile, 0)
if input == nil {
return result
}

profile := LogAnalyticsProfile{
LogAnalyticsProfileEnabled: input.Enabled,
WorkspaceId: pointer.From(input.WorkspaceId),
}
result = append(result, profile)

return result
}

func flattenNetworkProfile(input *hdinsights.ClusterPoolNetworkProfile) []NetworkProfile {
result := make([]NetworkProfile, 0)
if input == nil {
return result
}

profile := NetworkProfile{
SubnetId: input.SubnetId,
}

if input.EnablePrivateApiServer != nil {
profile.PrivateApiServerEnabled = *input.EnablePrivateApiServer
}

if input.OutboundType != nil {
profile.OutboundType = string(*input.OutboundType)
}
result = append(result, profile)

return result
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am confused, why are all of these fields lists when all of the expand and flatten functions are not looping over multiple values, they are only looking at the 0 index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because only one set of profile is allowed for them.

Comment on lines +115 to +117
"cluster_pool_profile": {
Type: pluginsdk.TypeList,
Required: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this have a MaxItems property defined for the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Comment on lines +130 to +132
"log_analytics_profile": {
Type: pluginsdk.TypeList,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, Shouldn't this have a MaxItems property defined for the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Comment on lines +148 to +150
"network_profile": {
Type: pluginsdk.TypeList,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here as well, shouldn't this have a MaxItems property defined for the list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants