From 1f583eef5378a7640cae47106160cda9dc62c311 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Tue, 16 Feb 2021 09:30:11 -0800 Subject: [PATCH 01/13] HCS-1716: Add HCP Consul federation support Adds federation support for HCP Consul. --- docs/data-sources/consul_cluster.md | 2 + docs/resources/consul_cluster.md | 2 + .../hcp_consul_cluster/federation.tf | 15 ++++++ go.mod | 2 +- go.sum | 4 +- internal/clients/consul_cluster.go | 37 ++++++------- internal/clients/consul_snapshot.go | 16 +++--- internal/clients/response.go | 8 ++- .../provider/data_source_consul_cluster.go | 10 ++++ internal/provider/resource_consul_cluster.go | 52 ++++++++++++++++++- 10 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 examples/resources/hcp_consul_cluster/federation.tf diff --git a/docs/data-sources/consul_cluster.md b/docs/data-sources/consul_cluster.md index 8c6d50cef..cb8371f3b 100644 --- a/docs/data-sources/consul_cluster.md +++ b/docs/data-sources/consul_cluster.md @@ -43,10 +43,12 @@ data "hcp_consul_cluster" "example" { - **datacenter** (String) The Consul data center name of the cluster. If not specified, it is defaulted to the value of `cluster_id`. - **hvn_id** (String) The ID of the HVN this HCP Consul cluster is associated to. - **organization_id** (String) The ID of the organization the project for this HCP Consul cluster is located. +- **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. - **project_id** (String) The ID of the project this HCP Consul cluster is located. - **public_endpoint** (Boolean) Denotes that the cluster has a public endpoint for the Consul UI. Defaults to false. - **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. diff --git a/docs/resources/consul_cluster.md b/docs/resources/consul_cluster.md index 220994763..8c7befc62 100644 --- a/docs/resources/consul_cluster.md +++ b/docs/resources/consul_cluster.md @@ -40,6 +40,7 @@ resource "hcp_consul_cluster" "example" { - **datacenter** (String) The Consul data center name of the cluster. If not specified, it is defaulted to the value of `cluster_id`. - **id** (String) The ID of this resource. - **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. - **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) @@ -60,6 +61,7 @@ resource "hcp_consul_cluster" "example" { - **project_id** (String) The ID of the project this HCP Consul cluster is located in. - **region** (String) The region where the HCP Consul cluster is located. - **scale** (Number) The number of Consul server nodes in the cluster. +- **self_link** (String) A unique URL identifying the HCP Consul Cluster. ### Nested Schema for `timeouts` diff --git a/examples/resources/hcp_consul_cluster/federation.tf b/examples/resources/hcp_consul_cluster/federation.tf new file mode 100644 index 000000000..cc6bf5aa3 --- /dev/null +++ b/examples/resources/hcp_consul_cluster/federation.tf @@ -0,0 +1,15 @@ +data "hcp_hvn" "example" { + hvn_id = "hvn" +} + +data "hcp_consul_cluster" "primary" { + cluster_id = "consul-cluster-primary" +} + +resource "hcp_consul_cluster" "secondary" { + hvn_id = data.hcp_hvn.example.hvn_id + cluster_id = "consul-cluster-secondary" + tier = "development" + primary_link = data.hcp_consul_cluster.primary.self_link +} + diff --git a/go.mod b/go.mod index 3ad93edaa..112177f96 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/go-openapi/runtime v0.19.20 github.com/google/uuid v1.1.1 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 - github.com/hashicorp/hcp-sdk-go v0.1.0 + github.com/hashicorp/hcp-sdk-go v0.2.0 github.com/hashicorp/terraform-plugin-docs v0.3.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0 github.com/stretchr/testify v1.6.1 diff --git a/go.sum b/go.sum index bea37cc36..626cf5a20 100644 --- a/go.sum +++ b/go.sum @@ -296,8 +296,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE= github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8= -github.com/hashicorp/hcp-sdk-go v0.1.0 h1:3UQRLDsgXHnK6++hQ9uFKwLbsQ8lLXm+nGO/ZbUtlg0= -github.com/hashicorp/hcp-sdk-go v0.1.0/go.mod h1:vpV5eSGZVmfCFcksi4AH8d/QSybuyLSH5UQcwmnRUQk= +github.com/hashicorp/hcp-sdk-go v0.2.0 h1:kY+1WSAE1NiWz+DwqzzgJDz6AUETVOhex6itGlJ4Rpw= +github.com/hashicorp/hcp-sdk-go v0.2.0/go.mod h1:vpV5eSGZVmfCFcksi4AH8d/QSybuyLSH5UQcwmnRUQk= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.9.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= diff --git a/internal/clients/consul_cluster.go b/internal/clients/consul_cluster.go index 0e1ef9026..5c8eedbbc 100644 --- a/internal/clients/consul_cluster.go +++ b/internal/clients/consul_cluster.go @@ -12,13 +12,13 @@ import ( func GetConsulClusterByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826Cluster, error) { - getParams := consul_service.NewGetParams() + getParams := consul_service.NewConsulServiceGetParams() getParams.Context = ctx getParams.ID = consulClusterID getParams.LocationOrganizationID = loc.OrganizationID getParams.LocationProjectID = loc.ProjectID - getResp, err := client.Consul.Get(getParams, nil) + getResp, err := client.Consul.ConsulServiceGet(getParams, nil) if err != nil { return nil, err } @@ -33,13 +33,13 @@ func GetConsulClusterByID(ctx context.Context, client *Client, loc *sharedmodels func GetConsulClientConfigFiles(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826GetClientConfigResponse, error) { - p := consul_service.NewGetClientConfigParams() + p := consul_service.NewConsulServiceGetClientConfigParams() p.Context = ctx p.ID = consulClusterID p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID - resp, err := client.Consul.GetClientConfig(p, nil) + resp, err := client.Consul.ConsulServiceGetClientConfig(p, nil) if err != nil { return nil, err } @@ -54,7 +54,7 @@ func GetConsulClientConfigFiles(ctx context.Context, client *Client, loc *shared func CreateCustomerRootACLToken(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, consulClusterID string) (*consulmodels.HashicorpCloudConsul20200826CreateCustomerMasterACLTokenResponse, error) { - p := consul_service.NewCreateCustomerMasterACLTokenParams() + p := consul_service.NewConsulServiceCreateCustomerMasterACLTokenParams() p.Context = ctx p.ID = consulClusterID p.Body = &consulmodels.HashicorpCloudConsul20200826CreateCustomerMasterACLTokenRequest{ @@ -64,7 +64,7 @@ func CreateCustomerRootACLToken(ctx context.Context, client *Client, loc *shared p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID - resp, err := client.Consul.CreateCustomerMasterACLToken(p, nil) + resp, err := client.Consul.ConsulServiceCreateCustomerMasterACLToken(p, nil) if err != nil { return nil, err } @@ -75,9 +75,9 @@ 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, - clusterID, datacenter, consulVersion string, numServers int32, private, connectEnabled bool, network *sharedmodels.HashicorpCloudLocationLink) (*consulmodels.HashicorpCloudConsul20200826CreateResponse, error) { + clusterID, datacenter, consulVersion string, numServers int32, private, connectEnabled bool, network *sharedmodels.HashicorpCloudLocationLink, primary *sharedmodels.HashicorpCloudLocationLink) (*consulmodels.HashicorpCloudConsul20200826CreateResponse, error) { - p := consul_service.NewCreateParams() + p := consul_service.NewConsulServiceCreateParams() p.Context = ctx p.Body = &consulmodels.HashicorpCloudConsul20200826CreateRequest{ Cluster: &consulmodels.HashicorpCloudConsul20200826Cluster{ @@ -88,6 +88,7 @@ func CreateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels. ConsulConfig: &consulmodels.HashicorpCloudConsul20200826ConsulConfig{ ConnectEnabled: connectEnabled, Datacenter: datacenter, + Primary: primary, }, MaintenanceConfig: nil, NetworkConfig: &consulmodels.HashicorpCloudConsul20200826NetworkConfig{ @@ -104,7 +105,7 @@ func CreateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels. p.ClusterLocationOrganizationID = loc.OrganizationID p.ClusterLocationProjectID = loc.ProjectID - resp, err := client.Consul.Create(p, nil) + resp, err := client.Consul.ConsulServiceCreate(p, nil) if err != nil { return nil, err } @@ -114,13 +115,13 @@ 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) { - p := consul_service.NewListVersionsParams() +func GetAvailableHCPConsulVersions(ctx context.Context, loc *sharedmodels.HashicorpCloudLocationLocation, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) { + p := consul_service.NewConsulServiceListVersionsParams() p.Context = ctx p.LocationProjectID = loc.ProjectID p.LocationOrganizationID = loc.OrganizationID - resp, err := client.Consul.ListVersions(p, nil) + resp, err := client.Consul.ConsulServiceListVersions(p, nil) if err != nil { return nil, err @@ -148,13 +149,13 @@ func GetAvailableHCPConsulVersions(ctx context.Context, client *Client) ([]*cons func DeleteConsulCluster(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, clusterID string) (*consulmodels.HashicorpCloudConsul20200826DeleteResponse, error) { - p := consul_service.NewDeleteParams() + p := consul_service.NewConsulServiceDeleteParams() p.Context = ctx p.ID = clusterID p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID - deleteResp, err := client.Consul.Delete(p, nil) + deleteResp, err := client.Consul.ConsulServiceDelete(p, nil) if err != nil { return nil, err } @@ -167,13 +168,13 @@ func DeleteConsulCluster(ctx context.Context, client *Client, loc *sharedmodels. func ListConsulUpgradeVersions(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, clusterID string) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) { - p := consul_service.NewListUpgradeVersionsParams() + p := consul_service.NewConsulServiceListUpgradeVersionsParams() p.Context = ctx p.ID = clusterID p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID - resp, err := client.Consul.ListUpgradeVersions(p, nil) + resp, err := client.Consul.ConsulServiceListUpgradeVersions(p, nil) if err != nil { return nil, err @@ -200,7 +201,7 @@ func UpdateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels. }, } - updateParams := consul_service.NewUpdateParams() + updateParams := consul_service.NewConsulServiceUpdateParams() updateParams.Context = ctx updateParams.ClusterID = cluster.ID updateParams.ClusterLocationProjectID = loc.ProjectID @@ -208,7 +209,7 @@ func UpdateConsulCluster(ctx context.Context, client *Client, loc *sharedmodels. updateParams.Body = &cluster // Invoke update cluster endpoint - updateResp, err := client.Consul.Update(updateParams, nil) + updateResp, err := client.Consul.ConsulServiceUpdate(updateParams, nil) if err != nil { return nil, err } diff --git a/internal/clients/consul_snapshot.go b/internal/clients/consul_snapshot.go index ef2713ebe..49fd8aa35 100644 --- a/internal/clients/consul_snapshot.go +++ b/internal/clients/consul_snapshot.go @@ -13,7 +13,7 @@ import ( func CreateSnapshot(ctx context.Context, client *Client, res *sharedmodels.HashicorpCloudLocationLink, snapshotName string) (*consulmodels.HashicorpCloudConsul20200826CreateSnapshotResponse, error) { - p := consul_service.NewCreateSnapshotParams() + p := consul_service.NewConsulServiceCreateSnapshotParams() p.Context = ctx p.ResourceLocationOrganizationID = res.Location.OrganizationID p.ResourceLocationProjectID = res.Location.ProjectID @@ -22,7 +22,7 @@ func CreateSnapshot(ctx context.Context, client *Client, res *sharedmodels.Hashi Resource: res, } - resp, err := client.Consul.CreateSnapshot(p, nil) + resp, err := client.Consul.ConsulServiceCreateSnapshot(p, nil) if err != nil { return nil, err } @@ -34,13 +34,13 @@ func CreateSnapshot(ctx context.Context, client *Client, res *sharedmodels.Hashi func GetSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, snapshotID string) (*consulmodels.HashicorpCloudConsul20200826GetSnapshotResponse, error) { - p := consul_service.NewGetSnapshotParams() + p := consul_service.NewConsulServiceGetSnapshotParams() p.Context = ctx p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID p.SnapshotID = snapshotID - resp, err := client.Consul.GetSnapshot(p, nil) + resp, err := client.Consul.ConsulServiceGetSnapshot(p, nil) if err != nil { return nil, err } @@ -52,13 +52,13 @@ func GetSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.Hash func DeleteSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, snapshotID string) (*consulmodels.HashicorpCloudConsul20200826DeleteSnapshotResponse, error) { - p := consul_service.NewDeleteSnapshotParams() + p := consul_service.NewConsulServiceDeleteSnapshotParams() p.Context = ctx p.LocationOrganizationID = loc.OrganizationID p.LocationProjectID = loc.ProjectID p.SnapshotID = snapshotID - resp, err := client.Consul.DeleteSnapshot(p, nil) + resp, err := client.Consul.ConsulServiceDeleteSnapshot(p, nil) if err != nil { return nil, err } @@ -70,7 +70,7 @@ func DeleteSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.H func RenameSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, snapshotID string, snapshotName string) (*consulmodels.HashicorpCloudConsul20200826UpdateSnapshotResponse, error) { - p := consul_service.NewUpdateSnapshotParams() + p := consul_service.NewConsulServiceUpdateSnapshotParams() p.Context = ctx p.SnapshotLocationOrganizationID = loc.OrganizationID p.SnapshotLocationProjectID = loc.ProjectID @@ -80,7 +80,7 @@ func RenameSnapshotByID(ctx context.Context, client *Client, loc *sharedmodels.H Name: snapshotName, } - resp, err := client.Consul.UpdateSnapshot(p, nil) + resp, err := client.Consul.ConsulServiceUpdateSnapshot(p, nil) if err != nil { return nil, err } diff --git a/internal/clients/response.go b/internal/clients/response.go index 8f423fc25..ebaffb2c0 100644 --- a/internal/clients/response.go +++ b/internal/clients/response.go @@ -2,7 +2,9 @@ package clients import ( "errors" + "fmt" "net/http" + "strings" "github.com/go-openapi/runtime" ) @@ -11,5 +13,9 @@ import ( // request, and returns true if the response code was 404 not found func IsResponseCodeNotFound(err error) bool { var apiErr *runtime.APIError - return errors.As(err, &apiErr) && apiErr.Code == http.StatusNotFound + if errors.As(err, &apiErr) { + return apiErr.Code == http.StatusNotFound + } else { + return strings.Contains(err.Error(), fmt.Sprintf("[%d]", http.StatusNotFound)) + } } diff --git a/internal/provider/data_source_consul_cluster.go b/internal/provider/data_source_consul_cluster.go index 164378a30..8cae4d64c 100644 --- a/internal/provider/data_source_consul_cluster.go +++ b/internal/provider/data_source_consul_cluster.go @@ -117,6 +117,16 @@ func dataSourceConsulCluster() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "self_link": { + Description: "A unique URL identifying the HCP Consul Cluster.", + Type: schema.TypeString, + Computed: true, + }, + "primary_link": { + Description: "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.", + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index 7f9f65def..a39ac6946 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -129,6 +129,12 @@ func resourceConsulCluster() *schema.Resource { Optional: true, ForceNew: true, }, + "primary_link": { + Description: "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.", + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, // computed outputs "organization_id": { Description: "The ID of the organization this HCP Consul cluster is located in.", @@ -206,6 +212,11 @@ func resourceConsulCluster() *schema.Resource { Type: schema.TypeInt, Computed: true, }, + "self_link": { + Description: "A unique URL identifying the HCP Consul Cluster.", + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -261,6 +272,29 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me return diag.Errorf("specified Consul version (%s) is unavailable; must be one of: [%s]", consulVersion, consul.VersionsToString(availableConsulVersions)) } + // If specified, validate and parse the primary link provided for federation. + primary_link, ok := d.GetOk("primary_link") + var primary *sharedmodels.HashicorpCloudLocationLink + if ok { + primary, err = parseLinkURL(primary_link.(string), ConsulClusterResourceType) + if err != nil { + return diag.Errorf(err.Error()) + } + if primary.Location.OrganizationID == "" { + primaryOrgID, err := clients.GetParentOrganizationIDByProjectID(ctx, client, primary.Location.ProjectID) + if err != nil { + return diag.Errorf("Error determining organization of primary cluster. %v", err) + } + primary.Location.OrganizationID = primaryOrgID + } + // fetch the primary cluster + primaryConsulCluster, err := clients.GetConsulClusterByID(ctx, client, primary.Location, primary.ID) + if err != nil { + return diag.Errorf("unable to check for presence of an existing primary Consul cluster (%s): %v", primary.ID, err) + } + primary.Location.Region = primaryConsulCluster.Location.Region + } + datacenter := strings.ToLower(clusterID) v, ok = d.GetOk("datacenter") if ok { @@ -276,7 +310,7 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me log.Printf("[INFO] Creating Consul cluster (%s)", clusterID) payload, err := clients.CreateConsulCluster(ctx, client, loc, clusterID, datacenter, consulVersion, - numServers, !publicEndpoint, connectEnabled, newLink(loc, "hvn", hvnID)) + numServers, !publicEndpoint, connectEnabled, newLink(loc, "hvn", hvnID), primary) if err != nil { return diag.Errorf("unable to create Consul cluster (%s): %v", clusterID, err) } @@ -417,6 +451,22 @@ func setConsulClusterResourceData(d *schema.ResourceData, cluster *consulmodels. return err } + // self_link is equal to the terraform ID of the resource + if err := d.Set("self_link", d.Id()); err != nil { + return err + } + + if cluster.Config.ConsulConfig.Primary != nil { + link := newLink(cluster.Config.ConsulConfig.Primary.Location, ConsulClusterResourceType, cluster.Config.ConsulConfig.Primary.ID) + primary_link, err := linkURL(link) + if err != nil { + return err + } + if err := d.Set("primary_link", primary_link); err != nil { + return err + } + } + return nil } From 0d72276563319d910b496096a532ae35c9df129b Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 14:36:39 -0800 Subject: [PATCH 02/13] Fix case Co-authored-by: Brenna Hewer-Darroch --- internal/provider/data_source_consul_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/data_source_consul_cluster.go b/internal/provider/data_source_consul_cluster.go index 8cae4d64c..b4f66c31b 100644 --- a/internal/provider/data_source_consul_cluster.go +++ b/internal/provider/data_source_consul_cluster.go @@ -118,7 +118,7 @@ func dataSourceConsulCluster() *schema.Resource { Computed: true, }, "self_link": { - Description: "A unique URL identifying the HCP Consul Cluster.", + Description: "A unique URL identifying the HCP Consul cluster.", Type: schema.TypeString, Computed: true, }, From c3c0fa914aeb11f9c1430cbbb11805aa026f48ba Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 14:37:00 -0800 Subject: [PATCH 03/13] Fix case 2 Co-authored-by: Brenna Hewer-Darroch --- internal/provider/data_source_consul_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/data_source_consul_cluster.go b/internal/provider/data_source_consul_cluster.go index b4f66c31b..c74ad6e40 100644 --- a/internal/provider/data_source_consul_cluster.go +++ b/internal/provider/data_source_consul_cluster.go @@ -123,7 +123,7 @@ func dataSourceConsulCluster() *schema.Resource { Computed: true, }, "primary_link": { - Description: "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.", + Description: "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.", Type: schema.TypeString, Computed: true, }, From 9e2d43ce9b78280d8b386a9474a7783f5ee42069 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 14:38:48 -0800 Subject: [PATCH 04/13] Fix case 3 Co-authored-by: Brenna Hewer-Darroch --- internal/provider/resource_consul_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index a39ac6946..9de7b8320 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -130,7 +130,7 @@ func resourceConsulCluster() *schema.Resource { ForceNew: true, }, "primary_link": { - Description: "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.", + Description: "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.", Type: schema.TypeString, Optional: true, ForceNew: true, From 4a99ab2662743f34ba4e75f3a9ff6b2eb378fb86 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 14:39:12 -0800 Subject: [PATCH 05/13] Fix case 4 Co-authored-by: Brenna Hewer-Darroch --- internal/provider/resource_consul_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index 9de7b8320..e4eb53824 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -213,7 +213,7 @@ func resourceConsulCluster() *schema.Resource { Computed: true, }, "self_link": { - Description: "A unique URL identifying the HCP Consul Cluster.", + Description: "A unique URL identifying the HCP Consul cluster.", Type: schema.TypeString, Computed: true, }, From a1f652274d68971a3efb3c4bb1e92406a8f87aba Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 15:50:34 -0800 Subject: [PATCH 06/13] Update docs --- docs/guides/consul-federation.md | 31 +++++++++++++++++++ .../consul_cluster_federation/_config.tf | 1 + .../guides/consul_cluster_federation/main.tf | 18 +++++++++++ .../consul_cluster_federation/variables.tf | 24 ++++++++++++++ .../hcp_consul_cluster/federation.tf | 18 ++++++----- templates/guides/consul-federation.md.tmpl | 12 +++++++ 6 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 docs/guides/consul-federation.md create mode 100644 examples/guides/consul_cluster_federation/_config.tf create mode 100644 examples/guides/consul_cluster_federation/main.tf create mode 100644 examples/guides/consul_cluster_federation/variables.tf create mode 100644 templates/guides/consul-federation.md.tmpl diff --git a/docs/guides/consul-federation.md b/docs/guides/consul-federation.md new file mode 100644 index 000000000..a1ac423db --- /dev/null +++ b/docs/guides/consul-federation.md @@ -0,0 +1,31 @@ +--- +subcategory: "" +page_title: "Federate HCP Consul clusters - HCP Provider" +description: |- + An example of federating a new HCP Consul cluster with an existing one. +--- + +# Federate a new HCP Consul cluster with an existing one + +Once you have a HCP Consul cluster, you can create new Consul cluster to federate with the existing one. + +```terraform +resource "hcp_hvn" "example" { + hvn_id = var.hvn_id + cloud_provider = var.cloud_provider + region = var.region +} + +resource "hcp_consul_cluster" "primary" { + hvn_id = hcp_hvn.example.hvn_id + cluster_id = var.primary_cluster_id + tier = "development" +} + +resource "hcp_consul_cluster" "secondary" { + hvn_id = hcp_hvn.example.hvn_id + cluster_id = var.secondary_cluster_id + tier = "development" + primary_link = hcp_consul_cluster.primary.self_link +} +``` \ No newline at end of file diff --git a/examples/guides/consul_cluster_federation/_config.tf b/examples/guides/consul_cluster_federation/_config.tf new file mode 100644 index 000000000..041a8b52b --- /dev/null +++ b/examples/guides/consul_cluster_federation/_config.tf @@ -0,0 +1 @@ +provider "hcp" {} \ No newline at end of file diff --git a/examples/guides/consul_cluster_federation/main.tf b/examples/guides/consul_cluster_federation/main.tf new file mode 100644 index 000000000..97b8aa2cf --- /dev/null +++ b/examples/guides/consul_cluster_federation/main.tf @@ -0,0 +1,18 @@ +resource "hcp_hvn" "example" { + hvn_id = var.hvn_id + cloud_provider = var.cloud_provider + region = var.region +} + +resource "hcp_consul_cluster" "primary" { + hvn_id = hcp_hvn.example.hvn_id + cluster_id = var.primary_cluster_id + tier = "development" +} + +resource "hcp_consul_cluster" "secondary" { + hvn_id = hcp_hvn.example.hvn_id + cluster_id = var.secondary_cluster_id + tier = "development" + primary_link = hcp_consul_cluster.primary.self_link +} \ No newline at end of file diff --git a/examples/guides/consul_cluster_federation/variables.tf b/examples/guides/consul_cluster_federation/variables.tf new file mode 100644 index 000000000..b38b11598 --- /dev/null +++ b/examples/guides/consul_cluster_federation/variables.tf @@ -0,0 +1,24 @@ +variable "hvn_id" { + description = "The ID of the HCP HVN." + type = string +} + +variable "cloud_provider" { + description = "The cloud provider of the HCP HVN and Consul cluster." + type = string +} + +variable "region" { + description = "The region of the HCP HVN and Consul cluster." + type = string +} + +variable "primary_cluster_id" { + description = "The ID of the HCP Consul cluster which is the primary in the federation." + type = string +} + +variable "secondary_cluster_id" { + description = "The ID of the HCP Consul cluster which is the secondary in the federation." + type = string +} \ No newline at end of file diff --git a/examples/resources/hcp_consul_cluster/federation.tf b/examples/resources/hcp_consul_cluster/federation.tf index cc6bf5aa3..abe8446b6 100644 --- a/examples/resources/hcp_consul_cluster/federation.tf +++ b/examples/resources/hcp_consul_cluster/federation.tf @@ -1,15 +1,19 @@ -data "hcp_hvn" "example" { - hvn_id = "hvn" +resource "hcp_hvn" "example" { + hvn_id = "hvn" + cloud_provider = "aws" + region = "us-west-2" + cidr_block = "172.25.16.0/20" } -data "hcp_consul_cluster" "primary" { +resource "hcp_consul_cluster" "primary" { + hvn_id = hcp_hvn.example.hvn_id cluster_id = "consul-cluster-primary" + tier = "development" } resource "hcp_consul_cluster" "secondary" { - hvn_id = data.hcp_hvn.example.hvn_id + hvn_id = hcp_hvn.example.hvn_id cluster_id = "consul-cluster-secondary" tier = "development" - primary_link = data.hcp_consul_cluster.primary.self_link -} - + primary_link = hcp_consul_cluster.primary.self_link +} \ No newline at end of file diff --git a/templates/guides/consul-federation.md.tmpl b/templates/guides/consul-federation.md.tmpl new file mode 100644 index 000000000..595b496c5 --- /dev/null +++ b/templates/guides/consul-federation.md.tmpl @@ -0,0 +1,12 @@ +--- +subcategory: "" +page_title: "Federate HCP Consul clusters - HCP Provider" +description: |- + An example of federating a new HCP Consul cluster with an existing one. +--- + +# Federate a new HCP Consul cluster with an existing one + +Once you have a HCP Consul cluster, you can create new Consul cluster to federate with the existing one. + +{{ tffile "examples/guides/consul_cluster_federation/main.tf" }} \ No newline at end of file From 8f81f8439110bf016acf712c04bce3e17bad6c79 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 15:59:44 -0800 Subject: [PATCH 07/13] Fix client call after rebase --- internal/clients/consul_cluster.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/clients/consul_cluster.go b/internal/clients/consul_cluster.go index 5c8eedbbc..b391e026b 100644 --- a/internal/clients/consul_cluster.go +++ b/internal/clients/consul_cluster.go @@ -132,10 +132,10 @@ func GetAvailableHCPConsulVersions(ctx context.Context, loc *sharedmodels.Hashic // GetAvailableHCPConsulVersions gets the list of available Consul versions that HCP supports. func GetAvailableHCPConsulVersions(ctx context.Context, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) { - p := consul_service.NewListVersions2Params() + p := consul_service.NewConsulServiceListVersions2Params() p.Context = ctx - resp, err := client.Consul.ListVersions2(p, nil) + resp, err := client.Consul.ConsulServiceListVersions2(p, nil) if err != nil { return nil, err From 6edd9a056429047cd3ad3156b5914e9366debd6a Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 16:08:46 -0800 Subject: [PATCH 08/13] Fix rebase bug --- internal/clients/consul_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/clients/consul_cluster.go b/internal/clients/consul_cluster.go index b391e026b..5fa9e79c2 100644 --- a/internal/clients/consul_cluster.go +++ b/internal/clients/consul_cluster.go @@ -115,7 +115,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 GetAvailableHCPConsulVersions(ctx context.Context, loc *sharedmodels.HashicorpCloudLocationLocation, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) { +func GetAvailableHCPConsulVersionsForLocation(ctx context.Context, loc *sharedmodels.HashicorpCloudLocationLocation, client *Client) ([]*consulmodels.HashicorpCloudConsul20200826Version, error) { p := consul_service.NewConsulServiceListVersionsParams() p.Context = ctx p.LocationProjectID = loc.ProjectID From 5ae8671fd5eedb344c960029e13f72ceeaf43e66 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 16:28:36 -0800 Subject: [PATCH 09/13] Reduce create cluster params --- internal/clients/consul_cluster.go | 25 ++------------------ internal/provider/resource_consul_cluster.go | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/internal/clients/consul_cluster.go b/internal/clients/consul_cluster.go index 5fa9e79c2..b27965113 100644 --- a/internal/clients/consul_cluster.go +++ b/internal/clients/consul_cluster.go @@ -75,32 +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, - clusterID, datacenter, consulVersion string, numServers int32, private, connectEnabled bool, network *sharedmodels.HashicorpCloudLocationLink, primary *sharedmodels.HashicorpCloudLocationLink) (*consulmodels.HashicorpCloudConsul20200826CreateResponse, error) { + consulCluster *consulmodels.HashicorpCloudConsul20200826Cluster) (*consulmodels.HashicorpCloudConsul20200826CreateResponse, error) { p := consul_service.NewConsulServiceCreateParams() p.Context = ctx - p.Body = &consulmodels.HashicorpCloudConsul20200826CreateRequest{ - Cluster: &consulmodels.HashicorpCloudConsul20200826Cluster{ - Config: &consulmodels.HashicorpCloudConsul20200826ClusterConfig{ - CapacityConfig: &consulmodels.HashicorpCloudConsul20200826CapacityConfig{ - NumServers: numServers, - }, - ConsulConfig: &consulmodels.HashicorpCloudConsul20200826ConsulConfig{ - ConnectEnabled: connectEnabled, - Datacenter: datacenter, - Primary: primary, - }, - MaintenanceConfig: nil, - NetworkConfig: &consulmodels.HashicorpCloudConsul20200826NetworkConfig{ - Network: network, - Private: private, - }, - }, - ConsulVersion: consulVersion, - ID: clusterID, - Location: loc, - }, - } + p.Body = &consulmodels.HashicorpCloudConsul20200826CreateRequest{Cluster: consulCluster} p.ClusterLocationOrganizationID = loc.OrganizationID p.ClusterLocationProjectID = loc.ProjectID diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index e4eb53824..fbe3ca9f5 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -309,8 +309,28 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me log.Printf("[INFO] Creating Consul cluster (%s)", clusterID) - payload, err := clients.CreateConsulCluster(ctx, client, loc, clusterID, datacenter, consulVersion, - numServers, !publicEndpoint, connectEnabled, newLink(loc, "hvn", hvnID), primary) + consulCuster := &consulmodels.HashicorpCloudConsul20200826Cluster{ + Config: &consulmodels.HashicorpCloudConsul20200826ClusterConfig{ + CapacityConfig: &consulmodels.HashicorpCloudConsul20200826CapacityConfig{ + NumServers: numServers, + }, + ConsulConfig: &consulmodels.HashicorpCloudConsul20200826ConsulConfig{ + ConnectEnabled: connectEnabled, + Datacenter: datacenter, + Primary: primary, + }, + MaintenanceConfig: nil, + NetworkConfig: &consulmodels.HashicorpCloudConsul20200826NetworkConfig{ + Network: newLink(loc, "hvn", hvnID), + Private: !publicEndpoint, + }, + }, + ConsulVersion: consulVersion, + ID: clusterID, + Location: loc, + } + + payload, err := clients.CreateConsulCluster(ctx, client, loc, consulCuster) if err != nil { return diag.Errorf("unable to create Consul cluster (%s): %v", clusterID, err) } From 713419dd76235fa24518fbf545865d8b424e9b38 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 16:35:49 -0800 Subject: [PATCH 10/13] Explicitly build the self_link instead of using tf resource id --- internal/provider/resource_consul_cluster.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index fbe3ca9f5..9280a7aa1 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -471,8 +471,12 @@ func setConsulClusterResourceData(d *schema.ResourceData, cluster *consulmodels. return err } - // self_link is equal to the terraform ID of the resource - if err := d.Set("self_link", d.Id()); err != nil { + link := newLink(cluster.Location, ConsulClusterResourceType, cluster.ID) + self_link, err := linkURL(link) + if err != nil { + return err + } + if err := d.Set("self_link", self_link); err != nil { return err } From 77432a4c7beee5df6dcab2f20c671a9083e548ab Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Thu, 18 Feb 2021 17:10:31 -0800 Subject: [PATCH 11/13] HCP Consul Cluster to HCP Consul cluster --- docs/data-sources/consul_cluster.md | 4 ++-- docs/resources/consul_cluster.md | 4 ++-- internal/provider/resource_consul_cluster_root_token.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/data-sources/consul_cluster.md b/docs/data-sources/consul_cluster.md index cb8371f3b..f84449d32 100644 --- a/docs/data-sources/consul_cluster.md +++ b/docs/data-sources/consul_cluster.md @@ -43,12 +43,12 @@ data "hcp_consul_cluster" "example" { - **datacenter** (String) The Consul data center name of the cluster. If not specified, it is defaulted to the value of `cluster_id`. - **hvn_id** (String) The ID of the HVN this HCP Consul cluster is associated to. - **organization_id** (String) The ID of the organization the project for this HCP Consul cluster is located. -- **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. +- **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. - **project_id** (String) The ID of the project this HCP Consul cluster is located. - **public_endpoint** (Boolean) Denotes that the cluster has a public endpoint for the Consul UI. Defaults to false. - **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. +- **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. diff --git a/docs/resources/consul_cluster.md b/docs/resources/consul_cluster.md index 8c7befc62..c74df068e 100644 --- a/docs/resources/consul_cluster.md +++ b/docs/resources/consul_cluster.md @@ -40,7 +40,7 @@ resource "hcp_consul_cluster" "example" { - **datacenter** (String) The Consul data center name of the cluster. If not specified, it is defaulted to the value of `cluster_id`. - **id** (String) The ID of this resource. - **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. +- **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. - **timeouts** (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) @@ -61,7 +61,7 @@ resource "hcp_consul_cluster" "example" { - **project_id** (String) The ID of the project this HCP Consul cluster is located in. - **region** (String) The region where the HCP Consul cluster is located. - **scale** (Number) The number of Consul server nodes in the cluster. -- **self_link** (String) A unique URL identifying the HCP Consul Cluster. +- **self_link** (String) A unique URL identifying the HCP Consul cluster. ### Nested Schema for `timeouts` diff --git a/internal/provider/resource_consul_cluster_root_token.go b/internal/provider/resource_consul_cluster_root_token.go index 2c8c916c1..2612ac6cd 100644 --- a/internal/provider/resource_consul_cluster_root_token.go +++ b/internal/provider/resource_consul_cluster_root_token.go @@ -105,7 +105,7 @@ func resourceConsulClusterRootTokenCreate(ctx context.Context, d *schema.Resourc rootTokenResp, err := clients.CreateCustomerRootACLToken(ctx, client, loc, clusterID) if err != nil { - return diag.Errorf("error creating HCP Consul Cluster root ACL token (cluster_id %q) (project_id %q): %+v", + return diag.Errorf("error creating HCP Consul cluster root ACL token (cluster_id %q) (project_id %q): %+v", clusterID, projectID, err, @@ -154,7 +154,7 @@ func resourceConsulClusterRootTokenRead(ctx context.Context, d *schema.ResourceD if err != nil { if clients.IsResponseCodeNotFound(err) { // No cluster exists, so this root token should be removed from state - log.Printf("[WARN] no HCP Consul Cluster found with (cluster_id %q) (project_id %q); removing root token.", + log.Printf("[WARN] no HCP Consul cluster found with (cluster_id %q) (project_id %q); removing root token.", clusterID, projectID, ) @@ -192,7 +192,7 @@ func resourceConsulClusterRootTokenDelete(ctx context.Context, d *schema.Resourc if err != nil { if clients.IsResponseCodeNotFound(err) { // No cluster exists, so this root token should be removed from state - log.Printf("[WARN] no HCP Consul Cluster found with (cluster_id %q) (project_id %q); removing root token.", + log.Printf("[WARN] no HCP Consul cluster found with (cluster_id %q) (project_id %q); removing root token.", clusterID, projectID, ) From 862fe684f494c6ad540d021677626ec4fe1349a6 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Fri, 19 Feb 2021 11:36:27 -0800 Subject: [PATCH 12/13] Update index.md and fix sentence in docs --- docs/guides/consul-federation.md | 2 +- docs/index.md | 8 ++++++++ examples/provider/provider.tf | 8 ++++++++ templates/guides/consul-federation.md.tmpl | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/guides/consul-federation.md b/docs/guides/consul-federation.md index a1ac423db..f69d29d7c 100644 --- a/docs/guides/consul-federation.md +++ b/docs/guides/consul-federation.md @@ -7,7 +7,7 @@ description: |- # Federate a new HCP Consul cluster with an existing one -Once you have a HCP Consul cluster, you can create new Consul cluster to federate with the existing one. +Once you have a HCP Consul cluster, you can create a new Consul cluster to federate with the existing one. ```terraform resource "hcp_hvn" "example" { diff --git a/docs/index.md b/docs/index.md index 1c27c36a6..32df8a0da 100644 --- a/docs/index.md +++ b/docs/index.md @@ -71,6 +71,14 @@ resource "hcp_consul_cluster" "example" { cluster_id = "hcp-tf-example-consul-cluster" tier = "development" } + +// Create a secondary Consul cluster to federate with the existing Consul cluster +resource "hcp_consul_cluster" "example_secondary" { + hvn_id = hcp_hvn.example_hvn.hvn_id + cluster_id = "hcp-tf-example-consul-cluster-secondary" + tier = "development" + primary_link = hcp_consul_cluster.example.self_link +} ``` ## Schema diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index e6a87a506..c6f7f9eea 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -52,4 +52,12 @@ resource "hcp_consul_cluster" "example" { hvn_id = hcp_hvn.example_hvn.hvn_id cluster_id = "hcp-tf-example-consul-cluster" tier = "development" +} + +// Create a secondary Consul cluster to federate with the existing Consul cluster +resource "hcp_consul_cluster" "example_secondary" { + hvn_id = hcp_hvn.example_hvn.hvn_id + cluster_id = "hcp-tf-example-consul-cluster-secondary" + tier = "development" + primary_link = hcp_consul_cluster.example.self_link } \ No newline at end of file diff --git a/templates/guides/consul-federation.md.tmpl b/templates/guides/consul-federation.md.tmpl index 595b496c5..6e5d18f1b 100644 --- a/templates/guides/consul-federation.md.tmpl +++ b/templates/guides/consul-federation.md.tmpl @@ -7,6 +7,6 @@ description: |- # Federate a new HCP Consul cluster with an existing one -Once you have a HCP Consul cluster, you can create new Consul cluster to federate with the existing one. +Once you have a HCP Consul cluster, you can create a new Consul cluster to federate with the existing one. {{ tffile "examples/guides/consul_cluster_federation/main.tf" }} \ No newline at end of file From 8ad8ed095f227ba6f425fe28990b482046940ce6 Mon Sep 17 00:00:00 2001 From: Riddhi Shah Date: Fri, 19 Feb 2021 11:46:30 -0800 Subject: [PATCH 13/13] Remove conditional for checking primary's org id --- internal/provider/resource_consul_cluster.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/provider/resource_consul_cluster.go b/internal/provider/resource_consul_cluster.go index 9280a7aa1..de2cec513 100644 --- a/internal/provider/resource_consul_cluster.go +++ b/internal/provider/resource_consul_cluster.go @@ -280,13 +280,11 @@ func resourceConsulClusterCreate(ctx context.Context, d *schema.ResourceData, me if err != nil { return diag.Errorf(err.Error()) } - if primary.Location.OrganizationID == "" { - primaryOrgID, err := clients.GetParentOrganizationIDByProjectID(ctx, client, primary.Location.ProjectID) - if err != nil { - return diag.Errorf("Error determining organization of primary cluster. %v", err) - } - primary.Location.OrganizationID = primaryOrgID + primaryOrgID, err := clients.GetParentOrganizationIDByProjectID(ctx, client, primary.Location.ProjectID) + if err != nil { + return diag.Errorf("Error determining organization of primary cluster. %v", err) } + primary.Location.OrganizationID = primaryOrgID // fetch the primary cluster primaryConsulCluster, err := clients.GetConsulClusterByID(ctx, client, primary.Location, primary.ID) if err != nil {