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-1760: Add Consul versions data source #63

Merged
merged 4 commits into from
Feb 18, 2021

Conversation

alexmunda
Copy link
Contributor

Based off the hcs_consul_versions data source, we can allows users to explicitly set their Consul cluster version to the latest recommended Consul version that HCP supports. This means that any time the recommended HCP Consul version changes, someone utilizing the recommended field of the consul_versions data source will be prompted to upgrade their cluster the next time they run terraform plan:

❯ terraform plan
hcp_hvn.example_hvn: Refreshing state... 
hcp_consul_cluster.example_consul_cluster: Refreshing state... 

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # hcp_consul_cluster.example_consul_cluster will be updated in-place
  ~ resource "hcp_consul_cluster" "example_consul_cluster" {
        id                            = "/project/XXX/hashicorp.consul.cluster/hcp-tf-example-consul-cluster"
      ~ min_consul_version            = "v1.9.2" -> "v1.9.3"
        # (19 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

This data source also informs users of the Consul versions that HCP supports, in the case where they are looking to use a specific Consul version.

If HCP offers preview versions of Consul in the future, users would be able to discover and set min_consul_version of their cluster using this data source.

❯ tf show
# data.hcp_consul_versions.versions:
data "hcp_consul_versions" "versions" {
    available   = [
        "v1.9.3",
        "v1.9.2",
        "v1.9.1",
        "v1.9.0",
        "v1.8.8",
        "v1.8.7",
        "v1.8.6",
        "v1.8.4",
        "v1.8.0",
    ]
    id          = "recommended/v1.9.3/available_len/9/preview_len/0"
    preview     = []
    recommended = "v1.9.3"
}

Usage:

data "hcp_consul_versions" "versions" {}

resource "hcp_consul_cluster" "example_consul_cluster" {
  hvn_id             = hcp_hvn.example_hvn.hvn_id
  cluster_id         = "hcp-tf-example-consul-cluster"
  tier               = "development"
  min_consul_version = data.hcp_consul_versions.versions.recommended
}

Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

Two things.

First is should we expose preview versions in the provider before we support them in HCP itself? If we wanted to call them something other than preview in the future once we went down the path of implementing them then it would potentially be a breaking change to the provider.

Secondly the doc comment I pointed out doesn't match the func name. However the name in the comment is referenced from new code so I am not too sure whats going on here.

internal/clients/consul_cluster.go Show resolved Hide resolved
@alexmunda
Copy link
Contributor Author

First is should we expose preview versions in the provider before we support them in HCP itself? If we wanted to call them something other than preview in the future once we went down the path of implementing them then it would potentially be a breaking change to the provider.

Great point @mkeeler. Fortunately this implementation is tied to the VersionStatus enum in the 2020-08-26 version of the consul-service API. If down the road that enum is changed, it would require a new consul-service API version to be created, the 2020-08-26 version would still function as expected, and we could safely update the data source implementation to the new API version's enum without breaking existing functionality.

Copy link
Contributor

@roaks3 roaks3 left a comment

Choose a reason for hiding this comment

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

LGTM, my comment on the id used here should not be blocking

internal/provider/data_source_consul_versions.go Outdated Show resolved Hide resolved
@alexmunda
Copy link
Contributor Author

data "hcp_consul_versions" "versions" {
    available   = [
        "v1.9.3",
        "v1.9.2",
        "v1.9.1",
        "v1.9.0",
        "v1.8.8",
        "v1.8.7",
        "v1.8.6",
        "v1.8.4",
        "v1.8.0",
    ]
    id          = "16fe24158cef6090063cae717b555142"
    preview     = []
    recommended = "v1.9.3"
}

Copy link
Contributor

@roaks3 roaks3 left a comment

Choose a reason for hiding this comment

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

LGTM, just had one comment that might make the ids more robust

return strings.Join(otherVersions, ", ")
}

return fmt.Sprintf("%s, %s", recommendedVersion, strings.Join(otherVersions, ", "))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be weird to prepend this string with something like recommended: (and same for line 61)? It might be overkill, but I think there's an edge case where eg. v1.9.0, v1.8.6, v1.8.4 would be produced by two configurations: no recommended version, and v1.9.0 recommended 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.

I can definitely get behind adding it for this line. On 61 since there would only be 1 version returned (the recommended one) it seems like overkill 🤷

@alexmunda alexmunda merged commit f727b2d into main Feb 18, 2021
@alexmunda alexmunda deleted the munda/f-hcs-1760-consul-versions-data branch February 18, 2021 23:28
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.

None yet

3 participants