GithubHelp home page GithubHelp logo

statuscakedev / terraform-provider-statuscake Goto Github PK

View Code? Open in Web Editor NEW
34.0 11.0 56.0 5.81 MB

Terraform StatusCake provider

Home Page: https://registry.terraform.io/providers/StatusCakeDev/statuscake/

License: Mozilla Public License 2.0

Makefile 0.76% Go 99.24%
terraform terraform-provider statuscake

terraform-provider-statuscake's People

Contributors

chris-gilpatrick avatar dependabot[bot] avatar ewannoble avatar github-actions[bot] avatar jlosito avatar tomasbasham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-statuscake's Issues

Rename argument `contact_group` in `contact_groups` on `statuscake_test` resource

The argument contact_group on the statuscake_test resource accepts a list. Also the statuscake API behind contact groups is /ContactGroups.

Wouldn't it be nice to rename this argument to contact_groups instead?

I know this will create non-backward compatible changes but if the change is made in a provider version bump we can support the old contact_group argument for one or two versions with a deprecation warning.

What do you think?

statuscake_uptime_check created but error on terraform apply

Describe the bug
Error while applying creation resource of type statuscake_uptime_check
The resource is successfully created (can be seen in statuscake web interface) but an error is thrown after creation and nothing is added to the terraform.tfstate

module.statuscake.statuscake_uptime_check.example_com: Creating...
╷
│ Error: Request cancelled
│ 
│   with module.statuscake.statuscake_uptime_check.example_com,
│   on statuscake/statuscake_tests.tf line 1, in resource "statuscake_uptime_check" "example_com":
│    1: resource "statuscake_uptime_check" "example_com" {
│ 
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.
╵

Stack trace from the terraform-provider-statuscake_v2.0.0 plugin:

panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 27 [running]:
reflect.valueInterface({0x0, 0x0, 0x40d247}, 0x8)
        reflect/value.go:1369 +0x10e
reflect.Value.Interface(...)
        reflect/value.go:1364
github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider.stringElem({0xb17f80, 0x0})
        github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider/utils.go:37 +0xbe
github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider.flattenUptimeCheckRequestHeaders({0xb17f80, 0x0}, 0xc42bd8)
        github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider/resource_uptime_check.go:1114 +0x45
github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider.flattenUptimeCheckHTTPCheck({0xc30740, 0xc0001b6e20}, 0x9)
        github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider/resource_uptime_check.go:964 +0x5be
github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider.resourceStatusCakeUptimeCheckRead({0xd4d4a8, 0xc000618b40}, 0xc000402e00, {0xc353a0, 0xc0004a4780})
        github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider/resource_uptime_check.go:505 +0xad5
github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider.resourceStatusCakeUptimeCheckCreate({0xd4d4a8, 0xc000618b40}, 0xc0001b7668, {0xc353a0, 0xc0004a4780})
        github.com/StatusCakeDev/terraform-provider-statuscake/internal/provider/resource_uptime_check.go:471 +0xe66
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc00029d420, {0xd4d438, 0xc0003f6440}, 0x2, {0xc353a0, 0xc0004a4780})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:341 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00029d420, {0xd4d438, 0xc0003f6440}, 0xc000430dd0, 0xc000402c80, {0xc353a0, 0xc0004a4780})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:467 +0x871
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0002907c8, {0xd4d438, 0xc0003f6440}, 0xc00042a640)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:977 +0xd8a
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000328be0, {0xd4d4e0, 0xc0003fa1e0}, 0xc000506000)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:810 +0x5eb
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xc0d560, 0xc000328be0}, {0xd4d4e0, 0xc0003fa1e0}, 0xc000618180, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0002ae700, {0xd5a810, 0xc00040c1a0}, 0xc000012000, 0xc0003d10b0, 0x12565e0, 0x0)
        google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0002ae700, {0xd5a810, 0xc00040c1a0}, 0xc000012000, 0x0)
        google.golang.org/[email protected]/server.go:1616 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:919 +0x294

Error: The terraform-provider-statuscake_v2.0.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

To Reproduce
Steps to reproduce the behavior:

  1. Download this repository https://github.com/Eagle-One1/statuscake
  2. Download status cake provider 2.0.0-pre
  3. Unzip the content in ~/.terraform.d/plugins/registry.terraform.io/statuscakedev/statuscake/2.0.0/linux_amd64/terraform-provider-statuscake_v2.0.0
  4. run terraform init in the previously cloned repository
  5. copy terraform.tfvars.sample to terraform.tfvars
  6. replace statuscake_api_key in terraform.tfvars
  7. run terraform apply and try to apply

Expected behavior
statuscake_uptime_check deployed with no errors and added to terraform.tfstate

Additional context
Trying to test the provider, tell me if you need more details

Feature request: Contact groups and Integrations

Hi there,

the provider should support Contact groups and Integrations to avoid UI usage by using for example integration IDs as outputs from the TF PagerDuty provider. I know that the StatusCake API V1 does not support Integrations yet, but I did not find out myself how I could report a feature request for the StatusCake API. Does anybody know that?

StatusCake seems to be loosing competition battle in this area: UptimeRobot API supports the full cycle of creating uptime tests connected to the alert contacts. PagerDuty support was added recently to their API, so I suppose that their TF provider will add it soon too.

P.S. I know that there is good alternative TF provider implementation for StatusCake , which is blocked on the lack of API endpoint for the Integrations too.

[PROPOSAL] Switch to Go Modules

As part of the preparation for Terraform v0.12, we would like to migrate all providers to use Go Modules. We plan to continue checking dependencies into vendor/ to remain compatible with existing tooling/CI for a period of time, however go modules will be used for management. Go Modules is the official solution for the go programming language, we understand some providers might not want this change yet, however we encourage providers to begin looking towards the switch as this is how we will be managing all Go projects in the future. Would maintainers please react with 👍 for support, or 👎 if you wish to have this provider omitted from the first wave of pull requests. If your provider is in support, we would ask that you avoid merging any pull requests that mutate the dependencies while the Go Modules PR is open (in fact a total codefreeze would be even more helpful), otherwise we will need to close that PR and re-run go mod init. Once merged, dependencies can be added or updated as follows:

$ GO111MODULE=on go get github.com/some/module@master
$ GO111MODULE=on go mod tidy
$ GO111MODULE=on go mod vendor

GO111MODULE=on might be unnecessary depending on your environment, this example will fetch a module @ master and record it in your project's go.mod and go.sum files. It's a good idea to tidy up afterward and then copy the dependencies into vendor/. To remove dependencies from your project, simply remove all usage from your codebase and run:

$ GO111MODULE=on go mody tidy
$ GO111MODULE=on go mod vendor

Thank you sincerely for all your time, contributions, and cooperation!

Feature request: data source statuscake_contact_group

Is your feature request related to a problem? Please describe.
Contact groups are used across repositories. It would be useful if we can use a data source to get the contact group so that we can validate we have the right contact group.

Describe the solution you'd like
A data resource for statuscake_contact_group, which mirrors the statuscake_contact_group resource.

Describe alternatives you've considered

  • Hard coding the contact group ids, but these are magic numbers, which are undesirable.

Include 'Validate SSL' option for tests

Terraform Version

Terraform v0.11.7
+ provider.statuscake v0.2.0

Affected Resource(s)

Thanks for all the additional options added in v0.2.0 of this provider! 😄

I'd love to also see support for the 'Validate SSL' option:

image

Unable to reference v2 as a package

Describe the bug
When trying to use the latest release as a package the following error occurs:
require github.com/StatusCakeDev/terraform-provider-statuscake: version "v2.0.2-pre" invalid: should be v0 or v1, not v2

To Reproduce
Steps to reproduce the behavior:
require github.com/StatusCakeDev/terraform-provider-statuscake v2.0.2-pre
go mod tidy

Expected behavior
Successfully required!

Desktop (please complete the following information):

  • OS: Mac

Pull request forthcoming 😄

Error during 'plan': bind: operation not permitted

Terraform Version

$ terraform -v
Terraform v0.10.2

Affected Resource(s)

  • statuscake
  • statuscake_test

Terraform Configuration Files

These are the only configuration files in my case ..

statuscake-var-defs.tf

variable "status_cake_username" {}
variable "status_cake_api_key" {}
variable "status_cake_contact_id" {
  default = "12345"
}

statuscake-provider-def.tf

provider "statuscake" {
  username = "${var.status_cake_username}"
  apikey   = "${var.status_cake_api_key}"
}

statuscake-tests.tf

resource "statuscake_test" "api_test_one" {
  website_name = "an_example_api_test"
  website_url  = "www.google.com"
  test_type    = "HTTP"
  check_rate   = 300
  paused       = 0
  timeout      = 20
  contact_id   = "${var.status_cake_contact_id}"
}

Debug Output

https://gist.github.com/vmadman/022ea5af347e7d3160cb6afff0a15c98

Panic Output

n/a

Expected Behavior

Terraform should have produced a plan that, if applied, would create a "test" in StatusCake.

Actual Behavior

I received an error in the console and in the execution log above.

Error asking for user input: 1 error(s) occurred:

* provider.statuscake: plugin exited before we could connect

Steps to Reproduce

terraform init \
    -var "status_cake_username=<<skuser>>" \
    -var "status_cake_api_key=<<skapikey>>" \
    -var "status_cake_contact_id=<<skcontact>>" \
    "/path/to/project/terraform/resources"

.. then ..

export TF_LOG="DEBUG"
export TF_LOG_PATH="/path/to/project/terraform/logs/terraform-debug.log"
terraform plan \
    -var "status_cake_username=<<skuser>>" \
    -var "status_cake_api_key=<<skapikey>>" \
    -var "status_cake_contact_id=<<skcontact>>" \
    -state="/path/to/project/terraform/state/default-primary.tfstate" \
    -out="/path/to/project/terraform/plans/default-primary.tfplan" \
    "/path/to/project/terraform/resources"

Important Factoids

n/a

References

none known

Invalid params causes the provider to crash

Describe the bug
Invalid regions crash the provider without an informative message

To Reproduce
Steps to reproduce the behavior:

  1. Create an uptime test with an invalid region
resource "statuscake_uptime_check" "debug" {
  name           = "[DEBUG] THIS IS A TEST"
  check_interval = 30
  regions        = [
    "invalid",
  ]

  monitored_resource {
    address = "https://google.com"
  }

  http_check {
    request_method   = "HTTP"
    status_codes     = [
      "500"
    ]
  }
}
  1. Try plan/apply
  2. See it fail without a good error
╷
│ Error: failed to create uptime test: The provided parameters are invalid. Check the errors output for detailed information.
│
│   with statuscake_uptime_check.debug,
│   on foo.tf line 18, in resource "statuscake_uptime_check" "debug":
│   18: resource "statuscake_uptime_check" "debug" {
│

https://gist.github.com/marceloboeira/89c5ed85fbed1f5ea76edee3434d08fa#file-main-tf

Here is the full error log and failing test case:

https://gist.github.com/marceloboeira/89c5ed85fbed1f5ea76edee3434d08fa

Expected behavior

Error on plan (or even apply) with the information that the error is caused by the wrong region code (or any possible message the API is returning for failure).

Additional context

By removing the region's block OR using valid regions, the code works; it just took me a long time to debug and find out that the problem was the region...

Random TF plan failures ("failed to get uptime test with ID")

Describe the bug
The terraform plan randomly fails with the following error

│ Error: failed to get uptime test with ID:
│
│   with statuscake_uptime_check.proxy["e7bc74d659a3166f"],
│   on monitoring.tf line 26, in resource "statuscake_uptime_check" "proxy":
│   26: resource "statuscake_uptime_check" "proxy" {

A DEBUG plan only adds the following

2022-09-26T10:22:25.327Z [ERROR] vertex "statuscake_uptime_check.proxy" error: failed to get uptime test with ID:

To Reproduce
Run TF plan multiple times until the error happens.

Expected behavior
Plan consistently succeeds.

Additional context
Using latest version 2.0.4

`monitored_resource.address` causes a destroy/create

Is your feature request related to a problem? Please describe.
I'm mostly wondering why changing the address causes Terraform to want to destroy and recreate a monitor in StatusCake. In my case I'm using http_checks on the statuscake_uptime_check resource. If I got into the StatusCake UI I can change the URL of the check without a problem so it seems like the Terraform provider should be able to accomplish the same without recreating the whole check and, presumably, loosing the history associated with the check.

Describe the solution you'd like
It would be best if the URL could be updated in place.

Describe alternatives you've considered
I'm not sure what other solutions inside Terraform there would be. Right now as a workaround I manually update the URL in the UI and then rerun the plan in Terraform but this kinda defeats the purpose of Terraform managing these resources.

Additional context
Add any other context or screenshots about the feature request here.

How to create dns tests?

Please explain to to create dns tests.
I can not find arguments for Expected IP and DNS Server IP.

Set 'follow_redirect' to true by default

Terraform Version

Terraform v0.11.7
+ provider.statuscake v0.2.0

Affected Resource(s)

v0.2.0 of this provider added support for the follow_redirect option, which by default Terraform sets to false:

image

The StatusCake UI however, when creating a new test, has this option on by default:

image

For consistency between Terraform and the UI, I'd suggest it would be good to use the same defaults where possible. For me, this manifested in diffs upon upgrading from v0.1.0 of the provider to v0.2.0, because my previous tests were implicitly created with 'follow redirects' turned on.

Terraform Registry missing ARM64 version of StatusCake Provider

Terraform Version

v0.13.5

Affected Resource(s)

StatusCake provider

Terraform Configuration Files

n/a

Expected Behavior

What should have happened?

Actual Behavior

Error: Failed to install provider

Error while installing -/statuscake v1.0.0: provider
registry.terraform.io/-/statuscake 1.0.0 is not available for linux_arm64

Steps to Reproduce

Run a terraform init on a project with a statuscake provider, but on an ARM64 machine, such as a raspberry pi 4

Feature request CRUD for Pagespeed Tests

The StatusCake API includes support for CRUD of the Pagespeed tests.

https://www.statuscake.com/api/Page%20Speed/Create%20Pagespeed%20Test.md

https://www.statuscake.com/api/Page%20Speed/Delete%20Pagespeed%20Test.md

https://www.statuscake.com/api/Page%20Speed/Update%20Pagespeed%20Test.md

https://www.statuscake.com/api/Page%20Speed/List%20Pagespeed%20Test.md

It would be nice to add this to the Statuscake provider. Corresponding request opened in the statuscake client library that this provider uses: DreamItGetIT/statuscake#49

Terraform 0.12 compatibility

Provider currently does not work with Terraform 0.12.

Error

$ terraform init

Initializing the backend...

Successfully configured the backend "gcs"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Checking for available provider plugins...

No available provider "statuscake" plugins are compatible with this Terraform version.

From time to time, new Terraform major releases can change the requirements for
plugins such that older plugins become incompatible.

Terraform checked all of the plugin versions matching the given constraint:
    (any version)

Unfortunately, none of the suitable versions are compatible with this version
of Terraform. If you have recently upgraded Terraform, it may be necessary to
move to a newer major release of this provider. Alternatively, if you are
attempting to upgrade the provider to a new major version you may need to
also upgrade Terraform to support the new version.

Consult the documentation for this provider for more information on
compatibility between provider versions and Terraform versions.


Error: no available version is compatible with this version of Terraform

Variable statuscake_custom_endpoint not optional in provider configuration

Describe the bug
The var statuscake_custom_endpoint seems to not be optional in provider configuration whereas the documentation say it is

To Reproduce
Use the provider as in the doc examples, with only api_token in the provider configuration

Expected behavior
No need to set statuscake_custom_endpoint, the default var should be "https://api.statuscake.com/" I think,

Additional context
Thanks for your job with the 2.x which seems to be have more functionalities and flexibility

statuscake_test resource fails on second apply with identical configuration

Terraform Version

Terraform v0.14.6
+ provider registry.terraform.io/terraform-providers/statuscake v1.0.0

Affected Resource(s)

Please list the resources as a list, for example:

  • statuscake_test

Terraform Configuration Files

resource "statuscake_test" "django" {                                                                                                                          
    check_rate       = 60                                                                                                                                      
    confirmations    = 0                                                                                                                                       
    contact_group    = [                                                                                                                                       
        "121431",                                                                                                                                              
    ]                                                                                                                                                          
    do_not_find      = false                                                                                                                                   
    enable_ssl_alert = true                                                                                                                                    
    final_endpoint   = "https://test.example.com/"                                                                                                             
    follow_redirect  = true                                                                                                                                    
    id               = "1235321"                                                                                                                               
    node_locations   = []                                                                                                                                      
    paused           = false                                                                                                                                   
    port             = 0                                                                                                                                       
    status           = "Up"                                                                                                                                    
    test_id          = "1235321"                                                                                                                               
    test_tags        = [                                                                                                                                       
        "django",                                                                                                                                              
    ]                                                                                                                                                          
    test_type        = "HTTP"                                                                                                                                  
    timeout          = 40                                                                                                                                      
    trigger_rate     = 5                                                                                                                                       
    uptime           = 0
    use_jar          = 0                                                                                                                                       
    website_name     = "test.example.com"                                                                                                                      
    website_url      = "test.example.com"                                                                                                                      
}

Expected Behavior

Test should be created in first apply run, secon run should not perform an changes.

Actual Behavior

# terraform apply -target 'module.hatch-test-example-com.statuscake_test.django[0]'

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.hatch-test-example-com.statuscake_test.django[0] will be created
  + resource "statuscake_test" "django" {
      + check_rate       = 60
      + contact_group    = [
          + "121431",
        ]
      + enable_ssl_alert = true
      + final_endpoint   = "https://test.example.com/"
      + follow_redirect  = true
      + id               = (known after apply)
      + paused           = false
      + status           = (known after apply)
      + test_id          = (known after apply)
      + test_tags        = [
          + "django",
        ]
      + test_type        = "HTTP"
      + timeout          = 40
      + trigger_rate     = 5
      + uptime           = (known after apply)
      + website_name     = "test.example.com"
      + website_url      = "test.example.com"
    }

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


Warning: Resource targeting is in effect

You are creating a plan with the -target option, which means that the result
of this plan may not represent all of the changes requested by the current
configuration.
		
The -target option is not for routine use, and is provided only for
exceptional situations such as recovering from errors or mistakes, or when
Terraform specifically suggests to use it as part of an error message.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.hatch-test-example-com.statuscake_test.django[0]: Creating...
module.hatch-test-example-com.statuscake_test.django[0]: Creation complete after 1s [id=1235325]

Warning: Applied changes may be incomplete

The plan was created with the -target option in effect, so some changes
requested in the configuration may have been ignored and the output values may
not be fully updated. Run the following command to verify that no other
changes are pending:
    terraform plan
	
Note that the -target option is not suitable for routine use, and is provided
only for exceptional situations such as recovering from errors or mistakes, or
when Terraform specifically suggests to use it as part of an error message.


Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
6aa012f6d6a3:~/project/terraform# terraform apply -target 'module.hatch-test-example-com.statuscake_test.django[0]'
module.hatch-test-example-com.statuscake_test.django[0]: Refreshing state... [id=1235325]

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:

  # module.hatch-test-example-com.statuscake_test.django[0] will be updated in-place
  ~ resource "statuscake_test" "django" {
      ~ enable_ssl_alert = false -> true
        id               = "1235325"
        # (19 unchanged attributes hidden)
    }

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


Warning: Resource targeting is in effect

You are creating a plan with the -target option, which means that the result
of this plan may not represent all of the changes requested by the current
configuration.
		
The -target option is not for routine use, and is provided only for
exceptional situations such as recovering from errors or mistakes, or when
Terraform specifically suggests to use it as part of an error message.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

module.hatch-test-example-com.statuscake_test.django[0]: Modifying... [id=1235325]

Warning: Applied changes may be incomplete

The plan was created with the -target option in effect, so some changes
requested in the configuration may have been ignored and the output values may
not be fully updated. Run the following command to verify that no other
changes are pending:
    terraform plan
	
Note that the -target option is not suitable for routine use, and is provided
only for exceptional situations such as recovering from errors or mistakes, or
when Terraform specifically suggests to use it as part of an error message.


Error: Error Updating StatusCake Test: No data has been updated (is any data different?)

  on modules/heroku_django_app/main.tf line 82, in resource "statuscake_test" "django":
  82: resource "statuscake_test" "django" {

Provide a way to set the api token of the provider as an env var

Is your feature request related to a problem? Please describe.

Setting up the provider requires to set the api_token in the provider block:

provider "statuscake" {
  api_token = "my-api-token"
}

Describe the solution you'd like

I'd like the provider to look at some env var by itself, and only fallback to api_token if this env var is not set.

Describe alternatives you've considered

To not harcode the api token, I have to explicitely define a TF_VAR_ terraform variable that I use in the provider

Import Documentation / Example?

Could an example be included for how to import existing statuscake configuration?

An example using terraform import or other suitable method.

Unable to delete a test

Terraform Version

terraform --version
Terraform v0.12.16

  • provider.aws v2.43.0
  • provider.external v1.2.0
  • provider.null v2.1.2
  • provider.random v2.2.1
  • provider.statuscake v1.0.0

Affected Resource(s)

  • statuscake_test.google

Terraform Configuration Files

After adding the following code (to test the provider)

resource "statuscake_test" "google" {
  website_name = "google.com"
  website_url  = "www.google.com"
  test_type    = "HTTP"
  check_rate   = 300
  contact_id   = 12345
}

And after removing it from our hcl files, when applying:

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

Terraform will perform the following actions:

  # statuscake_test.google will be destroyed
  - resource "statuscake_test" "google" {
      - check_rate       = 0 -> null
      - confirmations    = 0 -> null
      - contact_id       = 12345 -> null
      - do_not_find      = false -> null
      - enable_ssl_alert = false -> null
      - follow_redirect  = false -> null
      - id               = "5348916" -> null
      - node_locations   = [] -> null
      - paused           = false -> null
      - port             = 0 -> null
      - test_id          = "5348916" -> null
      - timeout          = 0 -> null
      - trigger_rate     = 0 -> null
      - uptime           = 0 -> null
      - use_jar          = 0 -> null
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statuscake_test.google: Destroying... [id=5348916]

Error:


We've got an error without any explanations.

Debug Output

(abstract with TF_LOG="debug")

2020/01/03 15:41:33 [DEBUG] statuscake_test.google: apply errored, but we're indicating that via the Error pointer rather than returning it:
2020/01/03 15:41:33 [ERROR] <root>: eval: *terraform.EvalApplyPost, err:
2020/01/03 15:41:33 [ERROR] <root>: eval: *terraform.EvalSequence, err:
2020/01/03 15:41:33 [ERROR] <root>: eval: *terraform.EvalOpFilter, err:
2020/01/03 15:41:33 [TRACE] [walkApply] Exiting eval tree: statuscake_test.google (destroy)
2020/01/03 15:41:33 [TRACE] vertex "statuscake_test.google (destroy)": visit complete

Panic Output

None

Expected Behavior

statuscake_test.google should have been destroyed and removed from the state.
That was the case after several apply, but the resource remained in terraform state.

Manually removing is a workaround:
terragrunt state rm statuscake_test.google

Actual Behavior

Error without any explanation

Steps to Reproduce

See above.

Support specifing a workspace

I had to create an account in Statuscake, then this account is "invited" into a business subscription (in Statuscake). When I try to deploy resources in the workspace/sub-account I got invited to, the resources are created on the original account and not on the workspace/sub-account one.

Seems there should be a workspace/sub-account option that we can leverage to specify a workspace/sub-account vs the default account.

Contact Group not apply correctly

When I try to create or update a Test, after the apply passed I can see the contact group on the Test overview:

image

But when I go to the Edit Test section, there is no contact group at all:

image

So no mail or notifications are send, when a test fail.
The StatusCake API return me a None value on the variable contact_group.

Also when I import an existing Test with contact groups attached (create by hand) in the tfstate the "contact_group" is equal to "null"

I try with Terraform v10, v11 and v12.

Statuscake provider errors when reapplying manually deleted resources

This issue was originally opened by @LukeDanielSmith as hashicorp/terraform#19572. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.11.10

Terraform Configuration Files

Module:

provider "statuscake" {
  username = "devops"
  alias = "scake"

  version = "= 0.2.0"
}

resource "statuscake_test" "statuscake" {
  provider        = "statuscake.scake"
  count           = "${lookup("${var.statuscake_service_name}", "${var.layer_version}", "0") == 1 ? 1: 0}"
  website_name    = "${var.website_name == "" ? "TF-${var.environment}-${var.service}" : "${var.website_name}"}"
  test_type       = "${var.test_type}"
  check_rate      = "${var.check_rate}"
  contact_id      = "${var.contact_id["${var.environment}"] }"
  website_url     = "${var.website_url == "" ? "${var.zuul}/${var.service}/${var.health_endpoint}" : "${var.website_url}"}"
  follow_redirect = "${var.follow_redirect}"
  confirmations   = "${var.confirmations}"
  trigger_rate    = "${var.trigger_rate}"
  timeout         = "${var.test_timeout}"

  find_string     = "${var.find_string}"
  do_not_find     = "${var.do_not_find}"
  post_raw        = "${var.post_raw}"
  custom_header   = "${var.custom_header}"
  status_codes    = "${var.status_codes}"
  test_tags       = "${var.test_tags}"
}

Resource: 

module "statuscake_test_data_article_file" {
  source         = "../../../modules/statuscake_tests"
  service        = "${lookup(var.docker, "name")}"
  environment    = "${lookup(var.docker, "env")}"
  layer_version  = "${var.layer_version}"
  test_tags      = "${lookup(var.docker, "name")},${lookup(var.docker, "env" )},api"

  website_name   = "TF-${lookup(var.statuscake, "name")}"
  website_url    = "${lookup(var.statuscake, "statuscake_url")}"
  check_rate     = "${lookup(var.statuscake, "statuscake_check_rate")}"
  confirmations  = "${lookup(var.statuscake, "statuscake_confirmations")}"
  custom_header  = "${lookup(var.statuscake, "statuscake_custom_header")}"
}

tfvars:

statuscake = {
  statuscake_custom_header = "{\"x-api-key\": \"<api-key>\"}"

  name                                  = "dev-statuscake_test-data-article-file"
  statuscake_url                   = "https://api/endpoint"
  statuscake_check_rate     = "2"
  statuscake_confirmations= "2"

}

Debug Output

2018/12/07 10:43:50 [DEBUG] apply: statuscake_test.statuscake: executing Apply
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalApply
2018/12/07 10:43:50 [DEBUG] apply: statuscake_test.statuscake: executing Apply
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalReadDiff
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalCompareDiff
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalGetProvider
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalReadState
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalApplyPre
2018/12/07 10:43:50 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalApply
2018/12/07 10:43:50 [DEBUG] apply: statuscake_test.statuscake: executing Apply
2018-12-07T10:43:50.884Z [DEBUG] plugin.terraform-provider-statuscake_v0.2.0_x4: 2018/12/07 10:43:50 [DEBUG] StatusCake Test Update for 3677792
2018-12-07T10:43:50.885Z [DEBUG] plugin.terraform-provider-statuscake_v0.2.0_x4: 2018/12/07 10:43:50 [DEBUG] StatusCake Test Update for 3677793
2018-12-07T10:43:50.886Z [DEBUG] plugin.terraform-provider-statuscake_v0.2.0_x4: 2018/12/07 10:43:50 [DEBUG] StatusCake Test Update for 3677791
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalApplyProvisioners
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalIf
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalWriteDiff
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalApplyPost
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalApplyProvisioners
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalIf
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_grouped_index_file: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [TRACE] [walkApply] Exiting eval tree: module.statuscake_test_data_grouped_index_file.statuscake_test.statuscake
2018/12/07 10:43:51 [TRACE] dag/walk: upstream errored, not walking "module.statuscake_test_data_grouped_index_file.provider.statuscake.scake (close)"
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalWriteDiff
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_article_file: eval: *terraform.EvalApplyPost
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_article_file: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_article_file: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [TRACE] [walkApply] Exiting eval tree: module.statuscake_test_data_article_file.statuscake_test.statuscake
2018/12/07 10:43:51 [TRACE] dag/walk: upstream errored, not walking "module.statuscake_test_data_article_file.provider.statuscake.scake (close)"
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalApplyProvisioners
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalIf
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalWriteState
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalWriteDiff
2018/12/07 10:43:51 [TRACE] root.statuscake_test_data_novoda_file: eval: *terraform.EvalApplyPost
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_novoda_file: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [ERROR] root.statuscake_test_data_novoda_file: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
2018/12/07 10:43:51 [TRACE] [walkApply] Exiting eval tree: module.statuscake_test_data_novoda_file.statuscake_test.statuscake
2018/12/07 10:43:51 [TRACE] dag/walk: upstream errored, not walking "module.statuscake_test_data_novoda_file.provider.statuscake.scake (close)"

Crash Output

Expected Behavior

Statuscake resource should be provisioned

Actual Behavior

Errors out with the following message:

Error: Error applying plan:

3 error(s) occurred:

* module.statuscake_test_data_grouped_index_file.statuscake_test.statuscake: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
* module.statuscake_test_data_article_file.statuscake_test.statuscake: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:
* module.statuscake_test_data_novoda_file.statuscake_test.statuscake: 1 error(s) occurred:

* statuscake_test.statuscake: Error Updating StatusCake Test:

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. Delete TF managed resource via AWS console
  4. Reapply the service

Additional Context

We use the statuscake provider across our infrastructure. However the service in question differs from the rest as it is the only one that uses a API endpoint that requires an API-key in its header as its healthcheck target. We also use a wrapper script when using Terraform.

References

API retries/backoff not working

Describe the bug
While trying options to workaround the rate limit issues experienced as per #91, it looks like the retries and backoff do not work

To Reproduce
Test configuration

provider "statuscake" {
  retries  = 10
  min_backoff = 5
  max_backoff = 60

  rps = 7
}

Run terraform plan.
No retry is performed.

Expected behavior
The required number of retries with the expected backoff is performed

Additional context
version v2.0.4

ssl check "on_broken" option not working

Describe the bug
Hello StatusCakeDev team,

First, I'd like to thank you for this terraform provider, it's really helpful to use your product.

Here's an annoying bug I faced when trying to switch to your terraform provider and your new v1 API.

When creating a ssl check with the option on_broken set to true, it's not taken into account.
When trying to apply a second time , the terraform operations fails.

To Reproduce

XXXXXX is the exact same redacted value everywhere.

  1. Create the ssl check
% terraform apply
[...]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # statuscake_ssl_check.bug will be created
  + resource "statuscake_ssl_check" "bug" {
      + check_interval   = 86400
      + follow_redirects = false
      + id               = (known after apply)
      + paused           = false

      + alert_config {
          + alert_at    = [
              + 1,
              + 7,
              + 30,
            ]
          + on_broken   = true
          + on_expiry   = true
          + on_mixed    = false
          + on_reminder = true
        }

      + monitored_resource {
          + address = "https://www.google.com"
        }
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statuscake_ssl_check.bug: Creating...
statuscake_ssl_check.bug: Creation complete after 1s [id=XXXXXX]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  1. Check the ssl check state :
% curl -s -H "Authorization: Bearer ${SC_API_KEY}" 'https://api.statuscake.com/v1/ssl/XXXXXX' | jq '.'
{
  "data": {
    "id": "XXXXXX",
    "paused": false,
    "check_rate": 86400,
    "website_url": "https://www.google.com",
    "issuer_common_name": "",
    "cipher": "",
    "cipher_score": 0,
    "certificate_score": 0,
    "certificate_status": "",
    "contact_groups": [],
    "alert_at": [
      1,
      7,
      30
    ],
    "last_reminder": 0,
    "alert_reminder": true,
    "alert_expiry": true,
    "alert_broken": false, <== the problem is here
    "alert_mixed": false,
    "follow_redirects": false,
    "mixed_content": [],
    "flags": {
      "is_extended": false,
      "has_pfs": true,
      "is_broken": false,
      "is_expired": false,
      "is_missing": false,
      "is_revoked": false,
      "has_mixed": false,
      "follow_redirects": false
    }
  }
}
  1. Try another apply
% terraform apply
[...]
statuscake_ssl_check.bug: Refreshing state... [id=XXXXXX]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # statuscake_ssl_check.bug will be updated in-place
  ~ resource "statuscake_ssl_check" "bug" {
        id               = "XXXXXX"
        # (4 unchanged attributes hidden)

      ~ alert_config {
          ~ on_broken   = false -> true
            # (4 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

statuscake_ssl_check.bug: Modifying... [id=XXXXXX]
╷
│ Error: failed to update SSL check: Unexpected error. Try again later.
│
│   with statuscake_ssl_check.bug,
│   on main.tf line 39, in resource "statuscake_ssl_check" "bug":
│   39: resource "statuscake_ssl_check" "bug" {
│
╵

Expected behavior
alert_broken should be set to true

Additional informations

terraform {
  required_providers {
    statuscake = {
      source  = "StatusCakeDev/statuscake"
      version = "2.0.3"
    }
  }
  required_version = "~>1.2.5"
}
% terraform version
Terraform v1.2.5
on darwin_amd64
+ provider registry.terraform.io/statuscakedev/statuscake v2.0.3

400 Error when creating statuscake_test

Terraform Version

$ terraform -v
Terraform v0.11.13
+ provider.statuscake v0.2.0

Affected Resource(s)

Please list the resources as a list, for example:

  • statuscake_test

Terraform Configuration Files

Here are the sample configuration files:

main.tf

provider "statuscake" {
  username = "${var.API_USER}"
  apikey   = "${var.API_KEY}"
}
resource "statuscake_test" "api_check" {
  count           = "${length(var.deployments)}"
  contact_id      = "${lookup(var.deployments[count.index], "live") == "1" ? var.contacts["operations"] : "0"}"
  basic_user      = "[email protected]"
  basic_pass      = "123456"
  website_name    = "Example ${lookup(var.deployments[count.index], "num")} (via API)"
  website_url     = "http://subdomain-${lookup(var.deployments[count.index], "num")}.example.com/api/something"
  test_type       = "HTTP"
  check_rate      = "${var.check_rate}"
  trigger_rate    = "${var.trigger_rate}"
  confirmations   = "${var.confirmations}"
  follow_redirect = "true"
  status_codes    = "${var.status_codes}"
  test_tags       = "Terraform"
}

variables.tf

variable "API_USER" {
  default = "{{ MY USER NAME }}"
}

variable "API_KEY" {
  default = "{{ MY API KEY }}"
}
variable "website_name" {
  default = ""
}

variable "website_url" {
  default = ""
}

variable "contact_id" {
  default = ""
}

variable "check_rate" {
  default     = "60"
  description = "Number of seconds between tests"
}

variable "trigger_rate" {
  default     = "0"
  description = "Number of minutes from first down to alert"
}

variable "confirmations" {
  default     = "3"
  description = "Number of consecutive failures before declaring down"
}

variable "status_codes" {
  default     = "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599"
  description = "default list of status codes"
}

variable "contacts" {
  type = "map"

  default = {
    operations = "109652"
  }
}

variable "deployments" {
  description = "List of deployments"
  type        = "list"
  default     = [
    {name = "Deployment 1", num = "1", live = "1", test_uri="example.com"},
  ]
}

Debug Output

https://gist.github.com/Strainy/67de491a84f09533eda3175211107b2e

Expected Behavior

A check should have been created.

Actual Behavior

400 Error.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

N/A

References

N/A

Bug sending custom headers for requests

Describe the bug

When migrating from terraform v1 provider, we discovered that the v2 provider introduced a bug that makes it impossible to send headers because they are not formatted correctly.

"custom_header": "{\"Content-Type\":\"text/html; charset=utf-8\"}",

vs

"custom_header": "{ Content-Type = \"text/html; charset=utf-8\" }",

To Reproduce
Steps to reproduce the behavior:

The code used to request a string:

resource "statuscake_test" "my_test" {
  custom_header   = `{ Content-Type = \"text/html; charset=utf-8\"}`
}

And then it switched to request a map(string)

resource "statuscake_uptime_check" "my_test" {
  ...
  http_check {
    request_headers  = {
      "Content-Type": "text/html; charset=utf-8"
    }
  } 
  ...
}

Additional context
Add any other context about the problem here.

For me, it seems related to the fact that the map(string) is sent directly to the API without serializing it to JSON:

https://github.com/StatusCakeDev/terraform-provider-statuscake/blob/master/internal/provider/resource_uptime_check.go#L167-L173

https://github.com/StatusCakeDev/terraform-provider-statuscake/blob/master/internal/provider/resource_uptime_check.go#L914-L919

status_codes in http_check block should be optional and have sane defaults

In the 1.x version of the provider, the status_codes parameter to the statuscake_test resources was optional and had sane defaults.

In the 2.x version of the provider, the equivalent parameter is required, which means that we need to supply a (long) list of HTTP response codes we want to trigger a failure for every single check we set up.

In our experience with the 1.x provider, the defaults were fine in the vast majority of cases, meaning the behaviour of the 2.x provider is needlessly verbose.

Feature request: contact groups

Terraform Version

Terraform v0.11.10
+ provider.statuscake v0.2.0

It would be great if this provider supported creating/updating/deleting contact groups as well. It's supported in the StatusCake APi

Support for Push Tests

Is your feature request related to a problem? Please describe.
It would be helpful if there was a Terraform resources for Push Tests.

Describe the solution you'd like
A new push monitor/test resource.

Describe alternatives you've considered
Or perhaps expending the currently uptime check resources to support push tests?

Additional context
NA

Use Integrations in Contract Groups by Name not ID

Is your feature request related to a problem? Please describe.
I wanted to use existing Slack and PagerDuty Integrations in new Contact Groups created using the terraform provider. The docs say, I have to add them by their ID but I cannot get their ID (or I don't know how to get their ID). I at least can't find out the Integration ID from the UI or API.

Describe the solution you'd like
Instead it would be nice to use the Integration name or any other (API-) retrievable information that's unique.

New argument "accepted_status_codes"

As an alternative to status_codes parameter we can implement the accepted_status_codes to add only few status code we want to not be triggered on.

For example, that's how it works now if I'd want to have 204 status code being accepted:

status_codes = "205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599"

How could it look like with the parameter accepted_status_codes:

accepted_status_codes = "200, 204"

The parameter status_codes should be ingnored if being set together with accepted_status_codes one.

Default Status Codes are not set

Terraform Version

v0.12.5

Affected Resource

  • statuscake_test

Terraform Configuration Files

provider "statuscake" {
  username = "###"
  apikey   = "###"
}

resource "statuscake_test" "google" {
  website_name  = "google.com"
  website_url   = "www.google.com"
  test_type     = "HTTP"
  check_rate    = 300
  trigger_rate  = 5
  confirmations = 1
}

Expected Behavior

The Status Codes field should be populated with the default.

According to the provider documentation for status_codes
https://www.terraform.io/docs/providers/statuscake/r/test.html

Defaults are "204, 205, 206, 303, 400, 401, 403, 404, 405, 406, 408, 410, 413, 444, 429, 494, 495, 496, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 521, 522, 523, 524, 520, 598, 599".

This is true when creating a test manually but not threw terraform.

Actual Behavior

The Status Codes field is blank.

Steps to Reproduce

  1. terraform apply
  2. View the test in the UI

Important Factoids

When I call the API using cURL the default values are populated so the provider is setting it to be blank instead of allowing the default behavior.

curl -H "API: ###" -H "Username: ###"  -d "WebsiteName=MySite&WebsiteURL=www.google.com&CheckRate=300&TestType=HTTP" -X PUT https://app.statuscake.com/API/Tests/Update

Reference

Issue #5 addresses this but I still don't see the defaults being applied.

This may be because the provider is passing an empty string to the client: https://github.com/terraform-providers/terraform-provider-statuscake/blob/ebf8436f01bcacb71e3c378f08b165dfd6dd90e6/statuscake/resource_statuscaketest.go#L265

The Go status cake client may also need to be updated to add the option: querystringoptions:"omitempty"
https://github.com/DreamItGetIT/statuscake/blob/71a9c9823950c85cdacc28e362800a80119356e2/tests.go#L102

"trigger_rate" sets to default after creating resource

Terraform version

Terraform v1.1.7
on linux_amd64
provider registry.terraform.io/statuscakedev/statuscake v2.0.1-pre

Affected Resource(s)

  • statuscake_uptime_check

Terraform Configuration Files

variable "statuscake_tests" {
  type = list(object({
    website_name     = string
    website_url      = string
    test_type        = string
    check_rate       = number
    timeout          = number
    confirmations    = number
    trigger_rate     = number
    find_string      = string
    enable_ssl_alert = bool
    follow_redirect  = bool
    do_not_find      = bool
    custom_header    = map(string)
  }))
  default = [
    {
      website_name     = "Test"
      website_url      = "https://google.com"
      test_type        = "HTTP"
      check_rate       = 60
      timeout          = 10
      confirmations    = 2
      trigger_rate     = 0
      find_string      = null
      enable_ssl_alert = true
      follow_redirect  = true
      do_not_find      = false
      custom_header    = null
    }
  ]
}

resource "statuscake_uptime_check" "test" {
  for_each = {
    for service in var.statuscake_tests :
    service.website_name => service
  }

  name           = each.value.website_name
  check_interval = each.value.check_rate
  confirmation   = each.value.confirmations
  trigger_rate   = each.value.trigger_rate
  monitored_resource {
    address = each.value.website_url
  }

  http_check {
    follow_redirects = each.value.follow_redirect
    timeout          = each.value.timeout
    validate_ssl     = each.value.enable_ssl_alert

    request_headers = each.value.custom_header

    dynamic "content_matchers" {
      for_each = toset(each.value.find_string != null ? ["1"] : [])
      content {
        content = each.value.find_string
      }
    }
  }
}

Expected Behavior

Resource statuscake_uptime_check.test["Test"] should be created with "trigger_rate = 0"

Actual Behavior

# terraform apply
Terraform will perform the following actions:

  # statuscake_uptime_check.test["Test"] will be created
  + resource "statuscake_uptime_check" "test" {
      + check_interval = 60
      + confirmation   = 2
      + id             = (known after apply)
      + locations      = (known after apply)
      + name           = "Test"
      + paused         = false
      + trigger_rate   = 0

      + http_check {
          + enable_cookies   = false
          + follow_redirects = true
          + request_method   = "HTTP"
          + timeout          = 10
          + validate_ssl     = true
        }

      + monitored_resource {
          + address = "https://google.com"
        }
    }

statuscake_uptime_check.test["Test"]: Creating...
statuscake_uptime_check.test["Test"]: Creation complete after 2s [id=1234]

# terraform show
statuscake_uptime_check.test["Test"]:
resource "statuscake_uptime_check" "test" {
    check_interval = 60
    confirmation   = 2
    id             = "1234"
    locations      = []
    name           = "Test"
    paused         = false
    trigger_rate   = 4

    http_check {
        enable_cookies   = false
        follow_redirects = true
        request_method   = "HTTP"
        status_codes     = ["204","205","206","303","400","401","403","404","405","406","408","410","413","429","444","494","495","496","499","500","501","502","503","504","505","506","507","508","509","510","511","520","521","522","523","524","598","599",
        ]
        timeout          = 10
        validate_ssl     = true
    }

    monitored_resource {
        address = "https://google.com"
    }
}

As you can see, trigger_rate sets 4, as default number:

"trigger_rate": &schema.Schema{
	Type:        schema.TypeInt,
	Optional:    true,
	Default:     4,
	Description: "The number of minutes to wait before sending an alert",
},

If i try terraform apply once more:

Terraform will perform the following actions:

  # statuscake_uptime_check.test["Test"] will be updated in-place
  ~ resource "statuscake_uptime_check" "test" {
        id             = "1234"
        name           = "Test"
        tags           = []
      ~ trigger_rate   = 4 -> 0
        # (5 unchanged attributes hidden)

      ~ http_check {
          ~ status_codes     = [
              - "204",
              - "205",
              - "206",
              - "303",
              - "400",
              - "401",
              - "403",
              - "404",
              - "405",
              - "406",
              - "408",
              - "410",
              - "413",
              - "429",
              - "444",
              - "494",
              - "495",
              - "496",
              - "499",
              - "500",
              - "501",
              - "502",
              - "503",
              - "504",
              - "505",
              - "506",
              - "507",
              - "508",
              - "509",
              - "510",
              - "511",
              - "520",
              - "521",
              - "522",
              - "523",
              - "524",
              - "598",
              - "599",
            ]
            # (7 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

It's expected behavior as result:

#terraform show
statuscake_uptime_check.test["Test"]:
resource "statuscake_uptime_check" "test" {
    check_interval = 60
    confirmation   = 2
    contact_groups = []
    id             = "1234"
    locations      = []
    name           = "Test"
    paused         = false
    tags           = []
    trigger_rate   = 0

    http_check {
        enable_cookies   = false
        follow_redirects = true
        request_headers  = {}
        request_method   = "HTTP"
        request_payload  = {}
        status_codes     = []
        timeout          = 10
        validate_ssl     = true
    }

    monitored_resource {
        address = "https://google.com"
    }
}

Status_codes have a similar problem for this example.

'cannot unmarshal string into Go struct field' when creating tests

Terraform Version

Terraform v0.11.13
+ provider.statuscake v0.2.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "statuscake_test" "example_test" {
  website_name = "example.com"
  website_url  = "example.com"
  test_type    = "HTTP"
  contact_id   = 146126
}

Debug Output

https://gist.github.com/tdmalone/85778595e2b6159b669214448f459562

Expected Behavior

  • Resource is created
  • Resource is added to state
  • Terraform returns success

Actual Behavior

  • Resource is created
  • Resource is not added to state (confirmed by Terraform still wanting to create it on subsequent runs)
  • Terraform returns * statuscake_test.example_test: Error creating StatusCake Test: json: cannot unmarshal string into Go struct field updateResponse.InsertID of type int

Steps to Reproduce

  1. Add above HCL to configuration
  2. Run terraform apply and type 'yes' when prompted
  3. Observe error; check app.statuscake.com to confirm that resource has created; run terraform apply again to observe Terraform wanting to create the test again

Important Factoids

I'm not sure what caused this behaviour - I have been creating tests semi-regularly for some time, and first encountered this issue today. I probably last successfully did this 1-2 weeks ago so it's possible something has changed (in the StatusCake API?) in that time.

StatusCake state inconsistency

Ay,

Terraform Version

Terraform v0.12.28

  • provider.statuscake v1.0.0

Affected Resource(s)

  • statuscake_test.http_test

Terraform Configuration Files

See https://gist.github.com/KrustyHack/4c6a7793b03b8c65bdf269e5bcf0d131

Debug Output

All elements are here : https://gist.github.com/KrustyHack/4c6a7793b03b8c65bdf269e5bcf0d131

See terraform apply #1 and terraform apply #2 for Terraform apply output.

merged.tfvars #1 are variables used for terraform apply #1 and merged.tfvars #2 are variables used for terraform apply #2 (we deleted one check in it)

Expected Behavior

If I delete an http check all the checks order must not be broken. Here it seems that StatusCake is going mad and can't handle properly a check deletion.

Actual Behavior

If I delete one of my check in my checks array (see merged.tfvars in gist) all the order is disrupted and it's not good because we can lost healthchecks history if we apply the plan.

Steps to Reproduce

  1. terraform apply with merged.tfvars #1
  2. terraform apply with merged.tfvars #2 : we deleted one check from the array

Statuscake test resource sets Alert Trigger Rate and Confirmation Servers To Use to zero

This issue was originally opened by @parabolic as hashicorp/terraform#10289. It was migrated here as part of the provider split. The original body of the issue is below.


Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.7.11

Affected Resource(s)

Please list the resources as a list, for example:

  • statuscake_test

Terraform Configuration Files

resource "statuscake_test" "ping" {
  website_name = "${var.website_name}"
  website_url  = "${var.website_url}"
  test_type    = "${var.test_type}"
  check_rate   = "${var.check_rate}"
}

Debug Output

None

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

Status cake test should have been created with Alert Trigger Rate and Confirmation Servers To Use with a non zero value

Actual Behavior

Alert Trigger Rate and Confirmation Servers To Use are both set to zero
image

Steps to Reproduce

  1. terraform apply

Important Factoids

None

References

None

Tests are being created with empty 'Alert Status Code' value rather than using the api default values

Terraform Version

0.10.7

Affected Resource(s)

  • statuscake_test

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

variable "status_cake_username" {}
variable "status_cake_api_key" {}

provider "statuscake" {
  username = "${var.status_cake_username}"
  apikey   = "${var.status_cake_api_key}"
}

resource "statuscake_test" "my_test" {
  website_name  = "My test"
  website_url   = "https://www.google.com"
  check_rate    = 300
  test_type     = "HTTP"
  paused        = false
  confirmations = 2
}

Debug Output

https://gist.github.com/strebor1982/714b15b086c135ad712258acc6225229

Panic Output

N/A

Expected Behavior

The default behaviour when creating a status cake test is to create a test with the default Alert Status Codes. This is confirmed by running a basic request on the status cake api

curl -X PUT \
  https://app.statuscake.com/API/Tests/Update \
  -H 'api: {apikey}' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'postman-token: 4a8656cc-61a2-af32-a79c-614293ee38fd' \
  -H 'username: {username}' \
  -d 'WebsiteName=MySite&WebsiteURL=http%3A%2F%2Fwww.google.com&CheckRate=300'

This will create a test with the default status codes - https://gist.github.com/strebor1982/8db9f314f32ea355075ab815e267845f

Actual Behavior

Tests are now being created without any Alert status codes

I have noticed that there was a commit on the status cake client library used by the status cake provider which I think has broken this - DreamItGetIT/statuscake@63610f9

As the statuscake_test has no way of actually setting the status codes via a variable there is no way to correct this behaviour

Steps to Reproduce

  1. terraform apply
  2. Login to status cake and go to the newly created test
  3. Click edit test and scroll down to the 'Alert Status Codes' field. Field is empty

Important Factoids

N/A

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

error updating statuscake user agent

Terraform Version

Terraform v0.11.14 and v0.12.21

  • provider.statuscake v1.0.0

Affected Resource(s)

  • statuscake_test

Terraform Configuration Files

resource "statuscake_test" "test" {
...
  user_agent = "test123"
}

Debug Output

https://gist.github.com/tjend/b200a20038091df631c1e7c76070cc99

Expected Behavior

User agent should be updated within statuscake.

Actual Behavior

An error occurs("No data has been updated (is any data different?)"), statuscake is not updated, but the tfstate file is updated as if it worked.

Steps to Reproduce

  1. terraform apply

Important Factoids

When not using a custom user agent, no error occurs. The api documentation for statuscake, https://www.statuscake.com/api/Tests/Updating%20Inserting%20and%20Deleting%20Tests.md, currently doesn't mention the user agent. However testing with curl works as expected, "curl -H "API: [key]" -H "Username: [user]" -d "TestID=5421105&UserAgent=test123" -X PUT https://app.statuscake.com/API/Tests/Update".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.