Skip to content

Commit

Permalink
fix: Add 'Block Deployments' attribute to manual intervention step (#847
Browse files Browse the repository at this point in the history
)
  • Loading branch information
denys-octopus authored Jan 5, 2025
1 parent 293287d commit 765e690
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/deployment_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ Required:
Optional:

- `action_template` (Block Set, Max: 1) Represents the template that is associated with this action. (see [below for nested schema](#nestedblock--step--manual_intervention_action--action_template))
- `block_deployments` (String) Should other deployments be blocked while this manual intervention is awaiting action.
- `can_be_used_for_project_versioning` (Boolean)
- `channels` (List of String) The channels associated with this deployment action.
- `condition` (String) The condition associated with this deployment action.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/runbook_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ Required:
Optional:

- `action_template` (Block Set, Max: 1) Represents the template that is associated with this action. (see [below for nested schema](#nestedblock--step--manual_intervention_action--action_template))
- `block_deployments` (String) Should other deployments be blocked while this manual intervention is awaiting action.
- `can_be_used_for_project_versioning` (Boolean)
- `channels` (List of String) The channels associated with this deployment action.
- `condition` (String) The condition associated with this deployment action.
Expand Down
5 changes: 5 additions & 0 deletions octopusdeploy/schema_action_manual_intervention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func testAccManualInterventionAction() string {
sort_order = 1
instructions = "Approve Me"
responsible_teams = "A Team"
block_deployments = "True"
}
`)
}
Expand All @@ -60,6 +61,10 @@ func testAccCheckManualInterventionAction() resource.TestCheckFunc {
return fmt.Errorf("ResponsibleTeamIds is incorrect: %s", action.Properties["Octopus.Action.Manual.ResponsibleTeamIds"].Value)
}

if action.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"].Value != "True" {
return fmt.Errorf("expected BlockConcurrentDeployments to be 'True' but got '%s'", action.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"].Value)
}

return nil
}
}
13 changes: 13 additions & 0 deletions octopusdeploy/schema_manual_intervention_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func flattenManualIntervention(actionMap map[string]interface{}, properties map[
actionMap["instructions"] = propertyValue.Value
case "Octopus.Action.Manual.ResponsibleTeamIds":
actionMap["responsible_teams"] = propertyValue.Value
case "Octopus.Action.Manual.BlockConcurrentDeployments":
actionMap["block_deployments"] = propertyValue.Value
}
}
}
Expand All @@ -39,6 +41,12 @@ func getManualInterventionActionSchema() *schema.Schema {
Optional: true,
}

element.Schema["block_deployments"] = &schema.Schema{
Type: schema.TypeString,
Description: "Should other deployments be blocked while this manual intervention is awaiting action.",
Optional: true,
}

return actionSchema
}

Expand All @@ -52,5 +60,10 @@ func expandManualInterventionAction(tfAction map[string]interface{}) *deployment
resource.Properties["Octopus.Action.Manual.ResponsibleTeamIds"] = core.NewPropertyValue(responsibleTeams.(string), false)
}

if blockDeployments, ok := tfAction["block_deployments"]; ok {
value := formatAsBoolOrBoundedValueForActionProperty(blockDeployments.(string))
resource.Properties["Octopus.Action.Manual.BlockConcurrentDeployments"] = core.NewPropertyValue(value, false)
}

return resource
}
14 changes: 14 additions & 0 deletions octopusdeploy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package octopusdeploy
import (
"hash/crc32"
"log"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -119,3 +120,16 @@ func formatBoolForActionProperty(b bool) string {
}
return "False"
}

func formatAsBoolOrBoundedValueForActionProperty(value string) string {
if strings.Contains(value, "#{") {
return value
}

boolValue, err := strconv.ParseBool(value)
if err == nil {
return formatBoolForActionProperty(boolValue)
}

return value
}

0 comments on commit 765e690

Please sign in to comment.