From ecbfe6a7001923fd1a441ba0a234e4cd24e4572a Mon Sep 17 00:00:00 2001 From: Evan Cleary Date: Mon, 13 Sep 2021 21:38:39 -0400 Subject: [PATCH] feat: Add block deployments support Adds support for blocking deployments in manual actions. Expands responsible teams attribute to a list for manual actions. --- ...o => schema_action_manual_intervention.go} | 27 +++++++++++++++---- .../schema_action_manual_intervention_test.go | 9 +++++-- 2 files changed, 29 insertions(+), 7 deletions(-) rename octopusdeploy/{schema_manual_intervention_action.go => schema_action_manual_intervention.go} (63%) diff --git a/octopusdeploy/schema_manual_intervention_action.go b/octopusdeploy/schema_action_manual_intervention.go similarity index 63% rename from octopusdeploy/schema_manual_intervention_action.go rename to octopusdeploy/schema_action_manual_intervention.go index d1b5ead3b..fba78710f 100644 --- a/octopusdeploy/schema_manual_intervention_action.go +++ b/octopusdeploy/schema_action_manual_intervention.go @@ -1,6 +1,9 @@ package octopusdeploy import ( + "strconv" + "strings" + "github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -8,10 +11,12 @@ import ( func flattenManualIntervention(actionMap map[string]interface{}, properties map[string]octopusdeploy.PropertyValue) { for propertyName, propertyValue := range properties { switch propertyName { + case "Octopus.Action.Manual.BlockConcurrentDeployments": + actionMap["block_deployments"], _ = strconv.ParseBool(propertyValue.Value) case "Octopus.Action.Manual.Instructions": actionMap["instructions"] = propertyValue.Value case "Octopus.Action.Manual.ResponsibleTeamIds": - actionMap["responsible_teams"] = propertyValue.Value + actionMap["responsible_teams"] = strings.Split(propertyValue.Value, ",") } } } @@ -26,6 +31,13 @@ func flattenManualInterventionAction(action *octopusdeploy.DeploymentAction) map func getManualInterventionActionSchema() *schema.Schema { actionSchema, element := getActionSchema() + element.Schema["block_deployments"] = &schema.Schema{ + Type: schema.TypeBool, + Description: "Should other deployments be blocked while this manual intervention is awaiting action?", + Optional: true, + Default: false, + } + element.Schema["instructions"] = &schema.Schema{ Type: schema.TypeString, Description: "The instructions for the user to follow", @@ -33,9 +45,10 @@ func getManualInterventionActionSchema() *schema.Schema { } element.Schema["responsible_teams"] = &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeList, Description: "The teams responsible to resolve this step. If no teams are specified, all users who have permission to deploy the project can resolve it.", Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, } return actionSchema @@ -44,11 +57,15 @@ func getManualInterventionActionSchema() *schema.Schema { func expandManualInterventionAction(tfAction map[string]interface{}) *octopusdeploy.DeploymentAction { resource := expandAction(tfAction) resource.ActionType = "Octopus.Manual" + + if blockDeployments, ok := tfAction["block_deployments"]; ok { + resource.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"] = octopusdeploy.NewPropertyValue(strings.Title(strconv.FormatBool(blockDeployments.(bool))), false) + } + resource.Properties["Octopus.Action.Manual.Instructions"] = octopusdeploy.NewPropertyValue(tfAction["instructions"].(string), false) - responsibleTeams := tfAction["responsible_teams"] - if responsibleTeams != nil { - resource.Properties["Octopus.Action.Manual.ResponsibleTeamIds"] = octopusdeploy.NewPropertyValue(responsibleTeams.(string), false) + if responsibleTeams, ok := tfAction["responsible_teams"]; ok { + resource.Properties["Octopus.Action.Manual.ResponsibleTeamIds"] = octopusdeploy.NewPropertyValue(strings.Join(getSliceFromTerraformTypeList(responsibleTeams), ","), false) } return resource diff --git a/octopusdeploy/schema_action_manual_intervention_test.go b/octopusdeploy/schema_action_manual_intervention_test.go index f127698a3..07a51b1f9 100644 --- a/octopusdeploy/schema_action_manual_intervention_test.go +++ b/octopusdeploy/schema_action_manual_intervention_test.go @@ -33,8 +33,9 @@ func testAccManualInterventionAction() string { return testAccBuildTestAction(` manual_intervention_action { name = "Test" + block_deployments = true instructions = "Approve Me" - responsible_teams = "A Team" + responsible_teams = ["A Team", "B Team"] } `) } @@ -54,11 +55,15 @@ func testAccCheckManualInterventionAction() resource.TestCheckFunc { return fmt.Errorf("Action type is incorrect: %s", action.ActionType) } + if action.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"].Value != "True" { + return fmt.Errorf("Block Deployments is incorrect: %s", action.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"].Value) + } + if action.Properties["Octopus.Action.Manual.Instructions"].Value != "Approve Me" { return fmt.Errorf("Instructions is incorrect: %s", action.Properties["Octopus.Action.Manual.Instructions"].Value) } - if action.Properties["Octopus.Action.Manual.ResponsibleTeamIds"].Value != "A Team" { + if action.Properties["Octopus.Action.Manual.ResponsibleTeamIds"].Value != "A Team,B Team" { return fmt.Errorf("ResponsibleTeamIds is incorrect: %s", action.Properties["Octopus.Action.Manual.ResponsibleTeamIds"].Value) }