Skip to content

Commit

Permalink
Merge pull request #23 from port-labs/PORT-2862-terraform-provider-do…
Browse files Browse the repository at this point in the history
…nt-ignore-report-workflow-status-in-github-action-type

Fix ignore report_workflow_status
  • Loading branch information
talsabagport authored Feb 1, 2023
2 parents 16d0640 + 0bf823e commit 8b6765d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion port/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type (
Workflow string `json:"workflow,omitempty"`
OmitPayload bool `json:"omitPayload,omitempty"`
OmitUserInputs bool `json:"omitUserInputs,omitempty"`
ReportWorkflowStatus bool `json:"reportWorkflowStatus,omitempty"`
ReportWorkflowStatus *bool `json:"reportWorkflowStatus,omitempty"`
}

ChangelogDestination struct {
Expand Down
17 changes: 15 additions & 2 deletions port/resource_port_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func newActionResource() *schema.Resource {
"report_workflow_status": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Relevant only when selecting type GITHUB. The flag that controls if to report the action status when the workflow completes",
RequiredWith: requiredGithubArguments,
},
Expand Down Expand Up @@ -211,6 +212,11 @@ func writeActionFieldsToResource(d *schema.ResourceData, action *cli.Action) {
d.Set("title", action.Title)
d.Set("icon", action.Icon)
d.Set("description", action.Description)

reportWorkflowStatus := true
if action.InvocationMethod.ReportWorkflowStatus != nil {
reportWorkflowStatus = *action.InvocationMethod.ReportWorkflowStatus
}
d.Set("invocation_method", []any{map[string]any{
"type": action.InvocationMethod.Type,
"url": action.InvocationMethod.Url,
Expand All @@ -220,7 +226,7 @@ func writeActionFieldsToResource(d *schema.ResourceData, action *cli.Action) {
"workflow": action.InvocationMethod.Workflow,
"omit_payload": action.InvocationMethod.OmitPayload,
"omit_user_inputs": action.InvocationMethod.OmitUserInputs,
"report_workflow_status": action.InvocationMethod.ReportWorkflowStatus,
"report_workflow_status": reportWorkflowStatus,
}})

d.Set("trigger", action.Trigger)
Expand Down Expand Up @@ -291,7 +297,14 @@ func actionResourceToBody(d *schema.ResourceData) (*cli.Action, error) {
action.InvocationMethod.Workflow = invocationMethod.([]any)[0].(map[string]interface{})["workflow"].(string)
action.InvocationMethod.OmitPayload = invocationMethod.([]any)[0].(map[string]interface{})["omit_payload"].(bool)
action.InvocationMethod.OmitUserInputs = invocationMethod.([]any)[0].(map[string]interface{})["omit_user_inputs"].(bool)
action.InvocationMethod.ReportWorkflowStatus = invocationMethod.([]any)[0].(map[string]interface{})["report_workflow_status"].(bool)

reportWorkflowStatus := invocationMethod.([]any)[0].(map[string]interface{})["report_workflow_status"].(bool)
if reportWorkflowStatus {
action.InvocationMethod.ReportWorkflowStatus = nil
} else {
action.InvocationMethod.ReportWorkflowStatus = new(bool)
*action.InvocationMethod.ReportWorkflowStatus = reportWorkflowStatus
}
}
action.Trigger = d.Get("trigger").(string)

Expand Down
4 changes: 2 additions & 2 deletions port/resource_port_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestAccPortActionGithubInvocation(t *testing.T) {
workflow = "deploy.yml"
omit_payload = false
omit_user_inputs = false
report_workflow_status = true
report_workflow_status = false
}
}
`, identifier, actionIdentifier)
Expand All @@ -362,7 +362,7 @@ func TestAccPortActionGithubInvocation(t *testing.T) {
resource.TestCheckResourceAttr("port-labs_action.restart_microservice", "invocation_method.0.workflow", "deploy.yml"),
resource.TestCheckResourceAttr("port-labs_action.restart_microservice", "invocation_method.0.omit_payload", "false"),
resource.TestCheckResourceAttr("port-labs_action.restart_microservice", "invocation_method.0.omit_user_inputs", "false"),
resource.TestCheckResourceAttr("port-labs_action.restart_microservice", "invocation_method.0.report_workflow_status", "true"),
resource.TestCheckResourceAttr("port-labs_action.restart_microservice", "invocation_method.0.report_workflow_status", "false"),
),
},
},
Expand Down

0 comments on commit 8b6765d

Please sign in to comment.