-
Notifications
You must be signed in to change notification settings - Fork 50
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-1716: Add HCP Consul federation support #68
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't have federation enabled and attempt to use it from the TF provider how does this present itself to the user?
@mkeeler : The user would get an error like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exciting. Which changes were generated and which are the ones you did? Mostly asking because that would make it a little easier to review.
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if this kind of validation should live in cloud-consul-service
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 The provider does some basic validation, like input format and verifying the existence of dependent resources, but I'd agree that this seems closer to Consul business logic. That being said, I could see the advantage of having the request fail sooner, giving the user quicker feedback. How much later down the line would the consul service check for the primary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me verify if this is done in the consul-service. If not, definitely sounds like a good place to include it vs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind. The reason I have this check in here is because I need the primary's region config (primary.Location.Region). Else, the below error is raised:
Error: unable to create Consul cluster (consul-cluster-secondary): [POST /consul/2020-08-26/organizations/{cluster.location.organization_id}/projects/{cluster.location.project_id}/clusters][400] ConsulService_Create default &{Code:3 Details:[0xc000151e60] Error:config: (consul_config: (primary: (location: (region: cannot be blank.).).).). Message:config: (consul_config: (primary: (location: (region: cannot be blank.).).).).}```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Code LGTM, just had two comments
Hi @riddhi89 , things are looking good. 👌 Can you add a /examples/guides/ markdown for federation? And also update the example in docs/index.md ? Customers will be very interested in this functionality. So it would be sweet to give them as much help as possible. |
@@ -0,0 +1,15 @@ | |||
data "hcp_hvn" "example" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In these examples, we've generally been using resource
for all the HCP resources, to encourage managing all those resources with the provider. We use data sources only for external resources like an AWS arn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! There's a few open questions I'm curious about: the necessity of self_link
and whether or not we should push the verification of the primary cluster's existence into consul service.
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this update! Awkward timing with my tech debt chore in the sdk 😅
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 The provider does some basic validation, like input format and verifying the existence of dependent resources, but I'd agree that this seems closer to Consul business logic. That being said, I could see the advantage of having the request fail sooner, giving the user quicker feedback. How much later down the line would the consul service check for the primary?
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the attribute self_link
needed if it's the same as the terraform ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's a separate field is to be explicit to the user that it is a separate property so they aren't confused between, id
and cluster_id
. It also protects against the Terraform id format being changed in the future (not likely but 🤷 ).
That being said, I think it might be best to "re-build" the link using the newLink
and linkUrl
functions just so we aren't relying on the id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be best to "re-build" the link
Makes sense. Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
internal/clients/consul_cluster.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of params to this function and the two links at the end make me think it would be easy to flip the hvn and primary in the future. What do you think about it taking in a single consulmodels.HashicorpCloudConsul20200826Cluster
struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good improvement to me. Will update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Adds federation support for HCP Consul.
Co-authored-by: Brenna Hewer-Darroch <[email protected]>
Co-authored-by: Brenna Hewer-Darroch <[email protected]>
Co-authored-by: Brenna Hewer-Darroch <[email protected]>
Co-authored-by: Brenna Hewer-Darroch <[email protected]>
@i0rek
All the changes within docs/* were generated. |
Thanks @riddhi89 . |
docs/guides/consul-federation.md
Outdated
|
||
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you adding this guide. ❤️
Can we add an a
to the sentence here?
Once you have a HCP Consul cluster, you can create a new Consul cluster to federate with the existing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
if err != nil { | ||
return diag.Errorf(err.Error()) | ||
} | ||
if primary.Location.OrganizationID == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: With the implementation you have here, you can probably take this block of code out of the primary.Location.OrganizationID == ""
conditional. parseLinkURL()
parses the URL without attempting to resolve any additional information, so primary.Location.OrganizationID
would always be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds federation support for HCP Consul.