Skip to content

Commit

Permalink
fix pipe schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed May 13, 2023
1 parent b910955 commit 7fc7df0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
27 changes: 18 additions & 9 deletions bitbucket/resource_pipeline_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func resourcePipelineScheduleCreate(ctx context.Context, d *schema.ResourceData,
c := m.(Clients).genClient
pipeApi := c.ApiClient.PipelinesApi

pipeSchedule := expandPipelineSchedule(d)
pipeSchedule := expandCreatePipelineSchedule(d)
log.Printf("[DEBUG] Pipeline Schedule Request: %#v", pipeSchedule)

repo := d.Get("repository").(string)
Expand All @@ -110,7 +110,8 @@ func resourcePipelineScheduleCreate(ctx context.Context, d *schema.ResourceData,
d.SetId(string(fmt.Sprintf("%s/%s/%s", workspace, repo, schedule.Uuid)))

if !d.Get("enabled").(bool) {
_, _, err = pipeApi.UpdateRepositoryPipelineSchedule(c.AuthContext, *pipeSchedule, workspace, repo, schedule.Uuid)
pipeScheduleUpdate := expandUpdatePipelineSchedule(d)
_, _, err = pipeApi.UpdateRepositoryPipelineSchedule(c.AuthContext, *pipeScheduleUpdate, workspace, repo, schedule.Uuid)
if err := handleClientError(err); err != nil {
return diag.FromErr(err)
}
Expand All @@ -128,9 +129,9 @@ func resourcePipelineScheduleUpdate(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

pipeSchedule := expandPipelineSchedule(d)
log.Printf("[DEBUG] Pipeline Schedule Request: %#v", pipeSchedule)
_, _, err = pipeApi.UpdateRepositoryPipelineSchedule(c.AuthContext, *pipeSchedule, workspace, repo, uuid)
pipeScheduleUpdate := expandUpdatePipelineSchedule(d)
log.Printf("[DEBUG] Pipeline Schedule Request: %#v", pipeScheduleUpdate)
_, _, err = pipeApi.UpdateRepositoryPipelineSchedule(c.AuthContext, *pipeScheduleUpdate, workspace, repo, uuid)
if err := handleClientError(err); err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -186,8 +187,16 @@ func resourcePipelineScheduleDelete(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

func expandPipelineSchedule(d *schema.ResourceData) *bitbucket.PipelineSchedule {
schedule := &bitbucket.PipelineSchedule{
func expandUpdatePipelineSchedule(d *schema.ResourceData) *bitbucket.PipelineSchedulePutRequestBody {
schedule := &bitbucket.PipelineSchedulePutRequestBody{
Enabled: d.Get("enabled").(bool),
}

return schedule
}

func expandCreatePipelineSchedule(d *schema.ResourceData) *bitbucket.PipelineSchedulePostRequestBody {
schedule := &bitbucket.PipelineSchedulePostRequestBody{
Enabled: d.Get("enabled").(bool),
CronPattern: d.Get("cron_pattern").(string),
Target: expandPipelineRefTarget(d.Get("target").([]interface{})),
Expand All @@ -196,10 +205,10 @@ func expandPipelineSchedule(d *schema.ResourceData) *bitbucket.PipelineSchedule
return schedule
}

func expandPipelineRefTarget(conf []interface{}) *bitbucket.PipelineRefTarget {
func expandPipelineRefTarget(conf []interface{}) *bitbucket.PipelineSchedulePostRequestBodyTarget {
tfMap, _ := conf[0].(map[string]interface{})

target := &bitbucket.PipelineRefTarget{
target := &bitbucket.PipelineSchedulePostRequestBodyTarget{
RefName: tfMap["ref_name"].(string),
RefType: tfMap["ref_type"].(string),
Selector: expandPipelineRefTargetSelector(tfMap["selector"].([]interface{})),
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/terraform-providers/terraform-provider-bitbucket

require (
github.com/DrFaust92/bitbucket-go-client v0.4.0
github.com/DrFaust92/bitbucket-go-client v0.7.1
github.com/antihax/optional v1.0.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/satori/go.uuid v1.2.0
golang.org/x/crypto v0.7.0
golang.org/x/oauth2 v0.6.0
golang.org/x/oauth2 v0.8.0
)

require (
Expand Down Expand Up @@ -47,9 +47,9 @@ require (
github.com/vmihailenco/tagparser v0.1.2 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.51.0 // indirect
Expand Down
22 changes: 11 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/DrFaust92/bitbucket-go-client v0.4.0 h1:XKPVp24XPTRj9Dl1Evrt2hakncF2NpHjgg6FLk4dWP8=
github.com/DrFaust92/bitbucket-go-client v0.4.0/go.mod h1:Q2LQIw5YbfbpTOCs0Gz4kU15bjVRsgUZ9w2+UbB3Yxc=
github.com/DrFaust92/bitbucket-go-client v0.7.1 h1:f/7eLlTARJEzjjB7MxyLUIUYsiAIqxLyBwKqFAelnLY=
github.com/DrFaust92/bitbucket-go-client v0.7.1/go.mod h1:ZEy6oSO5FrpsK234MXOPOfxKF3t255FCa1O4YFvG5ko=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
Expand Down Expand Up @@ -215,11 +215,11 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -244,19 +244,19 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand Down

0 comments on commit 7fc7df0

Please sign in to comment.