Skip to content

Commit

Permalink
Chore: remove wait_for (#430)
Browse files Browse the repository at this point in the history
* Revert "Chore: Add configuration for waiting for environment to finish deployment (#273)"

This reverts commit 2e045e5.

* some post revert fixes

* fix unit tests

* fix integration test

* BREAKING CHANGE: wait_for was removed when deploying an enviornment
  • Loading branch information
TomerHeber authored Jul 11, 2022
1 parent 5a87769 commit 3c97bb8
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 383 deletions.
3 changes: 1 addition & 2 deletions client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ type ApiClientInterface interface {
ProjectEnvironments(projectId string) ([]Environment, error)
Environment(id string) (Environment, error)
EnvironmentCreate(payload EnvironmentCreate) (Environment, error)
EnvironmentDestroy(id string) (EnvironmentDeployResponse, error)
EnvironmentDestroy(id string) (Environment, error)
EnvironmentUpdate(id string, payload EnvironmentUpdate) (Environment, error)
EnvironmentDeploy(id string, payload DeployRequest) (EnvironmentDeployResponse, error)
EnvironmentUpdateTTL(id string, payload TTL) (Environment, error)
EnvironmentScheduling(environmentId string) (EnvironmentScheduling, error)
EnvironmentSchedulingUpdate(environmentId string, payload EnvironmentScheduling) (EnvironmentScheduling, error)
EnvironmentSchedulingDelete(environmentId string) error
Deployment(id string) (DeploymentLog, error)
WorkflowTrigger(environmentId string) ([]WorkflowTrigger, error)
WorkflowTriggerUpsert(environmentId string, request WorkflowTriggerUpsertPayload) ([]WorkflowTrigger, error)
EnvironmentDriftDetection(environmentId string) (EnvironmentSchedulingExpression, error)
Expand Down
19 changes: 2 additions & 17 deletions client/api_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 3 additions & 14 deletions client/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type DeploymentLog struct {
BlueprintId string `json:"blueprintId"`
BlueprintRepository string `json:"blueprintRepository"`
BlueprintRevision string `json:"blueprintRevision"`
Status string `json:"status"`
}

type Environment struct {
Expand Down Expand Up @@ -166,11 +165,11 @@ func (client *ApiClient) EnvironmentCreate(payload EnvironmentCreate) (Environme
return result, nil
}

func (client *ApiClient) EnvironmentDestroy(id string) (EnvironmentDeployResponse, error) {
var result EnvironmentDeployResponse
func (client *ApiClient) EnvironmentDestroy(id string) (Environment, error) {
var result Environment
err := client.http.Post("/environments/"+id+"/destroy", nil, &result)
if err != nil {
return EnvironmentDeployResponse{}, err
return Environment{}, err
}
return result, nil
}
Expand Down Expand Up @@ -204,13 +203,3 @@ func (client *ApiClient) EnvironmentDeploy(id string, payload DeployRequest) (En
}
return result, nil
}

func (client *ApiClient) Deployment(id string) (DeploymentLog, error) {
var result DeploymentLog
err := client.http.Get("/environments/deployments/"+id, nil, &result)

if err != nil {
return DeploymentLog{}, err
}
return result, nil
}
72 changes: 1 addition & 71 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import (
"errors"
"fmt"
"log"
"os"
"regexp"
"time"

"github.com/env0/terraform-provider-env0/client"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const deploymentStatusWaitPollInterval = 10 // In seconds

func resourceEnvironment() *schema.Resource {
return &schema.Resource{
CreateContext: resourceEnvironmentCreate,
Expand Down Expand Up @@ -114,20 +110,6 @@ func resourceEnvironment() *schema.Resource {
Description: "Destroy safeguard. Must be enabled before delete/destroy",
Optional: true,
},
"wait_for": {
Type: schema.TypeString,
Description: "whether or not to wait for environment to fully deploy",
Optional: true,
Default: "ACK",
Deprecated: "wait_for is deprecated and will be removed in the next major release",
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
value := val.(string)
if value != "ACK" && value != "FULLY_DEPLOYED" {
errs = append(errs, fmt.Errorf("%q can be either \"ACK\", \"FULLY_DEPLOYED\" or empty, got: %q", key, value))
}
return
},
},
"terragrunt_working_directory": {
Type: schema.TypeString,
Description: "The working directory path to be used by a Terragrunt template. If left empty '/' is used.",
Expand Down Expand Up @@ -294,13 +276,6 @@ func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta
d.Set("deployment_id", environment.LatestDeploymentLogId)
setEnvironmentSchema(d, environment, environmentConfigurationVariables)

if shouldWaitForDeployment(d) {
err := waitForDeployment(environment.LatestDeploymentLogId, apiClient)
if err != nil {
return diag.Errorf("failed deploying environment: %v", err)
}
}

return nil
}

Expand Down Expand Up @@ -367,14 +342,6 @@ func deploy(d *schema.ResourceData, apiClient client.ApiClientInterface) diag.Di
return diag.Errorf("failed deploying environment: %v", err)
}
d.Set("deployment_id", deployResponse.Id)

if shouldWaitForDeployment(d) {
err := waitForDeployment(deployResponse.Id, apiClient)
if err != nil {
return diag.Errorf("failed deploying environment: %v", err)
}
}

return nil
}

Expand Down Expand Up @@ -411,17 +378,10 @@ func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, meta

apiClient := meta.(client.ApiClientInterface)

destroyResponse, err := apiClient.EnvironmentDestroy(d.Id())
_, err := apiClient.EnvironmentDestroy(d.Id())
if err != nil {
return diag.Errorf("could not delete environment: %v", err)
}
if shouldWaitForDeployment(d) {
err := waitForDeployment(destroyResponse.Id, apiClient)
if err != nil {
return diag.Errorf("failed to delete environment: %v", err)
}
}

return nil
}

Expand Down Expand Up @@ -735,33 +695,3 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta
return []*schema.ResourceData{d}, nil
}
}

func shouldWaitForDeployment(d *schema.ResourceData) bool {
return d.Get("wait_for").(string) == "FULLY_DEPLOYED"
}

func waitForDeployment(deploymentLogId string, apiClient client.ApiClientInterface) error {
log.Println("[INFO] Waiting for deployment to finish")
for {
deployment, err := apiClient.Deployment(deploymentLogId)
if err != nil {
return err
}
switch deployment.Status {
case "IN_PROGRESS",
"QUEUED",
"WAITING_FOR_USER":
log.Println("[INFO] Deployment not yet done deploying. Got status ", deployment.Status)
// TF_ACC is set during acceptance tests. Don't pause during accpetance tests.
if value, present := os.LookupEnv("TF_ACC"); !present || value != "1" {
time.Sleep(deploymentStatusWaitPollInterval * time.Second)
}
case "SUCCESS",
"SKIPPED":
log.Println("[INFO] Deployment done deploying! Got status ", deployment.Status)
return nil
default:
return fmt.Errorf("environment deployment reached failure status: %v", deployment.Status)
}
}
}
Loading

0 comments on commit 3c97bb8

Please sign in to comment.