Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCALRCORE-17105: API > Publish Webhooks API into preview #40

Merged
merged 18 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- `scalr_workspace`: drop attribute `queue_all_runs`. ([#40](https://github.com/Scalr/terraform-provider-scalr/pull/40))
- `scalr_endpoint`: drop attribute `http_method`. ([#40](https://github.com/Scalr/terraform-provider-scalr/pull/40))

### Changed
- `scalr_webhook` attribute `enabled` is optional with default: `true`. ([#40](https://github.com/Scalr/terraform-provider-scalr/pull/40))
- `scalr_endpoint` attribute `secret_key` is optional and sensitive.

### Required

- scalr server >= `TODO`

## [1.0.0-rc9] - 2020-11-12

### Added
Expand Down Expand Up @@ -139,5 +152,3 @@ Requires Scalr 8.0.1-beta.20200625 at least
[1.0.0-rc1]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v1.0.0-rc1
[0.0.0-rc2]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v0.0.0-rc2
[0.0.0-rc1]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v0.0.0-rc1


1 change: 0 additions & 1 deletion docs/data-sources/scalr_workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ All arguments plus:
* `id` - The workspace's ID, in the format `ws-<RANDOM STRING>`.
* `auto_apply` - Boolean indicates if `terrafrom apply` will be automatically run when `terraform plan` ends without error.
* `operations` - Boolean indicates if the workspace is being used for remote execution.
* `queue_all_runs` - Boolean indicates if all runs should be queued.
* `terraform_version` - The version of Terraform used for this workspace.
* `working_directory` - A relative path that Terraform will execute within.
* `vcs_repo` - If workspace is linked to VCS repository this block shows the details, otherwise `{}`
Expand Down
1 change: 0 additions & 1 deletion docs/resources/scalr_workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ resource "scalr_workspace" "example" {
* `auto_apply` - (Optional) Set (true/false) to configure if `terraform apply` should automatically run when `terraform plan` ends without error. Default `false`.
* `operations` - (Optional) Set (true/false) to configure workspace remote execution. When `false` workspace is only used to store state. Default `true`.
Defaults to `true`.
* `queue_all_runs` - (Optional) Set (true/false) to configure queuing all runs. When false one manually triggered run is required. Default `true`.
* `terraform_version` - (Optional) The version of Terraform to use for this workspace. Defaults to the latest available version.
* `working_directory` - (Optional) A relative path that Terraform will be run in. Defaults to the root of the repository.
* `vcs_provider_id` - (Optional) ID of vcs provider - required if vcs-repo present and vice versa, in the format `vcs-<RANDOM STRING>`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/terraform v0.12.0
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/scalr/go-scalr v0.0.0-20201111140348-ebd319838485
github.com/scalr/go-scalr v0.0.0-20201130122810-adece0aed6c5
)

go 1.13
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ github.com/scalr/go-scalr v0.0.0-20201103121620-a2559f72dce3 h1:AphlnwcwesmV9+R0
github.com/scalr/go-scalr v0.0.0-20201103121620-a2559f72dce3/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/scalr/go-scalr v0.0.0-20201111140348-ebd319838485 h1:xAqLzCB2DonU9Mj+fwynXrU3eD71JaV/UJzy7KDQp+o=
github.com/scalr/go-scalr v0.0.0-20201111140348-ebd319838485/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/scalr/go-scalr v0.0.0-20201123154434-010b8a9036d4 h1:qlu6s/tlRykxPmDUe+MFSz6b3uU7MEqn8P2UxnQiJzo=
github.com/scalr/go-scalr v0.0.0-20201123154434-010b8a9036d4/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/scalr/go-scalr v0.0.0-20201123155550-dc0d6d650bff h1:cuJQsle+A87pxMpuAPCZQMZEigMSuMyr+r+xqoBT2zI=
github.com/scalr/go-scalr v0.0.0-20201123155550-dc0d6d650bff/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/scalr/go-scalr v0.0.0-20201126155347-818ff373bbf0 h1:Z/xTSKrY7iTE3X2d8Psf9x307fQzJ2yHfMbnbcvS8XE=
github.com/scalr/go-scalr v0.0.0-20201126155347-818ff373bbf0/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/scalr/go-scalr v0.0.0-20201130122810-adece0aed6c5 h1:bC65zxjhhl5O1w5+FmalXun+xyRcuUqKLvQy4yVbo8Q=
github.com/scalr/go-scalr v0.0.0-20201130122810-adece0aed6c5/go.mod h1:eEDwNsOdDKg5TJHljpJWfb4LhobfCkUHZo/uX/rPph8=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down
22 changes: 7 additions & 15 deletions scalr/client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ func newMockWorkspaces() *mockWorkspaces {
}
}

func (m *mockWorkspaces) List(ctx context.Context, environment string, options scalr.WorkspaceListOptions) (*scalr.WorkspaceList, error) {
func (m *mockWorkspaces) List(ctx context.Context, options scalr.WorkspaceListOptions) (*scalr.WorkspaceList, error) {
panic("not implemented")
}

func (m *mockWorkspaces) Create(ctx context.Context, environment string, options scalr.WorkspaceCreateOptions) (*scalr.Workspace, error) {
func (m *mockWorkspaces) Create(ctx context.Context, options scalr.WorkspaceCreateOptions) (*scalr.Workspace, error) {
ws := &scalr.Workspace{
ID: options.ID,
Name: *options.Name,
Organization: &scalr.Organization{
Name: environment,
Environment: &scalr.Environment{
ID: options.Environment.ID,
},
}

m.workspaceNames[workspaceNamesKey{environment, *options.Name}] = ws
m.workspaceNames[workspaceNamesKey{options.Environment.ID, *options.Name}] = ws

return ws, nil
}
Expand All @@ -51,19 +51,11 @@ func (m *mockWorkspaces) ReadByID(ctx context.Context, workspaceID string) (*sca
panic("not implemented")
}

func (m *mockWorkspaces) Update(ctx context.Context, environment string, workspace string, options scalr.WorkspaceUpdateOptions) (*scalr.Workspace, error) {
func (m *mockWorkspaces) Update(ctx context.Context, workspaceID string, options scalr.WorkspaceUpdateOptions) (*scalr.Workspace, error) {
panic("not implemented")
}

func (m *mockWorkspaces) UpdateByID(ctx context.Context, workspaceID string, options scalr.WorkspaceUpdateOptions) (*scalr.Workspace, error) {
panic("not implemented")
}

func (m *mockWorkspaces) Delete(ctx context.Context, environment string, workspace string) error {
panic("not implemented")
}

func (m *mockWorkspaces) DeleteByID(ctx context.Context, workspaceID string) error {
func (m *mockWorkspaces) Delete(ctx context.Context, workspaceID string) error {
panic("not implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_current_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func dataSourceScalrCurrentRunRead(d *schema.ResourceData, meta interface{}) err
d.Set("is_dry", run.Apply == nil)

d.Set("workspace_name", workspace.Name)
d.Set("environment_id", workspace.Organization.ID)
d.Set("environment_id", workspace.Environment.ID)

if workspace.VCSRepo != nil {
log.Printf("[DEBUG] Read vcs revision attributes of run: %s", runID)
Expand Down
12 changes: 3 additions & 9 deletions scalr/data_source_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@ func dataSourceScalrEndpoint() *schema.Resource {
Computed: true,
},

"http_method": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"max_attempts": {
Type: schema.TypeInt,
Optional: true,
},

"secret_key": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"url": {
Expand Down Expand Up @@ -78,7 +73,6 @@ func dataSourceScalrEndpointRead(d *schema.ResourceData, meta interface{}) error
d.Set("name", endpoint.Name)
d.Set("timeout", endpoint.Timeout)
d.Set("max_attempts", endpoint.MaxAttempts)
d.Set("http_method", endpoint.HTTPMethod)
d.Set("secret_key", endpoint.SecretKey)
d.Set("url", endpoint.Url)
if endpoint.Environment != nil {
Expand Down
5 changes: 2 additions & 3 deletions scalr/data_source_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func TestAccEndpointDataSource_basic(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(
"data.scalr_endpoint.test", "name", fmt.Sprintf("test endpoint-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_endpoint.test", "secret_key", "my-secret-key"),
resource.TestCheckResourceAttrSet(
"data.scalr_endpoint.test", "secret_key"),
resource.TestCheckResourceAttr(
"data.scalr_endpoint.test", "timeout", "15"),
resource.TestCheckResourceAttr(
Expand All @@ -46,7 +46,6 @@ resource scalr_environment test {

resource scalr_endpoint test {
name = "test endpoint-%[1]d"
secret_key = "my-secret-key"
timeout = 15
url = "https://example.com/endpoint"
environment_id = scalr_environment.test.id
Expand Down
2 changes: 0 additions & 2 deletions scalr/data_source_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ resource scalr_workspace test {

resource scalr_endpoint test {
name = "test endpoint-%[1]d"
http_method = "POST"
secret_key = "my-secret-key"
timeout = 15
max_attempts = 3
url = "https://example.com/webhook"
Expand Down
6 changes: 0 additions & 6 deletions scalr/data_source_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func dataSourceScalrWorkspace() *schema.Resource {
Computed: true,
},

"queue_all_runs": {
Type: schema.TypeBool,
Computed: true,
},

"terraform_version": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -113,7 +108,6 @@ func dataSourceScalrWorkspaceRead(d *schema.ResourceData, meta interface{}) erro
// Update the config.
d.Set("auto_apply", workspace.AutoApply)
d.Set("operations", workspace.Operations)
d.Set("queue_all_runs", workspace.QueueAllRuns)
d.Set("terraform_version", workspace.TerraformVersion)
d.Set("working_directory", workspace.WorkingDirectory)

Expand Down
4 changes: 2 additions & 2 deletions scalr/data_source_workspace_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func dataSourceScalrWorkspaceIDsRead(d *schema.ResourceData, meta interface{}) e
// Create a map to store workspace IDs
ids := make(map[string]string, len(names))

options := scalr.WorkspaceListOptions{}
options := scalr.WorkspaceListOptions{Environment: &environmentID}
for {
wl, err := scalrClient.Workspaces.List(ctx, environmentID, options)
wl, err := scalrClient.Workspaces.List(ctx, options)
if err != nil {
return fmt.Errorf("Error retrieving workspaces: %v", err)
}
Expand Down
3 changes: 0 additions & 3 deletions scalr/data_source_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func TestAccScalrWorkspaceDataSource_basic(t *testing.T) {
"data.scalr_workspace.test", "name", fmt.Sprintf("workspace-test-%d", rInt)),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "auto_apply", "true"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "queue_all_runs", "false"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "terraform_version", "0.12.19"),
resource.TestCheckResourceAttr(
Expand All @@ -51,7 +49,6 @@ resource scalr_workspace test {
name = "workspace-test-%[1]d"
environment_id = scalr_environment.test.id
auto_apply = true
queue_all_runs = false
terraform_version = "0.12.19"
working_directory = "terraform/test"
}
Expand Down
2 changes: 0 additions & 2 deletions scalr/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
HTTPClient: httpClient,
Headers: make(http.Header),
}
// Set internal API profile
cfg.Headers.Set("Prefer", "profile=internal")

// Create a new Scalr client.
client, err := scalr.NewClient(cfg)
Expand Down
20 changes: 13 additions & 7 deletions scalr/resource_scalr_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ func resourceScalrEndpoint() *schema.Resource {
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceScalrEndpointResourceV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceScalrEndpointStateUpgradeV0,
Version: 0,
},
},

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,
Expand All @@ -42,7 +45,8 @@ func resourceScalrEndpoint() *schema.Resource {

"secret_key": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
Sensitive: true,
},

Expand Down Expand Up @@ -77,11 +81,13 @@ func resourceScalrEndpointCreate(d *schema.ResourceData, meta interface{}) error
// Create a new options struct.
options := scalr.EndpointCreateOptions{
Name: scalr.String(name),
SecretKey: scalr.String(d.Get("secret_key").(string)),
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))
Expand Down
55 changes: 55 additions & 0 deletions scalr/resource_scalr_endpoint_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package scalr

import (
"github.com/hashicorp/terraform/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(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
delete(rawState, "http_method")
return rawState, nil
}
24 changes: 24 additions & 0 deletions scalr/resource_scalr_endpoint_migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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(testResourceScalrEndpointStateDataV0(), nil)
assertCorrectState(t, err, actual, expected)
}
Loading