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

feat(r/manual_intervention_action): Add block deployments support #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package octopusdeploy

import (
"strconv"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

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, ",")
}
}
}
Expand All @@ -26,16 +31,24 @@ 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",
Required: true,
}

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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions octopusdeploy/schema_action_manual_intervention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
`)
}
Expand All @@ -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)
}

Expand Down