Skip to content

Commit

Permalink
support for dynamic content variant
Browse files Browse the repository at this point in the history
  • Loading branch information
970uraj committed May 10, 2024
1 parent 3ad48fb commit c80fd1d
Show file tree
Hide file tree
Showing 5 changed files with 423 additions and 38 deletions.
36 changes: 31 additions & 5 deletions examples/resources/scratchpad/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,34 @@
# description = "foo bar some desc"
# }

resource "zendesk_dynamic_content" "foodc" {
name = "dc utk snow"
content = "utk snow snow snow "
locale_id = 1
}
resource "zendesk_dynamic_content" "foodcnew" {
name = "dcutkok"
}

resource "zendesk_dynamic_content" "life_isgood" {
name = "lifeisgoodright"
}
resource "zendesk_dynamic_content_variant" "foobar" {
content = "FooBar change is good"
locale_id = 2
default = true
dynamic_content_item_id = zendesk_dynamic_content.life_isgood.id
}

# resource "zendesk_dynamic_content" "better" {
# name = "better"
# }

# resource "zendesk_dynamic_content_variant" "better_content" {
# content = "Some data here is template good"
# locale_id = 1
# default = true
# dynamic_content_item_id = 18847895265170
# }

# resource "zendesk_dynamic_content_variant" "foobaranother" {
# content = "foo bar is here right??? new"
# locale_id = 1
# default = true
# dynamic_content_item_id = zendesk_dynamic_content.life_isgood.id
# }
35 changes: 18 additions & 17 deletions zendesk/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ func Provider() *schema.Provider {
},

ResourcesMap: map[string]*schema.Resource{
"zendesk_automation": resourceZendeskAutomation(),
"zendesk_brand": resourceZendeskBrand(),
"zendesk_dynamic_content": resourceZendeskDynamicContent(),
"zendesk_group": resourceZendeskGroup(),
"zendesk_ticket_field": resourceZendeskTicketField(),
"zendesk_macro": resourceZendeskMacro(),
"zendesk_view": resourceZendeskView(),
"zendesk_user_field": resourceZendeskUserField(),
"zendesk_ticket_form": resourceZendeskTicketForm(),
"zendesk_trigger": resourceZendeskTrigger(),
"zendesk_trigger_category": resourceZendeskTriggerCategory(),
"zendesk_target": resourceZendeskTarget(),
"zendesk_attachment": resourceZendeskAttachment(),
"zendesk_organization": resourceZendeskOrganization(),
"zendesk_organization_field": resourceZendeskOrganizationField(),
"zendesk_sla_policy": resourceZendeskSLAPolicy(),
"zendesk_webhook": resourceZendeskWebhook(),
"zendesk_automation": resourceZendeskAutomation(),
"zendesk_brand": resourceZendeskBrand(),
"zendesk_dynamic_content": resourceZendeskDynamicContent(),
"zendesk_dynamic_content_variant": resourceZendeskDynamicContentVariant(),
"zendesk_group": resourceZendeskGroup(),
"zendesk_ticket_field": resourceZendeskTicketField(),
"zendesk_macro": resourceZendeskMacro(),
"zendesk_view": resourceZendeskView(),
"zendesk_user_field": resourceZendeskUserField(),
"zendesk_ticket_form": resourceZendeskTicketForm(),
"zendesk_trigger": resourceZendeskTrigger(),
"zendesk_trigger_category": resourceZendeskTriggerCategory(),
"zendesk_target": resourceZendeskTarget(),
"zendesk_attachment": resourceZendeskAttachment(),
"zendesk_organization": resourceZendeskOrganization(),
"zendesk_organization_field": resourceZendeskOrganizationField(),
"zendesk_sla_policy": resourceZendeskSLAPolicy(),
"zendesk_webhook": resourceZendeskWebhook(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down
26 changes: 11 additions & 15 deletions zendesk/resource_zendesk_dynamic_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func resourceZendeskDynamicContent() *schema.Resource {
return &schema.Resource{
Description: ``,
Description: `Due to limitation of zendesk API creates a placeholder dynamic_content_variant with placeholder text`,
CreateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
zd := meta.(*client.Client)
return createDynamicContent(ctx, d, zd)
Expand Down Expand Up @@ -43,25 +43,20 @@ func resourceZendeskDynamicContent() *schema.Resource {
Required: true,
Description: "Name of the Dynamic Content Item",
},
"content": {
Type: schema.TypeString,
Description: "Content of the dynamic content item",
Required: true,
},
"locale_id": {
Type: schema.TypeInt,
Description: "Locale Id for the dynamic content item",
Required: true,
Description: "Default Locale Id for the dynamic content item",
Computed: true,
},
},
}
}

func marshalDynamicContent(dc client.DynamicContentItem, d identifiableGetterSetter) error {
fields := map[string]interface{}{
"url": dc.URL,
"name": dc.Name,
"content": dc.Variants[0].Content,
"url": dc.URL,
"name": dc.Name,
// "content": dc.Variants[0].Content,
"locale_id": dc.DefaultLocaleID,
}

Expand Down Expand Up @@ -93,14 +88,15 @@ func unmarshalDynamicContent(d identifiableGetterSetter) (client.DynamicContentI
}

dc_variant := client.DynamicContentVariant{}
if v, ok := d.GetOk("content"); ok {
dc_variant.Default = true // This lib only supports a single dc variant
dc_variant.Content = v.(string)
}
dc_variant.Default = true // This lib only supports a single dc variant
dc_variant.Content = "BLANK_ONLY_HERE_BECAUSE_ZENDESK_API_NOT_GOOD"
// dc_variant.Active = false

if v, ok := d.GetOk("locale_id"); ok {
dc.DefaultLocaleID = int64(v.(int))
dc_variant.LocaleID = dc.DefaultLocaleID
} else {
dc_variant.LocaleID = 16
}
dc.Variants = append(dc.Variants, dc_variant)

Expand Down
Loading

0 comments on commit c80fd1d

Please sign in to comment.