From b056a9cf6e7d1fac2da04988aba6fc524b9f7a65 Mon Sep 17 00:00:00 2001
From: Roman <37997220+RomanMytsko@users.noreply.github.com>
Date: Mon, 12 Aug 2024 08:47:19 +0300
Subject: [PATCH] SCALRCORE-31428 [TF-PROVIDER] API > Sunset of old webhooks
API (#332)
* SCALRCORE-31428 remove data.scalr_endpoint and scalr_endpoint
* SCALRCORE-31428 update
* SCALRCORE-31428 update
* SCALRCORE-31428 update
* SCALRCORE-31428 fix lint
* SCALRCORE-31428 fix lint
* SCALRCORE-31428 fix test
* SCALRCORE-31428 fix test
* SCALRCORE-3142 update changelog
* SCALRCORE-31428 update changelog
* SCALRCORE-31428 update changelog
* Update CHANGELOG.md
Co-authored-by: Petro Protsakh
* SCALRCORE-31428 CR fixes.
* SCALRCORE-31428 CR fixes.
* SCALRCORE-31428 make url required
* SCALRCORE-31428 update client
---------
Co-authored-by: Petro Protsakh
---
CHANGELOG.md | 14 ++
docs/data-sources/endpoint.md | 44 ----
docs/data-sources/environment.md | 2 +-
docs/data-sources/environments.md | 2 +-
docs/data-sources/event_bridge_integration.md | 2 +-
docs/data-sources/iam_team.md | 2 +-
docs/data-sources/iam_user.md | 2 +-
docs/data-sources/module_version.md | 2 +-
docs/data-sources/policy_group.md | 2 +-
docs/data-sources/provider_configuration.md | 2 +-
docs/data-sources/provider_configurations.md | 2 +-
docs/data-sources/role.md | 2 +-
docs/data-sources/service_account.md | 2 +-
docs/data-sources/tag.md | 2 +-
docs/data-sources/variable.md | 2 +-
docs/data-sources/variables.md | 2 +-
docs/data-sources/vcs_provider.md | 2 +-
docs/data-sources/webhook.md | 5 +-
docs/data-sources/workspace.md | 2 +-
docs/data-sources/workspace_ids.md | 2 +-
docs/data-sources/workspaces.md | 2 +-
docs/resources/endpoint.md | 69 ------
docs/resources/environment.md | 2 +-
docs/resources/event_bridge_integration.md | 2 +-
docs/resources/iam_team.md | 2 +-
docs/resources/module.md | 2 +-
docs/resources/policy_group.md | 2 +-
docs/resources/policy_group_linkage.md | 2 +-
docs/resources/provider_configuration.md | 2 +-
.../provider_configuration_default.md | 2 +-
docs/resources/role.md | 2 +-
docs/resources/run_schedule_rule.md | 2 +-
docs/resources/run_trigger.md | 2 +-
docs/resources/service_account.md | 2 +-
docs/resources/service_account_token.md | 2 +-
docs/resources/slack_integration.md | 2 +-
docs/resources/tag.md | 2 +-
docs/resources/variable.md | 2 +-
docs/resources/vcs_provider.md | 2 +-
docs/resources/webhook.md | 9 +-
docs/resources/workspace.md | 2 +-
docs/resources/workspace_run_schedule.md | 2 +-
.../scalr_endpoint/data-source.tf | 9 -
go.mod | 2 +-
go.sum | 4 +-
scalr/data_source_scalr_endpoint.go | 128 ----------
scalr/data_source_scalr_endpoint_test.go | 188 --------------
scalr/data_source_scalr_webhook.go | 81 ++----
scalr/data_source_scalr_webhook_test.go | 154 +-----------
scalr/helpers.go | 41 ----
scalr/provider.go | 2 -
scalr/resource_scalr_endpoint.go | 190 --------------
scalr/resource_scalr_endpoint_migrate.go | 56 -----
scalr/resource_scalr_endpoint_migrate_test.go | 24 --
scalr/resource_scalr_endpoint_test.go | 113 ---------
scalr/resource_scalr_webhook.go | 231 +-----------------
scalr/resource_scalr_webhook_test.go | 78 +-----
templates/data-sources/endpoint.md.tmpl | 20 --
templates/resources/endpoint.md.tmpl | 35 ---
59 files changed, 105 insertions(+), 1466 deletions(-)
delete mode 100644 docs/data-sources/endpoint.md
delete mode 100644 docs/resources/endpoint.md
delete mode 100644 examples/data-sources/scalr_endpoint/data-source.tf
delete mode 100644 scalr/data_source_scalr_endpoint.go
delete mode 100644 scalr/data_source_scalr_endpoint_test.go
delete mode 100644 scalr/resource_scalr_endpoint.go
delete mode 100644 scalr/resource_scalr_endpoint_migrate.go
delete mode 100644 scalr/resource_scalr_endpoint_migrate_test.go
delete mode 100644 scalr/resource_scalr_endpoint_test.go
delete mode 100644 templates/data-sources/endpoint.md.tmpl
delete mode 100644 templates/resources/endpoint.md.tmpl
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0657a6c2..44ccb4af 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Removed
+- `data.scalr_endpoint`: removed data source ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `scalr_endpoint`: removed resource ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `scalr_webhook`: removed attribute `endpoint_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `scalr_webhook`: removed attribute `environment_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `scalr_webhook`: removed attribute `workspace_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `data.scalr_webhook`: removed attribute `endpoint_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `data.scalr_webhook`: removed attribute `environment_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `data.scalr_webhook`: removed attribute `workspace_id` ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+
+### Changed
+- `scalr_webhook`: `account_id` attribute became required ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+- `scalr_webhook`: `url` attribute became required ([#332](https://github.com/Scalr/terraform-provider-scalr/pull/332))
+
## [1.13.0] - 2024-08-02
### Added
diff --git a/docs/data-sources/endpoint.md b/docs/data-sources/endpoint.md
deleted file mode 100644
index a832af1e..00000000
--- a/docs/data-sources/endpoint.md
+++ /dev/null
@@ -1,44 +0,0 @@
----
-title: "scalr_endpoint"
-categorySlug: "scalr-terraform-provider"
-slug: "provider_datasource_scalr_endpoint"
-parentDocSlug: "provider_datasources"
-hidden: false
-order: 5
----
-## Data Source: scalr_endpoint
-
-Retrieves the details of a webhook endpoint.
-
-!> **Warning** This datasource is deprecated and will be removed in the next major version.
-
-## Example Usage
-
-```terraform
-data "scalr_endpoint" "example1" {
- id = "ep-xxxxxxxxxx"
- account_id = "acc-xxxxxxxxxx"
-}
-
-data "scalr_endpoint" "example2" {
- name = "endpoint_name"
- account_id = "acc-xxxxxxxxxx"
-}
-```
-
-
-## Schema
-
-### Optional
-
-- `account_id` (String) ID of the account, in the format `acc-`.
-- `id` (String) The endpoint ID, in the format `ep-`.
-- `name` (String) Name of the endpoint.
-
-### Read-Only
-
-- `environment_id` (String) ID of the environment, in the format `env-`.
-- `max_attempts` (Number) Max delivery attempts of the payload.
-- `secret_key` (String, Sensitive) Secret key to sign the webhook payload.
-- `timeout` (Number) Endpoint timeout (in seconds).
-- `url` (String) Endpoint URL.
diff --git a/docs/data-sources/environment.md b/docs/data-sources/environment.md
index 30fdac2b..cac0664a 100644
--- a/docs/data-sources/environment.md
+++ b/docs/data-sources/environment.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_environment"
parentDocSlug: "provider_datasources"
hidden: false
-order: 6
+order: 5
---
## Data Source: scalr_environment
diff --git a/docs/data-sources/environments.md b/docs/data-sources/environments.md
index 616b9ba3..c82ff055 100644
--- a/docs/data-sources/environments.md
+++ b/docs/data-sources/environments.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_environments"
parentDocSlug: "provider_datasources"
hidden: false
-order: 7
+order: 6
---
## Data Source: scalr_environments
diff --git a/docs/data-sources/event_bridge_integration.md b/docs/data-sources/event_bridge_integration.md
index 2bfb4bf3..fb1dd63c 100644
--- a/docs/data-sources/event_bridge_integration.md
+++ b/docs/data-sources/event_bridge_integration.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_event_bridge_integration"
parentDocSlug: "provider_datasources"
hidden: false
-order: 8
+order: 7
---
## Data Source: scalr_event_bridge_integration
diff --git a/docs/data-sources/iam_team.md b/docs/data-sources/iam_team.md
index 5b302182..e88c2c77 100644
--- a/docs/data-sources/iam_team.md
+++ b/docs/data-sources/iam_team.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_iam_team"
parentDocSlug: "provider_datasources"
hidden: false
-order: 9
+order: 8
---
## Data Source: scalr_iam_team
diff --git a/docs/data-sources/iam_user.md b/docs/data-sources/iam_user.md
index 50350234..42f4fbcc 100644
--- a/docs/data-sources/iam_user.md
+++ b/docs/data-sources/iam_user.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_iam_user"
parentDocSlug: "provider_datasources"
hidden: false
-order: 10
+order: 9
---
## Data Source: scalr_iam_user
diff --git a/docs/data-sources/module_version.md b/docs/data-sources/module_version.md
index 1f92cac3..275f9ef8 100644
--- a/docs/data-sources/module_version.md
+++ b/docs/data-sources/module_version.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_module_version"
parentDocSlug: "provider_datasources"
hidden: false
-order: 11
+order: 10
---
## Data Source: scalr_module_version
diff --git a/docs/data-sources/policy_group.md b/docs/data-sources/policy_group.md
index 081e7f0f..99f10c05 100644
--- a/docs/data-sources/policy_group.md
+++ b/docs/data-sources/policy_group.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_policy_group"
parentDocSlug: "provider_datasources"
hidden: false
-order: 12
+order: 11
---
## Data Source: scalr_policy_group
diff --git a/docs/data-sources/provider_configuration.md b/docs/data-sources/provider_configuration.md
index 43469cb6..04a65d12 100644
--- a/docs/data-sources/provider_configuration.md
+++ b/docs/data-sources/provider_configuration.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_provider_configuration"
parentDocSlug: "provider_datasources"
hidden: false
-order: 13
+order: 12
---
## Data Source: scalr_provider_configuration
diff --git a/docs/data-sources/provider_configurations.md b/docs/data-sources/provider_configurations.md
index 9ca23589..dadddc87 100644
--- a/docs/data-sources/provider_configurations.md
+++ b/docs/data-sources/provider_configurations.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_provider_configurations"
parentDocSlug: "provider_datasources"
hidden: false
-order: 14
+order: 13
---
## Data Source: scalr_provider_configurations
diff --git a/docs/data-sources/role.md b/docs/data-sources/role.md
index 1ce984f3..df7cb203 100644
--- a/docs/data-sources/role.md
+++ b/docs/data-sources/role.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_role"
parentDocSlug: "provider_datasources"
hidden: false
-order: 15
+order: 14
---
## Data Source: scalr_role
diff --git a/docs/data-sources/service_account.md b/docs/data-sources/service_account.md
index 8b6818af..5e0d2b35 100644
--- a/docs/data-sources/service_account.md
+++ b/docs/data-sources/service_account.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_service_account"
parentDocSlug: "provider_datasources"
hidden: false
-order: 16
+order: 15
---
## Data Source: scalr_service_account
diff --git a/docs/data-sources/tag.md b/docs/data-sources/tag.md
index 0699fe48..2bc93986 100644
--- a/docs/data-sources/tag.md
+++ b/docs/data-sources/tag.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_tag"
parentDocSlug: "provider_datasources"
hidden: false
-order: 17
+order: 16
---
## Data Source: scalr_tag
diff --git a/docs/data-sources/variable.md b/docs/data-sources/variable.md
index 7a294674..09d058cc 100644
--- a/docs/data-sources/variable.md
+++ b/docs/data-sources/variable.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_variable"
parentDocSlug: "provider_datasources"
hidden: false
-order: 18
+order: 17
---
## Data Source: scalr_variable
diff --git a/docs/data-sources/variables.md b/docs/data-sources/variables.md
index ca77cd95..dcb6b490 100644
--- a/docs/data-sources/variables.md
+++ b/docs/data-sources/variables.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_variables"
parentDocSlug: "provider_datasources"
hidden: false
-order: 19
+order: 18
---
## Data Source: scalr_variables
diff --git a/docs/data-sources/vcs_provider.md b/docs/data-sources/vcs_provider.md
index ec54d8e0..e27e5112 100644
--- a/docs/data-sources/vcs_provider.md
+++ b/docs/data-sources/vcs_provider.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_vcs_provider"
parentDocSlug: "provider_datasources"
hidden: false
-order: 20
+order: 19
---
## Data Source: scalr_vcs_provider
diff --git a/docs/data-sources/webhook.md b/docs/data-sources/webhook.md
index aa3df8ba..b9d46f58 100644
--- a/docs/data-sources/webhook.md
+++ b/docs/data-sources/webhook.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_webhook"
parentDocSlug: "provider_datasources"
hidden: false
-order: 21
+order: 20
---
## Data Source: scalr_webhook
@@ -36,8 +36,6 @@ data "scalr_webhook" "example2" {
### Read-Only
- `enabled` (Boolean) Boolean indicates if the webhook is enabled.
-- `endpoint_id` (String, Deprecated) ID of the endpoint, in the format `ep-`.
-- `environment_id` (String, Deprecated) ID of the environment, in the format `env-`.
- `environments` (Set of String) The list of environment identifiers that the webhook is shared to, or `["*"]` if shared with all environments.
- `events` (List of String) List of event IDs.
- `header` (Set of Object) Additional headers to set in the webhook request. (see [below for nested schema](#nestedatt--header))
@@ -46,7 +44,6 @@ data "scalr_webhook" "example2" {
- `secret_key` (String, Sensitive, Deprecated) Secret key to sign the webhook payload.
- `timeout` (Number) Endpoint timeout (in seconds).
- `url` (String) Endpoint URL.
-- `workspace_id` (String, Deprecated) ID of the workspace, in the format `ws-`.
### Nested Schema for `header`
diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md
index d62372d3..a7db42de 100644
--- a/docs/data-sources/workspace.md
+++ b/docs/data-sources/workspace.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_workspace"
parentDocSlug: "provider_datasources"
hidden: false
-order: 22
+order: 21
---
## Data Source: scalr_workspace
diff --git a/docs/data-sources/workspace_ids.md b/docs/data-sources/workspace_ids.md
index 9e550d77..028121d9 100644
--- a/docs/data-sources/workspace_ids.md
+++ b/docs/data-sources/workspace_ids.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_workspace_ids"
parentDocSlug: "provider_datasources"
hidden: false
-order: 23
+order: 22
---
## Data Source: scalr_workspace_ids
diff --git a/docs/data-sources/workspaces.md b/docs/data-sources/workspaces.md
index b3b2877b..b1383ccb 100644
--- a/docs/data-sources/workspaces.md
+++ b/docs/data-sources/workspaces.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_datasource_scalr_workspaces"
parentDocSlug: "provider_datasources"
hidden: false
-order: 24
+order: 23
---
## Data Source: scalr_workspaces
diff --git a/docs/resources/endpoint.md b/docs/resources/endpoint.md
deleted file mode 100644
index 49d9a1e5..00000000
--- a/docs/resources/endpoint.md
+++ /dev/null
@@ -1,69 +0,0 @@
----
-title: "scalr_endpoint"
-categorySlug: "scalr-terraform-provider"
-slug: "provider_resource_scalr_endpoint"
-parentDocSlug: "provider_resources"
-hidden: false
-order: 5
----
-## Resource: scalr_endpoint
-
-Manage the state of endpoints in Scalr. Create, update and destroy.
-
-!> **Warning** This resource is deprecated and will be removed in the next major version.
-
-## Example Usage
-
-```terraform
-resource "scalr_endpoint" "example" {
- name = "my-endpoint-name"
- secret_key = "my-secret-key"
- timeout = 15
- max_attempts = 3
- url = "https://my-endpoint.url"
- environment_id = "env-xxxxxxxxxx"
-}
-```
-
-
-## Schema
-
-### Required
-
-- `environment_id` (String) ID of the environment, in the format `env-`.
-- `name` (String) Name of the endpoint.
-- `url` (String) Endpoint URL.
-
-### Optional
-
-- `max_attempts` (Number) Max delivery attempts.
-- `secret_key` (String, Sensitive) Secret key to sign payload.
-- `timeout` (Number) Endpoint timeout (in sec).
-
-### Read-Only
-
-- `id` (String) The ID of this resource.
-
-## Useful snippets
-
-The secret key can be generated using the `random_string` resource.
-
-```terraform
-resource "random_string" "r" {
- length = 16
-}
-
-resource "scalr_endpoint" "example" {
- # ...
- secret_key = random_string.r.result
- # ...
-}
-```
-
-## Import
-
-Import is supported using the following syntax:
-
-```shell
-terraform import scalr_endpoint.example ep-xxxxxxxxxx
-```
diff --git a/docs/resources/environment.md b/docs/resources/environment.md
index 94acc390..385ddbdb 100644
--- a/docs/resources/environment.md
+++ b/docs/resources/environment.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_environment"
parentDocSlug: "provider_resources"
hidden: false
-order: 6
+order: 5
---
## Resource: scalr_environment
diff --git a/docs/resources/event_bridge_integration.md b/docs/resources/event_bridge_integration.md
index 2f683376..20b8a91b 100644
--- a/docs/resources/event_bridge_integration.md
+++ b/docs/resources/event_bridge_integration.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_event_bridge_integration"
parentDocSlug: "provider_resources"
hidden: false
-order: 7
+order: 6
---
## Resource: scalr_event_bridge_integration
diff --git a/docs/resources/iam_team.md b/docs/resources/iam_team.md
index fc853907..ee844269 100644
--- a/docs/resources/iam_team.md
+++ b/docs/resources/iam_team.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_iam_team"
parentDocSlug: "provider_resources"
hidden: false
-order: 8
+order: 7
---
## Resource: scalr_iam_team
diff --git a/docs/resources/module.md b/docs/resources/module.md
index 68c18737..865437b4 100644
--- a/docs/resources/module.md
+++ b/docs/resources/module.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_module"
parentDocSlug: "provider_resources"
hidden: false
-order: 9
+order: 8
---
## Resource: scalr_module
diff --git a/docs/resources/policy_group.md b/docs/resources/policy_group.md
index 01d54c06..3cd9bb85 100644
--- a/docs/resources/policy_group.md
+++ b/docs/resources/policy_group.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_policy_group"
parentDocSlug: "provider_resources"
hidden: false
-order: 10
+order: 9
---
## Resource: scalr_policy_group
diff --git a/docs/resources/policy_group_linkage.md b/docs/resources/policy_group_linkage.md
index c8a9e6b5..107e0614 100644
--- a/docs/resources/policy_group_linkage.md
+++ b/docs/resources/policy_group_linkage.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_policy_group_linkage"
parentDocSlug: "provider_resources"
hidden: false
-order: 11
+order: 10
---
## Resource: scalr_policy_group_linkage
diff --git a/docs/resources/provider_configuration.md b/docs/resources/provider_configuration.md
index ab3bbd1a..713b1158 100644
--- a/docs/resources/provider_configuration.md
+++ b/docs/resources/provider_configuration.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_provider_configuration"
parentDocSlug: "provider_resources"
hidden: false
-order: 12
+order: 11
---
## Resource: scalr_provider_configuration
diff --git a/docs/resources/provider_configuration_default.md b/docs/resources/provider_configuration_default.md
index becc96da..823d4943 100644
--- a/docs/resources/provider_configuration_default.md
+++ b/docs/resources/provider_configuration_default.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_provider_configuration_default"
parentDocSlug: "provider_resources"
hidden: false
-order: 13
+order: 12
---
## Resource: scalr_provider_configuration_default
diff --git a/docs/resources/role.md b/docs/resources/role.md
index e4da6486..4eb2322b 100644
--- a/docs/resources/role.md
+++ b/docs/resources/role.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_role"
parentDocSlug: "provider_resources"
hidden: false
-order: 14
+order: 13
---
## Resource: scalr_role
diff --git a/docs/resources/run_schedule_rule.md b/docs/resources/run_schedule_rule.md
index 6b4a58ab..1b482910 100644
--- a/docs/resources/run_schedule_rule.md
+++ b/docs/resources/run_schedule_rule.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_run_schedule_rule"
parentDocSlug: "provider_resources"
hidden: false
-order: 15
+order: 14
---
## Resource: scalr_run_schedule_rule
diff --git a/docs/resources/run_trigger.md b/docs/resources/run_trigger.md
index 760b145d..ee9873be 100644
--- a/docs/resources/run_trigger.md
+++ b/docs/resources/run_trigger.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_run_trigger"
parentDocSlug: "provider_resources"
hidden: false
-order: 16
+order: 15
---
## Resource: scalr_run_trigger
diff --git a/docs/resources/service_account.md b/docs/resources/service_account.md
index e48db231..a9fa7463 100644
--- a/docs/resources/service_account.md
+++ b/docs/resources/service_account.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_service_account"
parentDocSlug: "provider_resources"
hidden: false
-order: 17
+order: 16
---
## Resource: scalr_service_account
diff --git a/docs/resources/service_account_token.md b/docs/resources/service_account_token.md
index d752faca..84a4ce67 100644
--- a/docs/resources/service_account_token.md
+++ b/docs/resources/service_account_token.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_service_account_token"
parentDocSlug: "provider_resources"
hidden: false
-order: 18
+order: 17
---
## Resource: scalr_service_account_token
diff --git a/docs/resources/slack_integration.md b/docs/resources/slack_integration.md
index 86ac408d..a894ad63 100644
--- a/docs/resources/slack_integration.md
+++ b/docs/resources/slack_integration.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_slack_integration"
parentDocSlug: "provider_resources"
hidden: false
-order: 19
+order: 18
---
## Resource: scalr_slack_integration
diff --git a/docs/resources/tag.md b/docs/resources/tag.md
index d941eef8..0eaee52d 100644
--- a/docs/resources/tag.md
+++ b/docs/resources/tag.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_tag"
parentDocSlug: "provider_resources"
hidden: false
-order: 20
+order: 19
---
## Resource: scalr_tag
diff --git a/docs/resources/variable.md b/docs/resources/variable.md
index 1f15addd..15b1ea36 100644
--- a/docs/resources/variable.md
+++ b/docs/resources/variable.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_variable"
parentDocSlug: "provider_resources"
hidden: false
-order: 21
+order: 20
---
## Resource: scalr_variable
diff --git a/docs/resources/vcs_provider.md b/docs/resources/vcs_provider.md
index c6149776..d5348383 100644
--- a/docs/resources/vcs_provider.md
+++ b/docs/resources/vcs_provider.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_vcs_provider"
parentDocSlug: "provider_resources"
hidden: false
-order: 22
+order: 21
---
## Resource: scalr_vcs_provider
diff --git a/docs/resources/webhook.md b/docs/resources/webhook.md
index 54a53828..ce5b2c30 100644
--- a/docs/resources/webhook.md
+++ b/docs/resources/webhook.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_webhook"
parentDocSlug: "provider_resources"
hidden: false
-order: 23
+order: 22
---
## Resource: scalr_webhook
@@ -48,22 +48,19 @@ resource "scalr_webhook" "example2" {
### Required
+- `account_id` (String) ID of the account, in the format `acc-`.
- `events` (List of String) List of event IDs.
- `name` (String) Name of the webhook.
+- `url` (String) Endpoint URL. Required if `endpoint_id` is not set.
### Optional
-- `account_id` (String) ID of the account, in the format `acc-`.
- `enabled` (Boolean) Set (true/false) to enable/disable the webhook.
-- `endpoint_id` (String, Deprecated) ID of the endpoint, in the format `ep-`.
-- `environment_id` (String, Deprecated) ID of the environment, in the format `env-`.
- `environments` (Set of String) The list of environment identifiers that the webhook is shared to. Use `["*"]` to share with all environments.
- `header` (Block Set) Additional headers to set in the webhook request. (see [below for nested schema](#nestedblock--header))
- `max_attempts` (Number) Max delivery attempts of the payload.
- `secret_key` (String, Sensitive) Secret key to sign the webhook payload.
- `timeout` (Number) Endpoint timeout (in seconds).
-- `url` (String) Endpoint URL. Required if `endpoint_id` is not set.
-- `workspace_id` (String, Deprecated) ID of the workspace, in the format `ws-`.
### Read-Only
diff --git a/docs/resources/workspace.md b/docs/resources/workspace.md
index 46909abf..3adbc451 100644
--- a/docs/resources/workspace.md
+++ b/docs/resources/workspace.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_workspace"
parentDocSlug: "provider_resources"
hidden: false
-order: 24
+order: 23
---
## Resource: scalr_workspace
diff --git a/docs/resources/workspace_run_schedule.md b/docs/resources/workspace_run_schedule.md
index a55235d2..0f3c3209 100644
--- a/docs/resources/workspace_run_schedule.md
+++ b/docs/resources/workspace_run_schedule.md
@@ -4,7 +4,7 @@ categorySlug: "scalr-terraform-provider"
slug: "provider_resource_scalr_workspace_run_schedule"
parentDocSlug: "provider_resources"
hidden: false
-order: 25
+order: 24
---
## Resource: scalr_workspace_run_schedule
diff --git a/examples/data-sources/scalr_endpoint/data-source.tf b/examples/data-sources/scalr_endpoint/data-source.tf
deleted file mode 100644
index 0acbb099..00000000
--- a/examples/data-sources/scalr_endpoint/data-source.tf
+++ /dev/null
@@ -1,9 +0,0 @@
-data "scalr_endpoint" "example1" {
- id = "ep-xxxxxxxxxx"
- account_id = "acc-xxxxxxxxxx"
-}
-
-data "scalr_endpoint" "example2" {
- name = "endpoint_name"
- account_id = "acc-xxxxxxxxxx"
-}
diff --git a/go.mod b/go.mod
index 033132a5..afa65693 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
- github.com/scalr/go-scalr v0.0.0-20240723075138-bc76a6e7c4ca
+ github.com/scalr/go-scalr v0.0.0-20240808050842-7408799db900
)
require (
diff --git a/go.sum b/go.sum
index 20181b72..32f0e083 100644
--- a/go.sum
+++ b/go.sum
@@ -260,8 +260,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
-github.com/scalr/go-scalr v0.0.0-20240723075138-bc76a6e7c4ca h1:rdkzR4I7PG3KHfl/CSAOGu2FTSZW3CeCQR6XV+gFTms=
-github.com/scalr/go-scalr v0.0.0-20240723075138-bc76a6e7c4ca/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
+github.com/scalr/go-scalr v0.0.0-20240808050842-7408799db900 h1:dGqAjO+ZBmUD3GZBq0YLD6cy/Vmx1rzj2l1FWLpT02g=
+github.com/scalr/go-scalr v0.0.0-20240808050842-7408799db900/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
diff --git a/scalr/data_source_scalr_endpoint.go b/scalr/data_source_scalr_endpoint.go
deleted file mode 100644
index 176f6c31..00000000
--- a/scalr/data_source_scalr_endpoint.go
+++ /dev/null
@@ -1,128 +0,0 @@
-package scalr
-
-import (
- "context"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
- "log"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/scalr/go-scalr"
-)
-
-func dataSourceScalrEndpoint() *schema.Resource {
- return &schema.Resource{
- Description: "Retrieves the details of a webhook endpoint.",
- DeprecationMessage: "Datasource `scalr_endpoint` is deprecated, the endpoint information" +
- " is included in the `scalr_webhook` resource.",
-
- ReadContext: dataSourceScalrEndpointRead,
-
- Schema: map[string]*schema.Schema{
-
- "id": {
- Description: "The endpoint ID, in the format `ep-`.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- ValidateFunc: validation.StringIsNotWhiteSpace,
- AtLeastOneOf: []string{"name"},
- },
-
- "name": {
- Description: "Name of the endpoint.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- ValidateFunc: validation.StringIsNotWhiteSpace,
- },
-
- "max_attempts": {
- Description: "Max delivery attempts of the payload.",
- Type: schema.TypeInt,
- Computed: true,
- },
-
- "secret_key": {
- Description: "Secret key to sign the webhook payload.",
- Type: schema.TypeString,
- Computed: true,
- Sensitive: true,
- },
-
- "url": {
- Description: "Endpoint URL.",
- Type: schema.TypeString,
- Computed: true,
- },
-
- "timeout": {
- Description: "Endpoint timeout (in seconds).",
- Type: schema.TypeInt,
- Computed: true,
- },
-
- "account_id": {
- Description: "ID of the account, in the format `acc-`.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- DefaultFunc: scalrAccountIDDefaultFunc,
- },
-
- "environment_id": {
- Description: "ID of the environment, in the format `env-`.",
- Type: schema.TypeString,
- Computed: true,
- },
- },
- }
-}
-
-func dataSourceScalrEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- scalrClient := meta.(*scalr.Client)
-
- // Get IDs
- endpointID := d.Get("id").(string)
- endpointName := d.Get("name").(string)
- accountID := d.Get("account_id").(string)
-
- var endpoint *scalr.Endpoint
- var err error
-
- log.Printf("[DEBUG] Read endpoint with ID '%s' and name '%s'", endpointID, endpointName)
- if endpointID != "" {
- endpoint, err = scalrClient.Endpoints.Read(ctx, endpointID)
- if err != nil {
- return diag.Errorf("Error retrieving endpoint: %v", err)
- }
- if endpointName != "" && endpointName != endpoint.Name {
- return diag.Errorf("Could not find endpoint with ID '%s' and name '%s'", endpointID, endpointName)
- }
- } else {
- options := GetEndpointByNameOptions{
- Name: &endpointName,
- Account: &accountID,
- }
- endpoint, err = GetEndpointByName(ctx, options, scalrClient)
- if err != nil {
- return diag.Errorf("Error retrieving endpoint: %v", err)
- }
- if endpointID != "" && endpointID != endpoint.ID {
- return diag.Errorf("Could not find endpoint with ID '%s' and name '%s'", endpointID, endpointName)
- }
- }
-
- // Update the config.
- _ = d.Set("name", endpoint.Name)
- _ = d.Set("timeout", endpoint.Timeout)
- _ = d.Set("max_attempts", endpoint.MaxAttempts)
- _ = d.Set("secret_key", endpoint.SecretKey)
- _ = d.Set("url", endpoint.Url)
- if endpoint.Environment != nil {
- _ = d.Set("environment_id", endpoint.Environment.ID)
- }
- d.SetId(endpoint.ID)
-
- return nil
-}
diff --git a/scalr/data_source_scalr_endpoint_test.go b/scalr/data_source_scalr_endpoint_test.go
deleted file mode 100644
index a6e277bb..00000000
--- a/scalr/data_source_scalr_endpoint_test.go
+++ /dev/null
@@ -1,188 +0,0 @@
-package scalr
-
-import (
- "fmt"
- "math/rand"
- "regexp"
- "strconv"
- "testing"
- "time"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
-)
-
-func TestAccEndpointDataSource_basic(t *testing.T) {
- rand.Seed(time.Now().UnixNano())
- rInt := rand.Intn(100)
-
- cutRInt := strconv.Itoa(rInt)[:len(strconv.Itoa(rInt))-1]
-
- resource.Test(t, resource.TestCase{
- PreCheck: func() { testAccPreCheck(t) },
- ProviderFactories: testAccProviderFactories,
- Steps: []resource.TestStep{
- {
- Config: `data scalr_endpoint test {}`,
- ExpectError: regexp.MustCompile("\"id\": one of `id,name` must be specified"),
- PlanOnly: true,
- },
- {
- Config: `data scalr_endpoint test {id = ""}`,
- ExpectError: regexp.MustCompile("expected \"id\" to not be an empty string or whitespace"),
- PlanOnly: true,
- },
- {
- Config: `data scalr_endpoint test {name = ""}`,
- ExpectError: regexp.MustCompile("expected \"name\" to not be an empty string or whitespace"),
- PlanOnly: true,
- },
- {
- Config: testAccEndpointDataSourceAccessByIDConfig(rInt),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "secret_key"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "max_attempts", "3"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "url", "https://example.com/endpoint"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "environment_id"),
- ),
- },
- {
- Config: testAccEndpointDataSourceAccessByNameConfig(rInt),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "secret_key"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "max_attempts", "3"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "url", "https://example.com/endpoint"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "environment_id"),
- ),
- },
- {
- Config: testAccEndpointDataSourceAccessByIDAndNameConfig(rInt),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "secret_key"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "max_attempts", "3"),
- resource.TestCheckResourceAttr(
- "data.scalr_endpoint.test", "url", "https://example.com/endpoint"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_endpoint.test", "environment_id"),
- ),
- },
- {
- Config: testAccEndpointDataSourceNotFoundAlmostTheSameNameConfig(rInt, cutRInt),
- ExpectError: regexp.MustCompile(fmt.Sprintf("Endpoint with name 'test endpoint-%s' not found", cutRInt)),
- PlanOnly: true,
- },
- {
- Config: testAccEndpointDataSourceNotFoundByNameConfig(),
- ExpectError: regexp.MustCompile("Endpoint with name 'endpoint-foo-bar-baz' not found or user unauthorized"),
- PlanOnly: true,
- },
- },
- })
-}
-
-func testAccEndpointDataSourceAccessByIDConfig(rInt int) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- url = "https://example.com/endpoint"
- environment_id = scalr_environment.test.id
-}
-
-data scalr_endpoint test {
- id = scalr_endpoint.test.id
-}`, rInt, defaultAccount)
-}
-
-func testAccEndpointDataSourceAccessByNameConfig(rInt int) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- url = "https://example.com/endpoint"
- environment_id = scalr_environment.test.id
-}
-
-data scalr_endpoint test {
- name = scalr_endpoint.test.name
- account_id = scalr_environment.test.account_id
-}`, rInt, defaultAccount)
-}
-
-func testAccEndpointDataSourceAccessByIDAndNameConfig(rInt int) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- url = "https://example.com/endpoint"
- environment_id = scalr_environment.test.id
-}
-
-data scalr_endpoint test {
- id = scalr_endpoint.test.id
- name = scalr_endpoint.test.name
- account_id = scalr_environment.test.account_id
-}`, rInt, defaultAccount)
-}
-
-func testAccEndpointDataSourceNotFoundByNameConfig() string {
- return `
-data scalr_endpoint test {
- name = "endpoint-foo-bar-baz"
-}`
-}
-
-func testAccEndpointDataSourceNotFoundAlmostTheSameNameConfig(rInt int, cutRInt string) string {
- return fmt.Sprintf(`
-resource "scalr_environment" "test" {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- url = "https://example.com/endpoint"
- environment_id = scalr_environment.test.id
-}
-
-data scalr_endpoint test {
- name = "test endpoint-%[3]s"
-}`, rInt, defaultAccount, cutRInt)
-}
diff --git a/scalr/data_source_scalr_webhook.go b/scalr/data_source_scalr_webhook.go
index 9b450393..72fc7e25 100644
--- a/scalr/data_source_scalr_webhook.go
+++ b/scalr/data_source_scalr_webhook.go
@@ -53,14 +53,6 @@ func dataSourceScalrWebhook() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
- "endpoint_id": {
- Description: "ID of the endpoint, in the format `ep-`.",
- Type: schema.TypeString,
- Computed: true,
- Deprecated: "Attribute `endpoint_id` is deprecated, the endpoint information" +
- " is included in the `scalr_webhook` resource.",
- },
-
"account_id": {
Description: "ID of the account, in the format `acc-`.",
Type: schema.TypeString,
@@ -69,22 +61,6 @@ func dataSourceScalrWebhook() *schema.Resource {
DefaultFunc: scalrAccountIDDefaultFunc,
},
- "environment_id": {
- Description: "ID of the environment, in the format `env-`.",
- Type: schema.TypeString,
- Computed: true,
- Deprecated: "The attribute `environment_id` is deprecated. The webhook is created on the" +
- " account level and the environments to which it is exposed" +
- " are controlled by the `environments` attribute.",
- },
-
- "workspace_id": {
- Description: "ID of the workspace, in the format `ws-`.",
- Type: schema.TypeString,
- Computed: true,
- Deprecated: "The attribute `workspace_id` is deprecated.",
- },
-
"url": {
Description: "Endpoint URL.",
Type: schema.TypeString,
@@ -150,18 +126,18 @@ func dataSourceScalrWebhookRead(ctx context.Context, d *schema.ResourceData, met
webhookName := d.Get("name").(string)
accountID := d.Get("account_id").(string)
- var newWebhook *scalr.WebhookIntegration
+ var webhook *scalr.WebhookIntegration
var err error
log.Printf("[DEBUG] Read configuration of webhook with ID '%s' and name '%s'", webhookID, webhookName)
// First read from new API by ID or search by name, as the new API
// works both with old-style and new-style webhooks
if webhookID != "" {
- newWebhook, err = scalrClient.WebhookIntegrations.Read(ctx, webhookID)
+ webhook, err = scalrClient.WebhookIntegrations.Read(ctx, webhookID)
if err != nil {
return diag.Errorf("Error retrieving webhook: %v", err)
}
- if webhookName != "" && webhookName != newWebhook.Name {
+ if webhookName != "" && webhookName != webhook.Name {
return diag.Errorf("Could not find webhook with ID '%s' and name '%s'", webhookID, webhookName)
}
} else {
@@ -169,42 +145,36 @@ func dataSourceScalrWebhookRead(ctx context.Context, d *schema.ResourceData, met
Name: &webhookName,
Account: &accountID,
}
- newWebhook, err = GetWebhookByName(ctx, options, scalrClient)
+ webhook, err = GetWebhookByName(ctx, options, scalrClient)
if err != nil {
return diag.Errorf("Error retrieving webhook: %v", err)
}
- if webhookID != "" && webhookID != newWebhook.ID {
+ if webhookID != "" && webhookID != webhook.ID {
return diag.Errorf("Could not find webhook with ID '%s' and name '%s'", webhookID, webhookName)
}
}
- // Having the webhook found, read from old API then
- // to populate deprecated fields available only in old API
- oldWebhook, err := scalrClient.Webhooks.Read(ctx, newWebhook.ID)
- if err != nil {
- return diag.Errorf("Error retrieving webhook: %v", err)
- }
// Update the config.
- _ = d.Set("name", newWebhook.Name)
- _ = d.Set("account_id", newWebhook.Account.ID)
- _ = d.Set("enabled", newWebhook.Enabled)
- _ = d.Set("last_triggered_at", newWebhook.LastTriggeredAt)
- _ = d.Set("url", newWebhook.Url)
- _ = d.Set("secret_key", newWebhook.SecretKey)
- _ = d.Set("timeout", newWebhook.Timeout)
- _ = d.Set("max_attempts", newWebhook.MaxAttempts)
+ _ = d.Set("name", webhook.Name)
+ _ = d.Set("account_id", webhook.Account.ID)
+ _ = d.Set("enabled", webhook.Enabled)
+ _ = d.Set("last_triggered_at", webhook.LastTriggeredAt)
+ _ = d.Set("url", webhook.Url)
+ _ = d.Set("secret_key", webhook.SecretKey)
+ _ = d.Set("timeout", webhook.Timeout)
+ _ = d.Set("max_attempts", webhook.MaxAttempts)
events := make([]string, 0)
- if newWebhook.Events != nil {
- for _, event := range newWebhook.Events {
+ if webhook.Events != nil {
+ for _, event := range webhook.Events {
events = append(events, event.ID)
}
}
_ = d.Set("events", events)
headers := make([]map[string]interface{}, 0)
- if newWebhook.Headers != nil {
- for _, header := range newWebhook.Headers {
+ if webhook.Headers != nil {
+ for _, header := range webhook.Headers {
headers = append(headers, map[string]interface{}{
"name": header.Name,
"value": header.Value,
@@ -213,28 +183,17 @@ func dataSourceScalrWebhookRead(ctx context.Context, d *schema.ResourceData, met
}
_ = d.Set("header", headers)
- if newWebhook.IsShared {
+ if webhook.IsShared {
_ = d.Set("environments", []string{"*"})
} else {
environmentIDs := make([]string, 0)
- for _, environment := range newWebhook.Environments {
+ for _, environment := range webhook.Environments {
environmentIDs = append(environmentIDs, environment.ID)
}
_ = d.Set("environments", environmentIDs)
}
- // Add deprecated attributes from old-style webhook
- if oldWebhook.Workspace != nil {
- _ = d.Set("workspace_id", oldWebhook.Workspace.ID)
- }
- if oldWebhook.Environment != nil {
- _ = d.Set("environment_id", oldWebhook.Environment.ID)
- }
- if oldWebhook.Endpoint != nil {
- _ = d.Set("endpoint_id", oldWebhook.Endpoint.ID)
- }
-
- d.SetId(newWebhook.ID)
+ d.SetId(webhook.ID)
return nil
}
diff --git a/scalr/data_source_scalr_webhook_test.go b/scalr/data_source_scalr_webhook_test.go
index ce8b1caa..f1787e4a 100644
--- a/scalr/data_source_scalr_webhook_test.go
+++ b/scalr/data_source_scalr_webhook_test.go
@@ -36,38 +36,6 @@ func TestAccWebhookDataSource_basic(t *testing.T) {
ExpectError: regexp.MustCompile("expected \"name\" to not be an empty string or whitespace"),
PlanOnly: true,
},
- {
- Config: testAccOldWebhookDataSourceConfig(rInt),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d", rInt)),
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "enabled", "false"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
- // Attributes from related endpoint
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "url", "https://example.com/webhook"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "secret_key"),
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "max_attempts", "3"),
- // New attributes
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "header.#", "0"),
- resource.TestCheckResourceAttr(
- "data.scalr_webhook.test", "environments.#", "1"),
- resource.TestCheckResourceAttrPair(
- "data.scalr_webhook.test",
- "environments.0",
- "scalr_environment.test",
- "id"),
- ),
- },
{
Config: testAccWebhookDataSourceConfig(rInt),
Check: resource.ComposeAggregateTestCheckFunc(
@@ -92,10 +60,6 @@ func TestAccWebhookDataSource_basic(t *testing.T) {
"environments.0",
"scalr_environment.test-new",
"id"),
- // Deprecated attributes
- resource.TestCheckNoResourceAttr("data.scalr_webhook.test-new", "endpoint_id"),
- resource.TestCheckNoResourceAttr("data.scalr_webhook.test-new", "workspace_id"),
- resource.TestCheckNoResourceAttr("data.scalr_webhook.test-new", "environment_id"),
),
},
{
@@ -105,10 +69,6 @@ func TestAccWebhookDataSource_basic(t *testing.T) {
"data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_webhook.test", "enabled", "false"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
),
},
{
@@ -118,10 +78,6 @@ func TestAccWebhookDataSource_basic(t *testing.T) {
"data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_webhook.test", "enabled", "false"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
),
},
{
@@ -138,39 +94,6 @@ func TestAccWebhookDataSource_basic(t *testing.T) {
})
}
-func testAccOldWebhookDataSourceConfig(rInt int) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test-endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_webhook test {
- enabled = false
- name = "webhook-test-%[1]d"
- events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
-}
-
-data scalr_webhook test {
- id = scalr_webhook.test.id
-}`, rInt, defaultAccount)
-}
-
func testAccWebhookDataSourceConfig(rInt int) string {
return fmt.Sprintf(`
resource scalr_environment test-new {
@@ -203,71 +126,35 @@ data scalr_webhook test-new {
func testAccWebhookDataSourceAccessByNameConfig(rInt int) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = false
name = "webhook-test-%[1]d"
events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
+ url = "https://example.com/webhook"
+ account_id = "%s"
}
data scalr_webhook test {
name = scalr_webhook.test.name
- account_id = scalr_environment.test.account_id
-}`, rInt, defaultAccount)
+ account_id = "%s"
+}`, rInt, defaultAccount, defaultAccount)
}
func testAccWebhookDataSourceAccessByIDAndNameConfig(rInt int) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = false
name = "webhook-test-%[1]d"
events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
+ url = "https://example.com/webhook"
+ account_id = "%s"
}
data scalr_webhook test {
id = scalr_webhook.test.id
name = scalr_webhook.test.name
- account_id = scalr_environment.test.account_id
-}`, rInt, defaultAccount)
+ account_id = "%s"
+}`, rInt, defaultAccount, defaultAccount)
}
func testAccWebhookDataSourceNotFoundByNameConfig() string {
@@ -280,33 +167,16 @@ data scalr_webhook test {
func testAccWebhookDataSourceNotFoundAlmostTheSameNameConfig(rInt int, cutRInt string) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = false
name = "test webhook-%[1]d"
events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
+ url = "https://example.com/webhook"
+ account_id = "%s"
}
data scalr_webhook test {
name = "test webhook-%[3]s"
- account_id = scalr_environment.test.account_id
-}`, rInt, defaultAccount, cutRInt)
+ account_id = "%s"
+}`, rInt, defaultAccount, cutRInt, defaultAccount)
}
diff --git a/scalr/helpers.go b/scalr/helpers.go
index 128023dc..e05a0eba 100644
--- a/scalr/helpers.go
+++ b/scalr/helpers.go
@@ -49,47 +49,6 @@ func GetEnvironmentByName(ctx context.Context, options GetEnvironmentByNameOptio
return envl.Items[0], nil
}
-type GetEndpointByNameOptions struct {
- Name *string
- Account *string
-}
-
-func GetEndpointByName(ctx context.Context, options GetEndpointByNameOptions, scalrClient *scalr.Client) (*scalr.Endpoint, error) {
- listOptions := scalr.EndpointListOptions{
- Name: options.Name,
- Account: options.Account,
- }
- endpl, err := scalrClient.Endpoints.List(ctx, listOptions)
- if err != nil {
- return nil, fmt.Errorf("Error retrieving endpoints: %v", err)
- }
-
- if len(endpl.Items) == 0 {
- return nil, fmt.Errorf("Endpoint with name '%s' not found or user unauthorized", *options.Name)
- }
-
- var matchedEndpoints []*scalr.Endpoint
-
- // filter in endpoint search endpoints that contains query string, this is why we need to do exact match on our side.
- for _, endp := range endpl.Items {
- if endp.Name == *options.Name {
- matchedEndpoints = append(matchedEndpoints, endp)
- }
- }
-
- switch numberOfMatch := len(matchedEndpoints); {
- case numberOfMatch == 0:
- return nil, fmt.Errorf("Endpoint with name '%s' not found", *options.Name)
-
- case numberOfMatch > 1:
- return nil, fmt.Errorf("Found more than one endpoint with name: %s, specify 'account_id' to search only for endpoints in specific account", *options.Name)
-
- default:
- return matchedEndpoints[0], nil
-
- }
-}
-
type GetWebhookByNameOptions struct {
Name *string
Account *string
diff --git a/scalr/provider.go b/scalr/provider.go
index ef0ffa06..86321559 100644
--- a/scalr/provider.go
+++ b/scalr/provider.go
@@ -68,7 +68,6 @@ func Provider() *schema.Provider {
"scalr_agent_pool": dataSourceScalrAgentPool(),
"scalr_current_account": dataSourceScalrCurrentAccount(),
"scalr_current_run": dataSourceScalrCurrentRun(),
- "scalr_endpoint": dataSourceScalrEndpoint(),
"scalr_environment": dataSourceScalrEnvironment(),
"scalr_environments": dataSourceScalrEnvironments(),
"scalr_iam_team": dataSourceScalrIamTeam(),
@@ -95,7 +94,6 @@ func Provider() *schema.Provider {
"scalr_account_allowed_ips": resourceScalrAccountAllowedIps(),
"scalr_agent_pool": resourceScalrAgentPool(),
"scalr_agent_pool_token": resourceScalrAgentPoolToken(),
- "scalr_endpoint": resourceScalrEndpoint(),
"scalr_environment": resourceScalrEnvironment(),
"scalr_iam_team": resourceScalrIamTeam(),
"scalr_module": resourceScalrModule(),
diff --git a/scalr/resource_scalr_endpoint.go b/scalr/resource_scalr_endpoint.go
deleted file mode 100644
index b18bf73a..00000000
--- a/scalr/resource_scalr_endpoint.go
+++ /dev/null
@@ -1,190 +0,0 @@
-package scalr
-
-import (
- "context"
- "errors"
- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
- "log"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
- "github.com/scalr/go-scalr"
-)
-
-func resourceScalrEndpoint() *schema.Resource {
- return &schema.Resource{
- Description: "Manage the state of endpoints in Scalr. Create, update and destroy.",
- DeprecationMessage: "Resource `scalr_endpoint` is deprecated, the endpoint information" +
- " is included in the `scalr_webhook` resource.",
- CreateContext: resourceScalrEndpointCreate,
- ReadContext: resourceScalrEndpointRead,
- UpdateContext: resourceScalrEndpointUpdate,
- DeleteContext: resourceScalrEndpointDelete,
- Importer: &schema.ResourceImporter{
- StateContext: schema.ImportStatePassthroughContext,
- },
- SchemaVersion: 1,
- StateUpgraders: []schema.StateUpgrader{
- {
- Type: resourceScalrEndpointResourceV0().CoreConfigSchema().ImpliedType(),
- Upgrade: resourceScalrEndpointStateUpgradeV0,
- Version: 0,
- },
- },
-
- Schema: map[string]*schema.Schema{
- "name": {
- Description: "Name of the endpoint.",
- Type: schema.TypeString,
- Required: true,
- },
-
- "max_attempts": {
- Description: "Max delivery attempts.",
- Type: schema.TypeInt,
- Optional: true,
- Computed: true,
- },
-
- "url": {
- Description: "Endpoint URL.",
- Type: schema.TypeString,
- Required: true,
- },
-
- "secret_key": {
- Description: "Secret key to sign payload.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- Sensitive: true,
- },
-
- "timeout": {
- Description: "Endpoint timeout (in sec).",
- Type: schema.TypeInt,
- Optional: true,
- Computed: true,
- },
-
- "environment_id": {
- Description: "ID of the environment, in the format `env-`.",
- Type: schema.TypeString,
- Required: true,
- },
- },
- }
-}
-
-func resourceScalrEndpointCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- scalrClient := meta.(*scalr.Client)
-
- // Get attributes.
- name := d.Get("name").(string)
-
- // Get scope
- environmentID := d.Get("environment_id").(string)
- // we don't create endpoints on workspace scope for now
- _, environment, account, err := getResourceScope(ctx, scalrClient, "", environmentID)
- if err != nil {
- return diag.FromErr(err)
- }
-
- // Create a new options struct.
- options := scalr.EndpointCreateOptions{
- Name: scalr.String(name),
- Url: scalr.String(d.Get("url").(string)),
- Environment: environment,
- Account: account,
- }
- if secretKey, ok := d.GetOk("secret_key"); ok {
- options.SecretKey = scalr.String(secretKey.(string))
- }
-
- if maxAttempts, ok := d.GetOk("max_attempts"); ok {
- options.MaxAttempts = scalr.Int(maxAttempts.(int))
- }
-
- if timeout, ok := d.GetOk("timeout"); ok {
- options.Timeout = scalr.Int(timeout.(int))
- }
-
- log.Printf("[DEBUG] Create endpoint: %s", name)
- endpoint, err := scalrClient.Endpoints.Create(ctx, options)
- if err != nil {
- return diag.Errorf("Error creating endpoint %s: %v", name, err)
- }
-
- d.SetId(endpoint.ID)
-
- return resourceScalrEndpointRead(ctx, d, meta)
-}
-
-func resourceScalrEndpointRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- scalrClient := meta.(*scalr.Client)
- endpointID := d.Id()
-
- log.Printf("[DEBUG] Read endpoint with ID: %s", endpointID)
- endpoint, err := scalrClient.Endpoints.Read(ctx, endpointID)
- if err != nil {
- if errors.Is(err, scalr.ErrResourceNotFound) {
- d.SetId("")
- return nil
- }
- return diag.Errorf("Error retrieving endpoint: %v", err)
- }
-
- // Update the config.
- _ = d.Set("name", endpoint.Name)
- _ = d.Set("timeout", endpoint.Timeout)
- _ = d.Set("max_attempts", endpoint.MaxAttempts)
- _ = d.Set("secret_key", endpoint.SecretKey)
- if endpoint.Environment != nil {
- _ = d.Set("environment_id", endpoint.Environment.ID)
- }
- d.SetId(endpointID)
-
- return nil
-}
-
-func resourceScalrEndpointUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- scalrClient := meta.(*scalr.Client)
-
- var err error
- // Create a new options struct.
- options := scalr.EndpointUpdateOptions{
- Name: scalr.String(d.Get("name").(string)),
- Url: scalr.String(d.Get("url").(string)),
- SecretKey: scalr.String(d.Get("secret_key").(string)),
- }
-
- if maxAttempts, ok := d.GetOk("max_attempts"); ok {
- options.MaxAttempts = scalr.Int(maxAttempts.(int))
- }
-
- if timeout, ok := d.GetOk("timeout"); ok {
- options.Timeout = scalr.Int(timeout.(int))
- }
-
- log.Printf("[DEBUG] Update endpoint: %s", d.Id())
- _, err = scalrClient.Endpoints.Update(ctx, d.Id(), options)
- if err != nil {
- return diag.Errorf("Error updating endpoint %s: %v", d.Id(), err)
- }
-
- return resourceScalrEndpointRead(ctx, d, meta)
-}
-
-func resourceScalrEndpointDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
- scalrClient := meta.(*scalr.Client)
-
- log.Printf("[DEBUG] Delete endpoint: %s", d.Id())
- err := scalrClient.Endpoints.Delete(ctx, d.Id())
- if err != nil {
- if errors.Is(err, scalr.ErrResourceNotFound) {
- return nil
- }
- return diag.Errorf("Error deleting endpoint%s: %v", d.Id(), err)
- }
-
- return nil
-}
diff --git a/scalr/resource_scalr_endpoint_migrate.go b/scalr/resource_scalr_endpoint_migrate.go
deleted file mode 100644
index af19bfc5..00000000
--- a/scalr/resource_scalr_endpoint_migrate.go
+++ /dev/null
@@ -1,56 +0,0 @@
-package scalr
-
-import (
- "context"
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
-)
-
-func resourceScalrEndpointResourceV0() *schema.Resource {
- return &schema.Resource{
- Schema: map[string]*schema.Schema{
- "name": {
- Type: schema.TypeString,
- Required: true,
- },
-
- "http_method": {
- Type: schema.TypeString,
- Optional: true,
- },
-
- "max_attempts": {
- Type: schema.TypeInt,
- Optional: true,
- Computed: true,
- },
-
- "url": {
- Type: schema.TypeString,
- Required: true,
- },
-
- "secret_key": {
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- Sensitive: true,
- },
-
- "timeout": {
- Type: schema.TypeInt,
- Optional: true,
- Computed: true,
- },
-
- "environment_id": {
- Type: schema.TypeString,
- Required: true,
- },
- },
- }
-}
-
-func resourceScalrEndpointStateUpgradeV0(_ context.Context, rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) {
- delete(rawState, "http_method")
- return rawState, nil
-}
diff --git a/scalr/resource_scalr_endpoint_migrate_test.go b/scalr/resource_scalr_endpoint_migrate_test.go
deleted file mode 100644
index 550641d2..00000000
--- a/scalr/resource_scalr_endpoint_migrate_test.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package scalr
-
-import (
- "testing"
-)
-
-func testResourceScalrEndpointStateDataV0() map[string]interface{} {
- return map[string]interface{}{
- "id": "endpoint-id",
- "http_method": "POST",
- }
-}
-
-func testResourceScalrEndpointStateDataV1() map[string]interface{} {
- v0 := testResourceScalrEndpointStateDataV0()
- delete(v0, "http_method")
- return v0
-}
-
-func TestResourceScalrEndpointStateUpgradeV0(t *testing.T) {
- expected := testResourceScalrEndpointStateDataV1()
- actual, err := resourceScalrEndpointStateUpgradeV0(ctx, testResourceScalrEndpointStateDataV0(), nil)
- assertCorrectState(t, err, actual, expected)
-}
diff --git a/scalr/resource_scalr_endpoint_test.go b/scalr/resource_scalr_endpoint_test.go
deleted file mode 100644
index eda5d1e1..00000000
--- a/scalr/resource_scalr_endpoint_test.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package scalr
-
-import (
- "fmt"
- "testing"
-
- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
-)
-
-func TestAccEndpoint_basic(t *testing.T) {
- rInt := GetRandomInteger()
- secretKey := "strong_key_with_UPPERCASE_letter_at_least_1_number"
-
- resource.Test(t, resource.TestCase{
- PreCheck: func() { testAccPreCheck(t) },
- ProviderFactories: testAccProviderFactories,
- Steps: []resource.TestStep{
- {
- Config: testAccEndpointConfig(rInt, secretKey),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "secret_key", secretKey),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "max_attempts", "3"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "url", "https://example.com/endpoint"),
- resource.TestCheckResourceAttrSet(
- "scalr_endpoint.test", "environment_id"),
- ),
- },
- },
- })
-}
-
-func TestAccEndpoint_update(t *testing.T) {
- rInt := GetRandomInteger()
- secretKey := "strong_key_with_UPPERCASE_letter_at_least_1_number"
-
- resource.Test(t, resource.TestCase{
- PreCheck: func() { testAccPreCheck(t) },
- ProviderFactories: testAccProviderFactories,
- Steps: []resource.TestStep{
- {
- Config: testAccEndpointConfig(rInt, secretKey),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "secret_key", secretKey),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "timeout", "15"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "max_attempts", "3"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "url", "https://example.com/endpoint"),
- resource.TestCheckResourceAttrSet(
- "scalr_endpoint.test", "environment_id"),
- ),
- },
- {
- Config: testAccEndpointConfigUpdate(rInt, secretKey),
- Check: resource.ComposeAggregateTestCheckFunc(
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "timeout", "10"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "max_attempts", "5"),
- resource.TestCheckResourceAttr(
- "scalr_endpoint.test", "url", "https://example.com/endpoint-updated"),
- ),
- },
- },
- })
-}
-
-func testAccEndpointConfig(rInt int, secretKey string) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%[2]s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- secret_key = "%[3]s"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/endpoint"
- environment_id = scalr_environment.test.id
-}`, rInt, defaultAccount, secretKey)
-}
-
-func testAccEndpointConfigUpdate(rInt int, secretKey string) string {
- return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%[2]s"
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- secret_key = "%[3]s"
- timeout = 10
- max_attempts = 5
- url = "https://example.com/endpoint-updated"
- environment_id = scalr_environment.test.id
-}`, rInt, defaultAccount, secretKey)
-}
diff --git a/scalr/resource_scalr_webhook.go b/scalr/resource_scalr_webhook.go
index 44ce50b2..eaeda746 100644
--- a/scalr/resource_scalr_webhook.go
+++ b/scalr/resource_scalr_webhook.go
@@ -22,7 +22,6 @@ func resourceScalrWebhook() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
- CustomizeDiff: forceRecreateIf(),
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
@@ -68,30 +67,11 @@ func resourceScalrWebhook() *schema.Resource {
MinItems: 1,
},
- "endpoint_id": {
- Description: "ID of the endpoint, in the format `ep-`.",
- Type: schema.TypeString,
- Optional: true,
- Deprecated: "Attribute `endpoint_id` is deprecated, please set the endpoint information" +
- " in the webhook itself.",
- // If `endpoint_id` is set in configuration, we consider this an old-style webhook,
- // therefore using old API to create it.
- // That's why it conflicts with the fields that are only in new-style webhooks, so
- // user has two distinct sets of arguments for old and new webhooks.
- // One of `endpoint_id` or `url` must be set, and this defines which style will be chosen.
- ConflictsWith: []string{
- "url", "secret_key", "timeout", "max_attempts", "header", "environments", "account_id",
- },
- AtLeastOneOf: []string{"url"},
- },
-
"url": {
Description: "Endpoint URL. Required if `endpoint_id` is not set.",
Type: schema.TypeString,
- Optional: true,
- Computed: true,
+ Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace),
- ConflictsWith: []string{"endpoint_id", "workspace_id", "environment_id"},
},
"secret_key": {
@@ -143,30 +123,10 @@ func resourceScalrWebhook() *schema.Resource {
"account_id": {
Description: "ID of the account, in the format `acc-`.",
Type: schema.TypeString,
- Optional: true,
- Computed: true,
- DefaultFunc: scalrAccountIDOptionalDefaultFunc,
+ Required: true,
ForceNew: true,
},
- "workspace_id": {
- Description: "ID of the workspace, in the format `ws-`.",
- Type: schema.TypeString,
- Optional: true,
- Deprecated: "The attribute `workspace_id` is deprecated.",
- },
-
- "environment_id": {
- Description: "ID of the environment, in the format `env-`.",
- Type: schema.TypeString,
- Optional: true,
- Computed: true,
- Deprecated: "The attribute `environment_id` is deprecated. The webhook is created on the" +
- " account level and the environments to which it is exposed" +
- " are controlled by the `environments` attribute.",
- ConflictsWith: []string{"environments"},
- },
-
"environments": {
Description: "The list of environment identifiers that the webhook is shared to. Use `[\"*\"]` to share with all environments.",
Type: schema.TypeSet,
@@ -178,57 +138,6 @@ func resourceScalrWebhook() *schema.Resource {
}
}
-func forceRecreateIf() schema.CustomizeDiffFunc {
- // Destroy and recreate a webhook when `endpoint_id` has changed from having a value to unset,
- // which means switching from old-style to new-style webhook - and vice versa,
- // so we don't mix both style.
- return func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
- oldId, newId := d.GetChange("endpoint_id")
- if (oldId.(string) == "") != (newId.(string) == "") {
- return d.ForceNew("endpoint_id")
- }
- return nil
- }
-}
-
-// remove after https://scalr-labs.atlassian.net/browse/SCALRCORE-16234
-func getResourceScope(ctx context.Context, scalrClient *scalr.Client, workspaceID string, environmentID string) (*scalr.Workspace, *scalr.Environment, *scalr.Account, error) {
-
- // Resource scope
- var workspace *scalr.Workspace
- var environment *scalr.Environment
- var account *scalr.Account
-
- // Get the workspace.
- if workspaceID != "" {
- var err error
- workspace, err = scalrClient.Workspaces.ReadByID(ctx, workspaceID)
- if err != nil {
- return nil, nil, nil, fmt.Errorf("Error retrieving workspace %s: %v", workspaceID, err)
- }
-
- if environmentID != "" && environmentID != workspace.Environment.ID {
- return nil, nil, nil, fmt.Errorf("Workspace %s does not belong to an environment %s", workspaceID, environmentID)
- }
-
- environmentID = workspace.Environment.ID
- }
-
- // Get the environment.
- if environmentID != "" {
- var err error
- environment, err = scalrClient.Environments.Read(ctx, environmentID)
- if err != nil {
- return nil, nil, nil, fmt.Errorf("Error retrieving environment %s: %v", environmentID, err)
- }
- account = environment.Account
- } else {
- return nil, nil, nil, fmt.Errorf("Missing workspace_id or environment_id")
- }
-
- return workspace, environment, account, nil
-}
-
func parseEventDefinitions(d *schema.ResourceData) ([]*scalr.EventDefinition, error) {
eventDefinitions := make([]*scalr.EventDefinition, 0)
@@ -259,55 +168,7 @@ func parseHeaders(d *schema.ResourceData) []*scalr.WebhookHeader {
return headerValues
}
-func createOldWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
- // Get attributes.
- name := d.Get("name").(string)
- endpointID := d.Get("endpoint_id").(string)
- workspaceID := d.Get("workspace_id").(string)
- environmentID := d.Get("environment_id").(string)
-
- workspace, environment, account, err := getResourceScope(ctx, scalrClient, workspaceID, environmentID)
- if err != nil {
- return err
- }
-
- eventDefinitions, err := parseEventDefinitions(d)
- if err != nil {
- return err
- }
-
- // Create a new options struct.
- options := scalr.WebhookCreateOptions{
- Name: scalr.String(name),
- Enabled: scalr.Bool(d.Get("enabled").(bool)),
- Events: eventDefinitions,
- Endpoint: &scalr.Endpoint{ID: endpointID},
- Workspace: workspace,
- Environment: environment,
- Account: account,
- }
-
- if workspaceID != "" {
- options.Workspace = &scalr.Workspace{ID: workspaceID}
- }
- if environmentID != "" {
- options.Environment = &scalr.Environment{ID: environmentID}
- }
- if environmentID != "" {
- options.Environment = &scalr.Environment{ID: environmentID}
- }
-
- log.Printf("[DEBUG] Create webhook: %s", name)
- webhook, err := scalrClient.Webhooks.Create(ctx, options)
- if err != nil {
- return fmt.Errorf("Error creating webhook %s: %v", name, err)
- }
-
- d.SetId(webhook.ID)
- return nil
-}
-
-func createNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
+func createWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
name := d.Get("name").(string)
accountId := d.Get("account_id").(string)
@@ -370,17 +231,8 @@ func createNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *
func resourceScalrWebhookCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
scalrClient := meta.(*scalr.Client)
- endpointID := d.Get("endpoint_id").(string)
-
- var err error
- // Here the old method is kept and is used to create old-style webhooks (with `endpoint_id` attribute set).
- // After deprecation period it should be easy to remove it completely.
- // Same for updating a webhook.
- if endpointID != "" {
- err = createOldWebhook(ctx, d, scalrClient)
- } else {
- err = createNewWebhook(ctx, d, scalrClient)
- }
+
+ err := createWebhook(ctx, d, scalrClient)
if err != nil {
return diag.FromErr(err)
}
@@ -388,37 +240,7 @@ func resourceScalrWebhookCreate(ctx context.Context, d *schema.ResourceData, met
return resourceScalrWebhookRead(ctx, d, meta)
}
-func readOldWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
- webhookID := d.Id()
-
- webhook, err := scalrClient.Webhooks.Read(ctx, webhookID)
- if err != nil {
- if errors.Is(err, scalr.ErrResourceNotFound) {
- return fmt.Errorf("Could not find webhook %s: %v", webhookID, err)
- }
- return fmt.Errorf("Error retrieving webhook: %v", err)
- }
-
- if webhook.Workspace != nil {
- _ = d.Set("workspace_id", webhook.Workspace.ID)
- } else {
- _ = d.Set("workspace_id", nil)
- }
- if webhook.Environment != nil {
- _ = d.Set("environment_id", webhook.Environment.ID)
- } else {
- _ = d.Set("environment_id", nil)
- }
- if webhook.Endpoint != nil {
- _ = d.Set("endpoint_id", webhook.Endpoint.ID)
- } else {
- _ = d.Set("endpoint_id", nil)
- }
-
- return nil
-}
-
-func readNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
+func readWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
webhookID := d.Id()
webhook, err := scalrClient.WebhookIntegrations.Read(ctx, webhookID)
@@ -473,43 +295,14 @@ func readNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *sc
func resourceScalrWebhookRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
scalrClient := meta.(*scalr.Client)
- // Reading the webhook differs from create or update methods.
- // We read from both old and new API and basically merge the fields from both resources,
- // therefore keeping deprecated attributes in place for now and extending with the new ones.
- if err := readOldWebhook(ctx, d, scalrClient); err != nil {
+ if err := readWebhook(ctx, d, scalrClient); err != nil {
return diag.FromErr(err)
}
- if err := readNewWebhook(ctx, d, scalrClient); err != nil {
- return diag.FromErr(err)
- }
-
- return nil
-}
-
-func updateOldWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
- eventDefinitions, err := parseEventDefinitions(d)
- if err != nil {
- return err
- }
-
- // Create a new options struct.
- options := scalr.WebhookUpdateOptions{
- Name: scalr.String(d.Get("name").(string)),
- Enabled: scalr.Bool(d.Get("enabled").(bool)),
- Events: eventDefinitions,
- Endpoint: &scalr.Endpoint{ID: d.Get("endpoint_id").(string)},
- }
-
- log.Printf("[DEBUG] Update webhook: %s", d.Id())
- _, err = scalrClient.Webhooks.Update(ctx, d.Id(), options)
- if err != nil {
- return fmt.Errorf("Error updating webhook %s: %v", d.Id(), err)
- }
return nil
}
-func updateNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
+func updateWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *scalr.Client) error {
options := scalr.WebhookIntegrationUpdateOptions{}
@@ -581,14 +374,8 @@ func updateNewWebhook(ctx context.Context, d *schema.ResourceData, scalrClient *
func resourceScalrWebhookUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
scalrClient := meta.(*scalr.Client)
- endpointID := d.Get("endpoint_id").(string)
- var err error
- if endpointID != "" {
- err = updateOldWebhook(ctx, d, scalrClient)
- } else {
- err = updateNewWebhook(ctx, d, scalrClient)
- }
+ err := updateWebhook(ctx, d, scalrClient)
if err != nil {
return diag.FromErr(err)
}
diff --git a/scalr/resource_scalr_webhook_test.go b/scalr/resource_scalr_webhook_test.go
index d00b290e..79cc76b2 100644
--- a/scalr/resource_scalr_webhook_test.go
+++ b/scalr/resource_scalr_webhook_test.go
@@ -22,10 +22,6 @@ func TestAccWebhook_basic(t *testing.T) {
"data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_webhook.test", "enabled", "false"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
),
},
},
@@ -51,10 +47,6 @@ func TestAccWebhook_update(t *testing.T) {
"data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_webhook.test", "enabled", "false"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
),
},
{
@@ -64,10 +56,6 @@ func TestAccWebhook_update(t *testing.T) {
"data.scalr_webhook.test", "name", fmt.Sprintf("webhook-test-%d-renamed", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_webhook.test", "enabled", "true"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "endpoint_id"),
- resource.TestCheckResourceAttrSet(
- "data.scalr_webhook.test", "workspace_id"),
),
},
},
@@ -76,30 +64,12 @@ func TestAccWebhook_update(t *testing.T) {
func testAccWebhookConfig(rInt int) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = false
name = "webhook-test-%[1]d"
events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
+ url = "https://example.com/webhook"
+ account_id = "%s"
}
data scalr_webhook test {
@@ -109,30 +79,12 @@ data scalr_webhook test {
func testAccWebhookConfigUpdate(rInt int) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = true
name = "webhook-test-%[1]d-renamed"
events = ["run:completed", "run:errored"]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
+ url = "https://example.com/webhook"
+ account_id = "%s"
}
data scalr_webhook test {
@@ -142,30 +94,12 @@ data scalr_webhook test {
func testAccWebhookConfigUpdateEmptyEvent(rInt int) string {
return fmt.Sprintf(`
-resource scalr_environment test {
- name = "test-env-%[1]d"
- account_id = "%s"
-}
-
-resource scalr_workspace test {
- name = "test-ws-%[1]d"
- environment_id = scalr_environment.test.id
-}
-
-resource scalr_endpoint test {
- name = "test endpoint-%[1]d"
- timeout = 15
- max_attempts = 3
- url = "https://example.com/webhook"
- environment_id = scalr_environment.test.id
-}
-
resource scalr_webhook test {
enabled = true
name = "webhook-test-%[1]d-renamed"
events = [""]
- endpoint_id = scalr_endpoint.test.id
- workspace_id = scalr_workspace.test.id
+ account_id = "%s"
+ url = "https://example.com/webhook"
}
data scalr_webhook test {
diff --git a/templates/data-sources/endpoint.md.tmpl b/templates/data-sources/endpoint.md.tmpl
deleted file mode 100644
index ca219072..00000000
--- a/templates/data-sources/endpoint.md.tmpl
+++ /dev/null
@@ -1,20 +0,0 @@
----
-title: "{{.Name}}"
-categorySlug: "scalr-terraform-provider"
-slug: "provider_datasource_{{.Name}}"
-parentDocSlug: "provider_datasources"
-hidden: false
----
-## {{.Type}}: {{.Name}}
-
-{{ .Description | trimspace }}
-
-!> **Warning** This datasource is deprecated and will be removed in the next major version.
-
-{{ if .HasExample -}}
-## Example Usage
-
-{{tffile .ExampleFile }}
-{{- end }}
-
-{{ .SchemaMarkdown | trimspace }}
diff --git a/templates/resources/endpoint.md.tmpl b/templates/resources/endpoint.md.tmpl
deleted file mode 100644
index 81362ed2..00000000
--- a/templates/resources/endpoint.md.tmpl
+++ /dev/null
@@ -1,35 +0,0 @@
----
-title: "{{.Name}}"
-categorySlug: "scalr-terraform-provider"
-slug: "provider_resource_{{.Name}}"
-parentDocSlug: "provider_resources"
-hidden: false
----
-## {{.Type}}: {{.Name}}
-
-{{ .Description | trimspace }}
-
-!> **Warning** This resource is deprecated and will be removed in the next major version.
-
-{{ if .HasExample -}}
-## Example Usage
-
-{{tffile .ExampleFile }}
-{{- end }}
-
-{{ .SchemaMarkdown | trimspace }}
-
-## Useful snippets
-
-The secret key can be generated using the `random_string` resource.
-
-{{tffile "examples/resources/scalr_endpoint/secret-key.tf" }}
-
-{{- if .HasImport }}
-
-## Import
-
-Import is supported using the following syntax:
-
-{{codefile "shell" .ImportFile}}
-{{- end }}