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

Add HCP status check to run prior to TF commands #184

Merged
merged 8 commits into from
Aug 12, 2021
Merged

Conversation

bcmdarroch
Copy link
Contributor

@bcmdarroch bcmdarroch commented Aug 10, 2021

🛠️ Description

Inspired by a recent issue (#172), this PR adds a check to the ConfigureContextFunc hook that pings the HCP status json endpoint (https://pdrzb3d64wsj.statuspage.io/api/v2/components.json) and returns one of the following based on HCP's platform status:

  • operational: no error or warning
  • outage: error
  • degraded_performance or under_maintenance: a warning, which both prints a debug line and only shows if an error is triggered later

NOTE: once hashicorp/terraform-plugin-sdk#790 is fixed, the warnings should show whether or not an error triggers.

This check runs before: terraform plan, terraform apply, terraform refresh, terraform destroy.

$  terraform plan               

│ Error: HCP is currently experiencing an outage. Please check https://status.hashicorp.com/ for more details.
│ 
│   with provider["localhost/providers/hcp"],
│   on example.tf line 15, in provider "hcp":
│   15: provider "hcp" {}
│ 
$  terraform apply

2021-08-10T11:58:19.443-0700 [INFO]  provider.terraform-provider-hcp: 2021/08/10 11:58:19 HCP is undergoing maintenance that may affect performance. Please check https://status.hashicorp.com/ for more details.: timestamp=2021-08-10T11:58:19.443-0700

│ Warning: HCP is undergoing maintenance that may affect performance.
│ 
│   with provider["localhost/providers/hcp"],
│   on example.tf line 15, in provider "hcp":
│   15: provider "hcp" {}
│ 
│ Please check https://status.hashicorp.com/ for more details.
╵
╷
│ Error: something else failed
│ 
│   with provider["localhost/providers/hcp"],
│   on example.tf line 15, in provider "hcp":
│   15: provider "hcp" {}
│ 

🚢 Release Note

Release note for CHANGELOG:

* provider: add HCP status check to run before TF commands [GH-184]

🏗️ Acceptance tests

  • Have you run the acceptance tests on this branch?

Output from acceptance testing (just running HVN to do a quick verify):

$ make testacc TESTARGS='-run=TestAccHvn'

--- PASS: TestAccHvn (73.78s)

Copy link
Contributor

@xargs-P xargs-P 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

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.

This is really cool! I left some small comments, but approving because the behavior looks good.

@@ -64,8 +68,87 @@ func New() func() *schema.Provider {
}
}

const statuspageUrl = "https://pdrzb3d64wsj.statuspage.io/api/v2/components.json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this always check the production status? Maybe an edge case, but it seems like this could unnecessarily disrupt testing in lower envs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent point! Went ahead and added a HCP_HOST_PATH check so this only runs when pointed at prod.

func configure(p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {

// Check the Hashicorp status page in case there's an outage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe move this functionality out to a separate file, and then just call something like bool, diags = statuspage.isHCPOperational(). Mainly suggesting this so that the provider/provider.go doesn't become unwieldy as more functionality is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I like that plan

@bcmdarroch bcmdarroch merged commit 3be6359 into main Aug 12, 2021
@bcmdarroch bcmdarroch deleted the add-status-check branch August 12, 2021 22:18
@tmatilai
Copy link

tmatilai commented Sep 27, 2021

I just saw this in action and I think it's brilliant! 😍
Thanks!

(I mean, the functionality, not the degraded performance 😆)

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