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

HCS-1805: Add consul cluster vm size #77

Merged
merged 11 commits into from
Apr 6, 2021
Merged

HCS-1805: Add consul cluster vm size #77

merged 11 commits into from
Apr 6, 2021

Conversation

riddhi89
Copy link
Contributor

@riddhi89 riddhi89 commented Mar 18, 2021

  • Adds a size attribute to the consul cluster properties. This can be provided during creation to specify t-shirt size of each server.
  • Updates the hcp-go-sdk version.
  • Cleans up some tier related validation in favor of leveraging sdk provided validation.

Copy link
Contributor

@bcmdarroch bcmdarroch left a comment

Choose a reason for hiding this comment

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

Everything looks good to me from the overall provider perspective! Thanks for looking into the enum validation pattern. I like that your approach keeps the API (by extension of the generated SDK) as the source of truth - definitely an improvement I'd like to add that to our style guide.

I'll leave it to another consul team member to verify the business logic is all good.

sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
)

// GetConsulClusterByID gets an Consul cluster by its ID
func GetConsulClusterByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826Cluster, error) {
consulClusterID string) (*consulmodels.HashicorpCloudConsul20210204Cluster, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

oh gosh this is annoying to have to change everywhere. 😅 just wrote up an SDK ticket for seeing if we can strip out that version number, so these don't have to be updated every time the service version bumps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! That would be great.

@@ -37,20 +33,6 @@ var consulCusterResourceCloudProviders = []string{
"aws",
}

// consulClusterResourceTiers is the list of tiers
Copy link
Contributor

Choose a reason for hiding this comment

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

😎

err := consulmodels.HashicorpCloudConsul20210204ClusterConfigTier(strings.ToUpper(v.(string))).Validate(strfmt.Default)
if err != nil {
expectedEnumList := regexp.MustCompile(`\[.*\]`).FindStringSubmatch(err.Error())
msg := fmt.Sprintf("expected %v to be one of %v", v, expectedEnumList[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

A little confusing that expectedEnumList seems to be a list of lists 🤔 Any way to flatten?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Changed the regexp helper to extract the list directly.

@bcmdarroch bcmdarroch requested a review from a team March 18, 2021 19:32
@@ -117,6 +117,11 @@ func dataSourceConsulCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"size": {
Description: "The t-shirt size representation of each server VM that this Consul cluster\nis provisioned with. Valid options - x_small, small, medium, large.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Was there a reason you needed the \n in the description here and in the resource? If it is being done to control where the line wraps, I think we would generally prefer to have the docs renderer handle this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This was just a copy pasta of the desc from elsewhere. Removed.

}
break
}
if err := d.Set("tier", strings.ToLower(string(cluster.Config.Tier))); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Since you're already using DiffSuppressFunc, I don't think you need to normalize this with ToLower (same with size)

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!

@@ -106,3 +108,39 @@ func validateDatacenter(v interface{}, path cty.Path) diag.Diagnostics {

return diagnostics
}

func validateConsulClusterTier(v interface{}, path cty.Path) diag.Diagnostics {
Copy link
Contributor

Choose a reason for hiding this comment

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

Very cool pattern for these validate* functions, thanks for adding them (and tests)!

@@ -135,6 +117,16 @@ func resourceConsulCluster() *schema.Resource {
Optional: true,
ForceNew: true,
},
"size": {
Description: "The t-shirt size representation of each server VM that this Consul cluster\nis provisioned with. Valid options - x_small, small, medium, large.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to think of how we could ensure this description stays up-to-date with the enum values, but it looks like the SDK doesn't provide them in a list, just constants. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea this was the other place I did not like the hard-coding :'( The compromise was at least the sdk validation will be our gate check. But, open to suggestions if any.

@riddhi89 riddhi89 requested a review from a team March 18, 2021 20:59
Copy link

@kedevlin kedevlin left a comment

Choose a reason for hiding this comment

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

Looking good! A few mostly minor comments

docs/data-sources/consul_cluster.md Outdated Show resolved Hide resolved
internal/provider/validators.go Outdated Show resolved Hide resolved
internal/provider/validators.go Outdated Show resolved Hide resolved
internal/provider/validators_test.go Outdated Show resolved Hide resolved
Copy link

@kedevlin kedevlin left a comment

Choose a reason for hiding this comment

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

Looks great! Just one nit comment

docs/data-sources/consul_cluster.md Outdated Show resolved Hide resolved
riddhi89 and others added 11 commits March 31, 2021 14:34
- Adds a size attribute to the consul cluster properties. This can be provided
 during creation to specify t-shirt size of the server.
- Updates the hcp-go-sdk version.
- Cleans up some tier related validation in favor of leveraging sdk
  provided validation.
Fix grammar

Co-authored-by: Kelly Devlin <[email protected]>
Fix grammar

Co-authored-by: Kelly Devlin <[email protected]>
@riddhi89 riddhi89 merged commit 8322167 into main Apr 6, 2021
@riddhi89 riddhi89 deleted the hcs-1805 branch April 6, 2021 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants