Skip to content

Commit

Permalink
[Devtooling-837] External contacts organization id added (#1492)
Browse files Browse the repository at this point in the history
* Added field external_organization_id to resource genesyscloud_externalcontacts_contact

* removed print

* update test added for oragnization
  • Loading branch information
fergalmcl authored Jan 28, 2025
1 parent c48b9ab commit 9eb24cd
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 104 deletions.
6 changes: 4 additions & 2 deletions docs/resources/externalcontacts_contact.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ resource "genesyscloud_externalcontacts_contact" "contact" {
}
display_name = "facebookName"
}
survey_opt_out = false
external_system_url = "https://systemUrl.com"
survey_opt_out = false
external_system_url = "https://systemUrl.com"
external_organization_id = genesyscloud_externalcontacts_organization.example.id
}
```

Expand All @@ -104,6 +105,7 @@ resource "genesyscloud_externalcontacts_contact" "contact" {

- `address` (Block List, Max: 1) Contact address. (see [below for nested schema](#nestedblock--address))
- `cell_phone` (Block List, Max: 1) Contact call phone settings. (see [below for nested schema](#nestedblock--cell_phone))
- `external_organization_id` (String) External organization for this external contact
- `external_system_url` (String) Contact external system url.
- `facebook_id` (Block List, Max: 1) Contact facebook account informations. (see [below for nested schema](#nestedblock--facebook_id))
- `first_name` (String) The first name of the contact.
Expand Down
36 changes: 15 additions & 21 deletions docs/resources/externalcontacts_organization.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,28 @@ The following Genesys Cloud APIs are used by this resource. Ensure your OAuth Cl

```terraform
resource "genesyscloud_externalcontacts_organization" "organization" {
first_name = "jean"
middle_name = "jacques"
last_name = "dupont"
salutation = "salutation"
title = "genesys staff"
name = "ExampleCorporation"
company_type = "Software"
employee_count = 450
phone_number {
display = "+33 0 00 00 00 00"
extension = 4
accepts_sms = false
e164 = "+330000000000"
country_code = "FR"
display = "+2 123-123-4567"
country_code = "US"
}
address {
address1 = "1 rue de la paix"
address2 = "2 rue de la paix"
city = "Paris"
state = "île-de-France"
postal_code = "75000"
country_code = "FR"
address1 = "51 Example Street"
city = "Irvine"
state = "California"
postal_code = "45678"
country_code = "US"
}
twitter {
twitter_id = "RealABCNews"
name = "ABCNews"
screen_name = "ABCNewsCorp"
twitter_id = "ExampleTwitterId"
name = "ExampleTwitterName"
screen_name = "ExampleScreenName"
}
tickers {
symbol = "ABC"
exchange = "NYSE"
symbol = "EXPC"
exchange = "NASDAQ"
}
external_system_url = "https://systemUrl.com"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ resource "genesyscloud_externalcontacts_contact" "contact" {
}
display_name = "facebookName"
}
survey_opt_out = false
external_system_url = "https://systemUrl.com"
survey_opt_out = false
external_system_url = "https://systemUrl.com"
external_organization_id = genesyscloud_externalcontacts_organization.example.id
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
resource "genesyscloud_externalcontacts_organization" "organization" {
first_name = "jean"
middle_name = "jacques"
last_name = "dupont"
salutation = "salutation"
title = "genesys staff"
name = "ExampleCorporation"
company_type = "Software"
employee_count = 450
phone_number {
display = "+33 0 00 00 00 00"
extension = 4
accepts_sms = false
e164 = "+330000000000"
country_code = "FR"
display = "+2 123-123-4567"
country_code = "US"
}
address {
address1 = "1 rue de la paix"
address2 = "2 rue de la paix"
city = "Paris"
state = "île-de-France"
postal_code = "75000"
country_code = "FR"
address1 = "51 Example Street"
city = "Irvine"
state = "California"
postal_code = "45678"
country_code = "US"
}
twitter {
twitter_id = "RealABCNews"
name = "ABCNews"
screen_name = "ABCNewsCorp"
twitter_id = "ExampleTwitterId"
name = "ExampleTwitterName"
screen_name = "ExampleScreenName"
}
tickers {
symbol = "ABC"
exchange = "NYSE"
symbol = "EXPC"
exchange = "NASDAQ"
}
external_system_url = "https://systemUrl.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package external_contacts

import (
"sync"
externalContactOrganization "terraform-provider-genesyscloud/genesyscloud/external_contacts_organization"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -31,6 +32,7 @@ func (r *registerTestInstance) registerTestResources() {
defer r.resourceMapMutex.Unlock()

providerResources[ResourceType] = ResourceExternalContact()
providerResources["genesyscloud_externalcontacts_organization"] = externalContactOrganization.ResourceExternalContactsOrganization()
}

// registerTestDataSources registers all data sources used in the tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ func readExternalContact(ctx context.Context, d *schema.ResourceData, meta inter
resourcedata.SetNillableValueWithInterfaceArrayWithFunc(d, "facebook_id", externalContact.FacebookId, flattenSdkFacebookId)
resourcedata.SetNillableValue(d, "survey_opt_out", externalContact.SurveyOptOut)
resourcedata.SetNillableValue(d, "external_system_url", externalContact.ExternalSystemUrl)
if externalContact.ExternalOrganization != nil && externalContact.ExternalOrganization.Id != nil {
_ = d.Set("external_organization_id", externalContact.ExternalOrganization.Id)
}

log.Printf("Read external contact %s", d.Id())

return cc.CheckState(d)
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package external_contacts

import (
externalContactsOrganization "terraform-provider-genesyscloud/genesyscloud/external_contacts_organization"
"terraform-provider-genesyscloud/genesyscloud/provider"
resourceExporter "terraform-provider-genesyscloud/genesyscloud/resource_exporter"
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register"
Expand Down Expand Up @@ -320,6 +321,11 @@ func ResourceExternalContact() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"external_organization_id": {
Description: "External organization for this external contact",
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand All @@ -329,7 +335,7 @@ func ExternalContactExporter() *resourceExporter.ResourceExporter {
return &resourceExporter.ResourceExporter{
GetResourcesFunc: provider.GetAllWithPooledClient(getAllAuthExternalContacts),
RefAttrs: map[string]*resourceExporter.RefAttrSettings{
"external_organization": {}, //Need to add this when we external orgs implemented
"external_organization_id": {RefType: externalContactsOrganization.ResourceType},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package external_contacts

import (
"fmt"
"github.com/google/uuid"
"strconv"
externalContactOrganization "terraform-provider-genesyscloud/genesyscloud/external_contacts_organization"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
Expand Down Expand Up @@ -162,6 +165,118 @@ func TestAccResourceExternalContacts(t *testing.T) {
})
}

func TestAccResourceExternalContactsOrganizationRef(t *testing.T) {
var (
organizationResourceLabel1 = "external_organization_test"
organizationResourcePath1 = externalContactOrganization.ResourceType + "." + organizationResourceLabel1
name1 = "ABCCorp-" + uuid.NewString()
phoneDisplay1 = "+1 321-700-1243"
countryCode1 = "US"
address1 = "1011 New Hope St"
city1 = "Norristown"
state1 = "PA"
postalCode1 = "19401"
twitterId1 = "twitterId"
twitterName1 = "twitterName"
twitterScreenName1 = "twitterScreenname"
symbol1 = "ABC"
exchange1 = "NYSE"
tags1 = []string{
strconv.Quote("news"),
strconv.Quote("channel"),
}

organizationResourceLabel2 = "new_external_organization"
organizationResourcePath2 = externalContactOrganization.ResourceType + "." + organizationResourceLabel2
name2 = "NewCorp-" + uuid.NewString()
phoneDisplay2 = "+1 321-990-9876"
countryCode2 = "US"
address2 = "65 Upper Street"
city2 = "Springfield"
state2 = "MO"
postalCode2 = "67890"
twitterId2 = "twitterId2"
twitterName2 = "twitterName2"
twitterScreenName2 = "twitterScreenname2"
symbol2 = "NEW"
exchange2 = "NYSE"
tags2 = []string{
strconv.Quote("SWE"),
strconv.Quote("development"),
}
)
var (
contactResourceLabel = "testing_contact"
contactResourcePath = ResourceType + "." + contactResourceLabel
title = "testing team"
title2 = "dev team"
externalContactOrganizationResource1 = externalContactOrganization.GenerateBasicExternalOrganizationResource(
organizationResourceLabel1,
name1,
phoneDisplay1, countryCode1,
address1, city1, state1, postalCode1, countryCode1,
twitterId1, twitterName1, twitterScreenName1,
symbol1, exchange1,
tags1,
"",
)
externalContactOrganizationResource2 = externalContactOrganization.GenerateBasicExternalOrganizationResource(
organizationResourceLabel2,
name2,
phoneDisplay2, countryCode2,
address2, city2, state2, postalCode2, countryCode2,
twitterId2, twitterName2, twitterScreenName2,
symbol2, exchange2,
tags2,
"",
)
)
resource.Test(t, resource.TestCase{
PreCheck: func() { util.TestAccPreCheck(t) },
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
//Create
Config: externalContactOrganizationResource1 +
GenerateBasicExternalContactResource(
contactResourceLabel,
title,
"external_organization_id = "+organizationResourcePath1+".id",
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(contactResourcePath, "title", title),
resource.TestCheckResourceAttrPair(
organizationResourcePath1, "id",
contactResourcePath, "external_organization_id",
),
),
},
{
//Update
Config: externalContactOrganizationResource2 + GenerateBasicExternalContactResource(
contactResourceLabel,
title2,
"external_organization_id = "+organizationResourcePath2+".id",
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(contactResourcePath, "title", title2),
resource.TestCheckResourceAttrPair(
organizationResourcePath2, "id",
contactResourcePath, "external_organization_id",
),
),
},
{
// Import/Read
ResourceName: contactResourcePath,
ImportState: true,
ImportStateVerify: true,
},
},
CheckDestroy: testVerifyContactDestroyed,
})
}

func generateFullExternalContactResource(
resourceLabel string,
firstname string, middlename string, lastname string, title string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package external_contacts

import (
"fmt"
"strings"
"terraform-provider-genesyscloud/genesyscloud/util"
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata"

Expand Down Expand Up @@ -29,8 +30,9 @@ func getExternalContactFromResourceData(d *schema.ResourceData) platformclientv2
otherEmail := d.Get("other_email").(string)
surveyOptOut := d.Get("survey_opt_out").(bool)
externalSystemUrl := d.Get("external_system_url").(string)
externalOrganizationId := d.Get("external_organization_id").(string)

return platformclientv2.Externalcontact{
externalContact := platformclientv2.Externalcontact{
FirstName: &firstName,
MiddleName: &middleName,
LastName: &lastName,
Expand All @@ -51,6 +53,12 @@ func getExternalContactFromResourceData(d *schema.ResourceData) platformclientv2
SurveyOptOut: &surveyOptOut,
ExternalSystemUrl: &externalSystemUrl,
}

if externalOrganizationId != "" {
externalContact.ExternalOrganization = &platformclientv2.Externalorganization{Id: &externalOrganizationId}
}

return externalContact
}

// buildPhonenumberFromData is a helper method to map phone data to the GenesysCloud platformclientv2.PhoneNumber
Expand Down Expand Up @@ -332,9 +340,10 @@ func hashFormattedPhoneNumber(val string) int {
return schema.HashString(formattedNumber)
}

func GenerateBasicExternalContactResource(resourceLabel string, title string) string {
func GenerateBasicExternalContactResource(resourceLabel string, title string, extras ...string) string {
return fmt.Sprintf(`resource "genesyscloud_externalcontacts_contact" "%s" {
title = "%s"
%s
}
`, resourceLabel, title)
`, resourceLabel, title, strings.Join(extras, "\n"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func updateExternalContactsOrganization(ctx context.Context, d *schema.ResourceD
proxy := getExternalContactsOrganizationProxy(sdkConfig)

externalContactsOrganization, err := getExternalContactsOrganizationFromResourceData(d)

if err != nil {
return util.BuildDiagnosticError(ResourceType, fmt.Sprintf("failed to build external organization error: %s", err), nil)
}
Expand Down
Loading

0 comments on commit 9eb24cd

Please sign in to comment.