Skip to content

Commit

Permalink
HCS-1805: Add consul cluster vm size (#77)
Browse files Browse the repository at this point in the history
* HCS-1805: Add consul cluster vm size

- 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.
  • Loading branch information
riddhi89 authored Apr 6, 2021
1 parent 30806e4 commit 8322167
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 93 deletions.
3 changes: 2 additions & 1 deletion docs/data-sources/consul_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ data "hcp_consul_cluster" "example" {
- **region** (String) The region where the HCP Consul cluster is located.
- **scale** (Number) The the number of Consul server nodes in the cluster.
- **self_link** (String) A unique URL identifying the HCP Consul cluster.
- **tier** (String) The tier that the HCP Consul cluster will be provisioned as. Only 'development' and 'standard' are available at this time.
- **size** (String) The t-shirt size representation of each server VM that this Consul cluster is provisioned with. Valid option for development tier - `x_small`. Valid options for other tiers - `small`, `medium`, `large`.
- **tier** (String) The tier that the HCP Consul cluster will be provisioned as. Only `development` and `standard` are available at this time.

<a id="nestedblock--timeouts"></a>
### Nested Schema for `timeouts`
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/consul_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "hcp_consul_cluster" "example" {

- **cluster_id** (String) The ID of the HCP Consul cluster.
- **hvn_id** (String) The ID of the HVN this HCP Consul cluster is associated to.
- **tier** (String) The tier that the HCP Consul cluster will be provisioned as. Only 'development' and 'standard' are available at this time.
- **tier** (String) The tier that the HCP Consul cluster will be provisioned as. Only `development` and `standard` are available at this time.

### Optional

Expand All @@ -42,6 +42,7 @@ resource "hcp_consul_cluster" "example" {
- **min_consul_version** (String) The minimum Consul version of the cluster. If not specified, it is defaulted to the version that is currently recommended by HCP.
- **primary_link** (String) The `self_link` of the HCP Consul cluster which is the primary in the federation setup with this HCP Consul cluster. If not specified, it is a standalone cluster.
- **public_endpoint** (Boolean) Denotes that the cluster has a public endpoint for the Consul UI. Defaults to false.
- **size** (String) The t-shirt size representation of each server VM that this Consul cluster is provisioned with. Valid option for development tier - `x_small`. Valid options for other tiers - `small`, `medium`, `large`.
- **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-only
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/go-openapi/runtime v0.19.20
github.com/go-openapi/strfmt v0.19.5
github.com/google/uuid v1.2.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/hcp-sdk-go v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package clients

import (
cloud_consul "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/client"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/client/consul_service"
cloud_consul "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/client"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/client/consul_service"
cloud_network "github.com/hashicorp/hcp-sdk-go/clients/cloud-network/preview/2020-09-07/client"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-network/preview/2020-09-07/client/network_service"
cloud_operation "github.com/hashicorp/hcp-sdk-go/clients/cloud-operation/preview/2020-05-05/client"
Expand Down
28 changes: 14 additions & 14 deletions internal/clients/consul_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package clients
import (
"context"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/client/consul_service"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/models"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/client/consul_service"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/models"
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) {

getParams := consul_service.NewGetParams()
getParams.Context = ctx
Expand All @@ -31,7 +31,7 @@ func GetConsulClusterByID(ctx context.Context, client *Client, loc *sharedmodels
// The files will be returned in base64-encoded format and will get passed in
// that format.
func GetConsulClientConfigFiles(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826GetClientConfigResponse, error) {
consulClusterID string) (*consulmodels.HashicorpCloudConsul20210204GetClientConfigResponse, error) {

p := consul_service.NewGetClientConfigParams()
p.Context = ctx
Expand All @@ -52,12 +52,12 @@ func GetConsulClientConfigFiles(ctx context.Context, client *Client, loc *shared
// Example token: After cluster create, a customer would want a root token
// (or "bootstrap token") so they can continue to set-up their cluster.
func CreateCustomerRootACLToken(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826CreateCustomerMasterACLTokenResponse, error) {
consulClusterID string) (*consulmodels.HashicorpCloudConsul20210204CreateCustomerMasterACLTokenResponse, error) {

p := consul_service.NewCreateCustomerMasterACLTokenParams()
p.Context = ctx
p.ID = consulClusterID
p.Body = &consulmodels.HashicorpCloudConsul20200826CreateCustomerMasterACLTokenRequest{
p.Body = &consulmodels.HashicorpCloudConsul20210204CreateCustomerMasterACLTokenRequest{
ID: consulClusterID,
Location: loc,
}
Expand All @@ -75,11 +75,11 @@ func CreateCustomerRootACLToken(ctx context.Context, client *Client, loc *shared
// CreateConsulCluster will make a call to the Consul service to initiate the create Consul
// cluster workflow.
func CreateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
consulCluster *consulmodels.HashicorpCloudConsul20200826Cluster) (*consulmodels.HashicorpCloudConsul20200826CreateResponse, error) {
consulCluster *consulmodels.HashicorpCloudConsul20210204Cluster) (*consulmodels.HashicorpCloudConsul20210204CreateResponse, error) {

p := consul_service.NewCreateParams()
p.Context = ctx
p.Body = &consulmodels.HashicorpCloudConsul20200826CreateRequest{Cluster: consulCluster}
p.Body = &consulmodels.HashicorpCloudConsul20210204CreateRequest{Cluster: consulCluster}

p.ClusterLocationOrganizationID = loc.OrganizationID
p.ClusterLocationProjectID = loc.ProjectID
Expand All @@ -94,7 +94,7 @@ func CreateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.

// GetAvailableHCPConsulVersionsForLocation gets the list of available Consul versions that HCP supports for
// the provided location.
func GetAvailableHCPConsulVersionsForLocation(ctx context.Context, loc *sharedmodels.HashicorpCloudLocationLocation, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) {
func GetAvailableHCPConsulVersionsForLocation(ctx context.Context, loc *sharedmodels.HashicorpCloudLocationLocation, client *Client) ([]*consulmodels.HashicorpCloudConsul20210204Version, error) {
p := consul_service.NewListVersionsParams()
p.Context = ctx
p.LocationProjectID = loc.ProjectID
Expand All @@ -110,7 +110,7 @@ func GetAvailableHCPConsulVersionsForLocation(ctx context.Context, loc *sharedmo
}

// GetAvailableHCPConsulVersions gets the list of available Consul versions that HCP supports.
func GetAvailableHCPConsulVersions(ctx context.Context, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) {
func GetAvailableHCPConsulVersions(ctx context.Context, client *Client) ([]*consulmodels.HashicorpCloudConsul20210204Version, error) {
p := consul_service.NewListVersions2Params()
p.Context = ctx

Expand All @@ -126,7 +126,7 @@ func GetAvailableHCPConsulVersions(ctx context.Context, client *Client) ([]*cons
// DeleteConsulCluster will make a call to the Consul service to initiate the delete Consul
// cluster workflow.
func DeleteConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
clusterID string) (*consulmodels.HashicorpCloudConsul20200826DeleteResponse, error) {
clusterID string) (*consulmodels.HashicorpCloudConsul20210204DeleteResponse, error) {

p := consul_service.NewDeleteParams()
p.Context = ctx
Expand All @@ -145,7 +145,7 @@ func DeleteConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.
// ListConsulUpgradeVersions gets the list of available Consul versions that the supplied cluster
// can upgrade to.
func ListConsulUpgradeVersions(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
clusterID string) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) {
clusterID string) ([]*consulmodels.HashicorpCloudConsul20210204Version, error) {

p := consul_service.NewListUpgradeVersionsParams()
p.Context = ctx
Expand All @@ -165,9 +165,9 @@ func ListConsulUpgradeVersions(ctx context.Context, client *Client, loc *sharedm
// UpdateConsulCluster will make a call to the Consul service to initiate the update Consul
// cluster workflow.
func UpdateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
clusterID, newConsulVersion string) (*consulmodels.HashicorpCloudConsul20200826UpdateResponse, error) {
clusterID, newConsulVersion string) (*consulmodels.HashicorpCloudConsul20210204UpdateResponse, error) {

cluster := consulmodels.HashicorpCloudConsul20200826Cluster{
cluster := consulmodels.HashicorpCloudConsul20210204Cluster{
ConsulVersion: newConsulVersion,
ID: clusterID,
Location: &sharedmodels.HashicorpCloudLocationLocation{
Expand Down
16 changes: 8 additions & 8 deletions internal/clients/consul_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package clients
import (
"context"

"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/client/consul_service"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/models"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/client/consul_service"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/models"
sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
)

// CreateSnapshot will make a call to the Consul service to initiate the create Consul
// snapshot workflow.
func CreateSnapshot(ctx context.Context, client *Client, res *sharedmodels.HashicorpCloudLocationLink,
snapshotName string) (*consulmodels.HashicorpCloudConsul20200826CreateSnapshotResponse, error) {
snapshotName string) (*consulmodels.HashicorpCloudConsul20210204CreateSnapshotResponse, error) {

p := consul_service.NewCreateSnapshotParams()
p.Context = ctx
p.ResourceLocationOrganizationID = res.Location.OrganizationID
p.ResourceLocationProjectID = res.Location.ProjectID
p.Body = &consulmodels.HashicorpCloudConsul20200826CreateSnapshotRequest{
p.Body = &consulmodels.HashicorpCloudConsul20210204CreateSnapshotRequest{
Name: snapshotName,
Resource: res,
}
Expand All @@ -32,7 +32,7 @@ func CreateSnapshot(ctx context.Context, client *Client, res *sharedmodels.Hashi

// GetSnapshotByID gets a Consul snapshot by its ID
func GetSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
snapshotID string) (*consulmodels.HashicorpCloudConsul20200826GetSnapshotResponse, error) {
snapshotID string) (*consulmodels.HashicorpCloudConsul20210204GetSnapshotResponse, error) {

p := consul_service.NewGetSnapshotParams()
p.Context = ctx
Expand All @@ -50,7 +50,7 @@ func GetSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.Hash

// DeleteSnapshotByID deletes a Consul snapshot by its ID
func DeleteSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
snapshotID string) (*consulmodels.HashicorpCloudConsul20200826DeleteSnapshotResponse, error) {
snapshotID string) (*consulmodels.HashicorpCloudConsul20210204DeleteSnapshotResponse, error) {

p := consul_service.NewDeleteSnapshotParams()
p.Context = ctx
Expand All @@ -68,15 +68,15 @@ func DeleteSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.H

// RenameSnapshotByID renames a Consul snapshot by its ID
func RenameSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation,
snapshotID string, snapshotName string) (*consulmodels.HashicorpCloudConsul20200826UpdateSnapshotResponse, error) {
snapshotID string, snapshotName string) (*consulmodels.HashicorpCloudConsul20210204UpdateSnapshotResponse, error) {

p := consul_service.NewUpdateSnapshotParams()
p.Context = ctx
p.SnapshotLocationOrganizationID = loc.OrganizationID
p.SnapshotLocationProjectID = loc.ProjectID
p.SnapshotID = snapshotID

p.Body = &consulmodels.HashicorpCloudConsul20200826Snapshot{
p.Body = &consulmodels.HashicorpCloudConsul20210204Snapshot{
Name: snapshotName,
}

Expand Down
10 changes: 5 additions & 5 deletions internal/consul/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"strings"

consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/models"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/models"
)

// RecommendedVersion returns the recommended version of Consul
func RecommendedVersion(versions []*consulmodels.HashicorpCloudConsul20200826Version) string {
func RecommendedVersion(versions []*consulmodels.HashicorpCloudConsul20210204Version) string {
var defaultVersion string

for _, v := range versions {
Expand All @@ -24,7 +24,7 @@ func RecommendedVersion(versions []*consulmodels.HashicorpCloudConsul20200826Ver

// IsValidVersion determines that a given version string is contained within the slice of
// available Consul versions.
func IsValidVersion(version string, versions []*consulmodels.HashicorpCloudConsul20200826Version) bool {
func IsValidVersion(version string, versions []*consulmodels.HashicorpCloudConsul20210204Version) bool {
for _, v := range versions {
if version == v.Version {
return true
Expand All @@ -40,7 +40,7 @@ func NormalizeVersion(version string) string {
}

// VersionsToString converts a slice of version pointers to a string of their comma delimited values.
func VersionsToString(versions []*consulmodels.HashicorpCloudConsul20200826Version) string {
func VersionsToString(versions []*consulmodels.HashicorpCloudConsul20210204Version) string {
var recommendedVersion string
var otherVersions []string

Expand All @@ -49,7 +49,7 @@ func VersionsToString(versions []*consulmodels.HashicorpCloudConsul20200826Versi
continue
}

if v.Status == consulmodels.HashicorpCloudConsul20200826VersionStatusRECOMMENDED {
if v.Status == consulmodels.HashicorpCloudConsul20210204VersionStatusRECOMMENDED {
recommendedVersion = v.Version
} else {
otherVersions = append(otherVersions, v.Version)
Expand Down
24 changes: 12 additions & 12 deletions internal/consul/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package consul
import (
"testing"

consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2020-08-26/models"
consulmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-consul-service/preview/2021-02-04/models"
"github.com/stretchr/testify/require"
)

func Test_RecommendedVersion(t *testing.T) {
tcs := map[string]struct {
expected string
input []*consulmodels.HashicorpCloudConsul20200826Version
input []*consulmodels.HashicorpCloudConsul20210204Version
}{
"with a recommended version": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Expand All @@ -30,7 +30,7 @@ func Test_RecommendedVersion(t *testing.T) {
expected: "v1.9.0",
},
"without a recommended version": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "AVAILABLE",
Expand Down Expand Up @@ -62,11 +62,11 @@ func Test_IsValidVersion(t *testing.T) {
tcs := map[string]struct {
expected bool
version string
validVersions []*consulmodels.HashicorpCloudConsul20200826Version
validVersions []*consulmodels.HashicorpCloudConsul20210204Version
}{
"with a valid version": {
version: "v1.9.0",
validVersions: []*consulmodels.HashicorpCloudConsul20200826Version{
validVersions: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Expand All @@ -84,7 +84,7 @@ func Test_IsValidVersion(t *testing.T) {
},
"with an invalid version": {
version: "v1.8.0",
validVersions: []*consulmodels.HashicorpCloudConsul20200826Version{
validVersions: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Expand Down Expand Up @@ -145,10 +145,10 @@ func Test_NormalizeVersion(t *testing.T) {
func Test_VersionsToString(t *testing.T) {
tcs := map[string]struct {
expected string
input []*consulmodels.HashicorpCloudConsul20200826Version
input []*consulmodels.HashicorpCloudConsul20210204Version
}{
"with a recommended version": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Expand All @@ -165,7 +165,7 @@ func Test_VersionsToString(t *testing.T) {
expected: "v1.9.0 (recommended), v1.8.6, v1.8.4",
},
"without a recommended version": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.8.6",
Status: "AVAILABLE",
Expand All @@ -178,7 +178,7 @@ func Test_VersionsToString(t *testing.T) {
expected: "v1.8.6, v1.8.4",
},
"no other versions but recommended": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
{
Version: "v1.9.0",
Status: "RECOMMENDED",
Expand All @@ -191,7 +191,7 @@ func Test_VersionsToString(t *testing.T) {
expected: "",
},
"nil values": {
input: []*consulmodels.HashicorpCloudConsul20200826Version{
input: []*consulmodels.HashicorpCloudConsul20210204Version{
nil,
{
Version: "v1.9.0",
Expand Down
7 changes: 6 additions & 1 deletion internal/provider/data_source_consul_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ func dataSourceConsulCluster() *schema.Resource {
Computed: true,
},
"tier": {
Description: "The tier that the HCP Consul cluster will be provisioned as. Only 'development' and 'standard' are available at this time.",
Description: "The tier that the HCP Consul cluster will be provisioned as. Only `development` and `standard` are available at this time.",
Type: schema.TypeString,
Computed: true,
},
"size": {
Description: "The t-shirt size representation of each server VM that this Consul cluster is provisioned with. Valid option for development tier - `x_small`. Valid options for other tiers - `small`, `medium`, `large`.",
Type: schema.TypeString,
Computed: true,
},
Expand Down
Loading

0 comments on commit 8322167

Please sign in to comment.