@@ -3,28 +3,29 @@ package resource
33import (
44 "context"
55 "fmt"
6+ "reflect"
7+ "strconv"
8+ "strings"
9+
610 "github.com/hashicorp/go-cty/cty"
711 "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
812 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
913 "github.com/inwx/terraform-provider-inwx/inwx/internal/api"
10- "reflect"
11- "strconv"
12- "strings"
1314)
1415
1516type Contact struct {
16- Type string
17- Name string
18- Organization string
19- StreetAddress string
20- City string
21- PostalCode string
22- StateProvince string
23- CountryCode string
24- PhoneNumber string
25- FaxNumber string
26- Email string
27- Remarks string
17+ Type string
18+ Name string
19+ Organization string
20+ StreetAddress string
21+ City string
22+ PostalCode string
23+ StateProvince string
24+ CountryCode string
25+ PhoneNumber string
26+ FaxNumber string
27+ Email string
28+ Remarks string
2829}
2930
3031func DomainContactResource () * schema.Resource {
@@ -144,15 +145,15 @@ func resourceContactCreate(ctx context.Context, data *schema.ResourceData, meta
144145 contact := expandContactFromResourceData (data )
145146
146147 parameters := map [string ]interface {}{
147- "type" : contact .Type ,
148- "name" : contact .Name ,
149- "street" : contact .StreetAddress ,
150- "city" : contact .City ,
151- "pc" : contact .PostalCode ,
152- "sp" : contact .StateProvince ,
153- "cc" : contact .CountryCode ,
154- "voice" : contact .PhoneNumber ,
155- "email" : contact .Email ,
148+ "type" : contact .Type ,
149+ "name" : contact .Name ,
150+ "street" : contact .StreetAddress ,
151+ "city" : contact .City ,
152+ "pc" : contact .PostalCode ,
153+ "sp" : contact .StateProvince ,
154+ "cc" : contact .CountryCode ,
155+ "voice" : contact .PhoneNumber ,
156+ "email" : contact .Email ,
156157 }
157158 if contact .Organization != "" {
158159 parameters ["org" ] = contact .Organization
@@ -187,13 +188,13 @@ func resourceContactCreate(ctx context.Context, data *schema.ResourceData, meta
187188 }
188189
189190 rawId := call ["resData" ].(map [string ]interface {})["id" ]
190- switch rawId .(type ) {
191+ switch id := rawId .(type ) {
191192 case string :
192193 // When contact already exists: id = string
193- data .SetId (rawId .( string ) )
194+ data .SetId (id )
194195 case float64 :
195196 // When contact does not already exist: id = float64 ...
196- data .SetId (strconv .Itoa (int (rawId .( float64 ) )))
197+ data .SetId (strconv .Itoa (int (id )))
197198 default :
198199 diags = append (diags , diag.Diagnostic {
199200 Severity : diag .Error ,
@@ -396,18 +397,18 @@ func expandContactFromResourceData(data *schema.ResourceData) *Contact {
396397 }
397398
398399 return & Contact {
399- Type : data .Get ("type" ).(string ),
400- Name : data .Get ("name" ).(string ),
401- Organization : organization ,
402- StreetAddress : data .Get ("street_address" ).(string ),
403- City : data .Get ("city" ).(string ),
404- PostalCode : data .Get ("postal_code" ).(string ),
405- StateProvince : stateProvince ,
406- CountryCode : data .Get ("country_code" ).(string ),
407- PhoneNumber : data .Get ("phone_number" ).(string ),
408- FaxNumber : fax ,
409- Email : data .Get ("email" ).(string ),
410- Remarks : remarks ,
400+ Type : data .Get ("type" ).(string ),
401+ Name : data .Get ("name" ).(string ),
402+ Organization : organization ,
403+ StreetAddress : data .Get ("street_address" ).(string ),
404+ City : data .Get ("city" ).(string ),
405+ PostalCode : data .Get ("postal_code" ).(string ),
406+ StateProvince : stateProvince ,
407+ CountryCode : data .Get ("country_code" ).(string ),
408+ PhoneNumber : data .Get ("phone_number" ).(string ),
409+ FaxNumber : fax ,
410+ Email : data .Get ("email" ).(string ),
411+ Remarks : remarks ,
411412 }
412413}
413414
@@ -430,17 +431,17 @@ func expandContactFromInfoResponse(contactData map[string]interface{}) *Contact
430431 }
431432
432433 return & Contact {
433- Type : contactData ["type" ].(string ),
434- Name : contactData ["name" ].(string ),
435- Organization : organization ,
436- StreetAddress : contactData ["street" ].(string ),
437- City : contactData ["city" ].(string ),
438- PostalCode : contactData ["pc" ].(string ),
439- StateProvince : stateProvince ,
440- CountryCode : contactData ["cc" ].(string ),
441- PhoneNumber : contactData ["voice" ].(string ),
442- FaxNumber : fax ,
443- Email : contactData ["email" ].(string ),
444- Remarks : remarks ,
434+ Type : contactData ["type" ].(string ),
435+ Name : contactData ["name" ].(string ),
436+ Organization : organization ,
437+ StreetAddress : contactData ["street" ].(string ),
438+ City : contactData ["city" ].(string ),
439+ PostalCode : contactData ["pc" ].(string ),
440+ StateProvince : stateProvince ,
441+ CountryCode : contactData ["cc" ].(string ),
442+ PhoneNumber : contactData ["voice" ].(string ),
443+ FaxNumber : fax ,
444+ Email : contactData ["email" ].(string ),
445+ Remarks : remarks ,
445446 }
446447}
0 commit comments