Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mamacdon-surveymonkey committed Mar 1, 2022
1 parent b77a717 commit 9dd1c72
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions internal/provider/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,11 @@ func buildTemplate(templateID string, d *schema.ResourceData) *sp.Template {
return template
}

func publishTemplate(ctx context.Context, d *schema.ResourceData, client *sp.Client, templateID string, publish bool) error {
if publish {
// automatically publish the template
_, err := client.TemplatePublishContext(ctx, templateID)
if err != nil {
return err
}
func publishTemplate(ctx context.Context, d *schema.ResourceData, client *sp.Client, templateID string) error {
// automatically publish the template
_, err := client.TemplatePublishContext(ctx, templateID)
if err != nil {
return err
}

return nil
Expand All @@ -210,9 +208,11 @@ func resourceTemplateCreate(ctx context.Context, d *schema.ResourceData, m inter
return diag.FromErr(err)
}

err = publishTemplate(ctx, d, client, templateID, template.Published)
if err != nil {
return diag.FromErr(err)
if template.Published {
err = publishTemplate(ctx, d, client, templateID)
if err != nil {
return diag.FromErr(err)
}
}

// Ensure the read looks for the correct copy of the template
Expand Down Expand Up @@ -255,9 +255,11 @@ func resourceTemplateUpdate(ctx context.Context, d *schema.ResourceData, m inter
}

// Publish it if we're going from draft -> published
err = publishTemplate(ctx, d, client, templateID, publishUpdate)
if err != nil {
return diag.FromErr(err)
if publishUpdate {
err = publishTemplate(ctx, d, client, templateID)
if err != nil {
return diag.FromErr(err)
}
}

// Ensure the read looks for the correct copy of the template
Expand Down

0 comments on commit 9dd1c72

Please sign in to comment.