Skip to content

Commit

Permalink
Add sync+method in action resource (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirsegev authored Oct 1, 2023
1 parent d354a79 commit b636416
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ type (
Type string `json:"type,omitempty"`
Url *string `json:"url,omitempty"`
Agent *bool `json:"agent,omitempty"`
Synchronized *bool `json:"synchronized,omitempty"`
Method *string `json:"method,omitempty"`
Org *string `json:"org,omitempty"`
Repo *string `json:"repo,omitempty"`
Webhook *string `json:"webhook,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions port/action/actionStateToPortBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ func invocationMethodToBody(data *ActionModel) *cli.InvocationMethod {
agent := data.WebhookMethod.Agent.ValueBool()
webhookInvocation.Agent = &agent
}
if !data.WebhookMethod.Synchronized.IsNull() {
synchronized := data.WebhookMethod.Synchronized.ValueBool()
webhookInvocation.Synchronized = &synchronized
}
if !data.WebhookMethod.Method.IsNull() {
method := data.WebhookMethod.Method.ValueString()
webhookInvocation.Method = &method
}

return webhookInvocation
}

Expand Down
6 changes: 4 additions & 2 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
)

type WebhookMethodModel struct {
Url types.String `tfsdk:"url"`
Agent types.Bool `tfsdk:"agent"`
Url types.String `tfsdk:"url"`
Agent types.Bool `tfsdk:"agent"`
Synchronized types.Bool `tfsdk:"synchronized"`
Method types.String `tfsdk:"method"`
}

type Value struct {
Expand Down
6 changes: 4 additions & 2 deletions port/action/refreshActionState.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ func writeInvocationMethodToResource(a *cli.Action, state *ActionModel) {

if a.InvocationMethod.Type == consts.Webhook {
state.WebhookMethod = &WebhookMethodModel{
Url: types.StringValue(*a.InvocationMethod.Url),
Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent),
Url: types.StringValue(*a.InvocationMethod.Url),
Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent),
Synchronized: flex.GoBoolToFramework(a.InvocationMethod.Synchronized),
Method: flex.GoStringToFramework(a.InvocationMethod.Method),
}
}

Expand Down
39 changes: 39 additions & 0 deletions port/action/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,45 @@ func TestAccPortActionWebhookInvocation(t *testing.T) {
},
})
}
func TestAccPortActionWebhookSyncInvocation(t *testing.T) {
identifier := utils.GenID()
actionIdentifier := utils.GenID()
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
resource "port_action" "create_microservice" {
title = "TF Provider Test"
identifier = "%s"
icon = "Terraform"
blueprint = port_blueprint.microservice.id
trigger = "DAY-2"
webhook_method = {
url = "https://example.com"
synchronized = true
agent = true
method = "POST"
}
}`, actionIdentifier)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_action.create_microservice", "title", "TF Provider Test"),
resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
resource.TestCheckResourceAttr("port_action.create_microservice", "blueprint", identifier),
resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"),
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://example.com"),
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.synchronized", "true"),
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.method", "POST"),
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.agent", "true"),
),
},
},
})
}

func TestAccPortActionGitlabInvocation(t *testing.T) {
identifier := utils.GenID()
Expand Down
11 changes: 11 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ func ActionSchema() map[string]schema.Attribute {
MarkdownDescription: "Use the agent to invoke the action",
Optional: true,
},
"synchronized": schema.BoolAttribute{
MarkdownDescription: "Synchronize the action",
Optional: true,
},
"method": schema.StringAttribute{
MarkdownDescription: "The HTTP method to invoke the action",
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("POST", "PUT", "PATCH", "DELETE"),
},
},
},
},
"github_method": schema.SingleNestedAttribute{
Expand Down

0 comments on commit b636416

Please sign in to comment.