Skip to content

Commit b636416

Browse files
authored
Add sync+method in action resource (#78)
1 parent d354a79 commit b636416

File tree

6 files changed

+69
-4
lines changed

6 files changed

+69
-4
lines changed

internal/cli/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ type (
126126
Type string `json:"type,omitempty"`
127127
Url *string `json:"url,omitempty"`
128128
Agent *bool `json:"agent,omitempty"`
129+
Synchronized *bool `json:"synchronized,omitempty"`
130+
Method *string `json:"method,omitempty"`
129131
Org *string `json:"org,omitempty"`
130132
Repo *string `json:"repo,omitempty"`
131133
Webhook *string `json:"webhook,omitempty"`

port/action/actionStateToPortBody.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ func invocationMethodToBody(data *ActionModel) *cli.InvocationMethod {
183183
agent := data.WebhookMethod.Agent.ValueBool()
184184
webhookInvocation.Agent = &agent
185185
}
186+
if !data.WebhookMethod.Synchronized.IsNull() {
187+
synchronized := data.WebhookMethod.Synchronized.ValueBool()
188+
webhookInvocation.Synchronized = &synchronized
189+
}
190+
if !data.WebhookMethod.Method.IsNull() {
191+
method := data.WebhookMethod.Method.ValueString()
192+
webhookInvocation.Method = &method
193+
}
194+
186195
return webhookInvocation
187196
}
188197

port/action/model.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
)
66

77
type WebhookMethodModel struct {
8-
Url types.String `tfsdk:"url"`
9-
Agent types.Bool `tfsdk:"agent"`
8+
Url types.String `tfsdk:"url"`
9+
Agent types.Bool `tfsdk:"agent"`
10+
Synchronized types.Bool `tfsdk:"synchronized"`
11+
Method types.String `tfsdk:"method"`
1012
}
1113

1214
type Value struct {

port/action/refreshActionState.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ func writeInvocationMethodToResource(a *cli.Action, state *ActionModel) {
1919

2020
if a.InvocationMethod.Type == consts.Webhook {
2121
state.WebhookMethod = &WebhookMethodModel{
22-
Url: types.StringValue(*a.InvocationMethod.Url),
23-
Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent),
22+
Url: types.StringValue(*a.InvocationMethod.Url),
23+
Agent: flex.GoBoolToFramework(a.InvocationMethod.Agent),
24+
Synchronized: flex.GoBoolToFramework(a.InvocationMethod.Synchronized),
25+
Method: flex.GoStringToFramework(a.InvocationMethod.Method),
2426
}
2527
}
2628

port/action/resource_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,45 @@ func TestAccPortActionWebhookInvocation(t *testing.T) {
174174
},
175175
})
176176
}
177+
func TestAccPortActionWebhookSyncInvocation(t *testing.T) {
178+
identifier := utils.GenID()
179+
actionIdentifier := utils.GenID()
180+
var testAccActionConfigCreate = testAccCreateBlueprintConfig(identifier) + fmt.Sprintf(`
181+
resource "port_action" "create_microservice" {
182+
title = "TF Provider Test"
183+
identifier = "%s"
184+
icon = "Terraform"
185+
blueprint = port_blueprint.microservice.id
186+
trigger = "DAY-2"
187+
webhook_method = {
188+
url = "https://example.com"
189+
synchronized = true
190+
agent = true
191+
method = "POST"
192+
}
193+
}`, actionIdentifier)
194+
195+
resource.Test(t, resource.TestCase{
196+
PreCheck: func() { acctest.TestAccPreCheck(t) },
197+
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,
198+
Steps: []resource.TestStep{
199+
{
200+
Config: acctest.ProviderConfig + testAccActionConfigCreate,
201+
Check: resource.ComposeTestCheckFunc(
202+
resource.TestCheckResourceAttr("port_action.create_microservice", "title", "TF Provider Test"),
203+
resource.TestCheckResourceAttr("port_action.create_microservice", "identifier", actionIdentifier),
204+
resource.TestCheckResourceAttr("port_action.create_microservice", "icon", "Terraform"),
205+
resource.TestCheckResourceAttr("port_action.create_microservice", "blueprint", identifier),
206+
resource.TestCheckResourceAttr("port_action.create_microservice", "trigger", "DAY-2"),
207+
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.url", "https://example.com"),
208+
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.synchronized", "true"),
209+
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.method", "POST"),
210+
resource.TestCheckResourceAttr("port_action.create_microservice", "webhook_method.agent", "true"),
211+
),
212+
},
213+
},
214+
})
215+
}
177216

178217
func TestAccPortActionGitlabInvocation(t *testing.T) {
179218
identifier := utils.GenID()

port/action/schema.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ func ActionSchema() map[string]schema.Attribute {
152152
MarkdownDescription: "Use the agent to invoke the action",
153153
Optional: true,
154154
},
155+
"synchronized": schema.BoolAttribute{
156+
MarkdownDescription: "Synchronize the action",
157+
Optional: true,
158+
},
159+
"method": schema.StringAttribute{
160+
MarkdownDescription: "The HTTP method to invoke the action",
161+
Optional: true,
162+
Validators: []validator.String{
163+
stringvalidator.OneOf("POST", "PUT", "PATCH", "DELETE"),
164+
},
165+
},
155166
},
156167
},
157168
"github_method": schema.SingleNestedAttribute{

0 commit comments

Comments
 (0)