func resourceMailginDomainRetrieve(id string, client *mailgun.Client, d *schema.ResourceData) (*mailgun.DomainResponse, error) {
	resp, err := client.RetrieveDomain(id)

	if err != nil {
		return nil, fmt.Errorf("Error retrieving domain: %s", err)
	}

	d.Set("name", resp.Domain.Name)
	d.Set("smtp_password", resp.Domain.SmtpPassword)
	d.Set("smtp_login", resp.Domain.SmtpLogin)
	d.Set("wildcard", resp.Domain.Wildcard)
	d.Set("spam_action", resp.Domain.SpamAction)

	receivingRecords := make([]map[string]interface{}, len(resp.ReceivingRecords))
	for i, r := range resp.ReceivingRecords {
		receivingRecords[i] = make(map[string]interface{})
		receivingRecords[i]["priority"] = r.Priority
		receivingRecords[i]["valid"] = r.Valid
		receivingRecords[i]["value"] = r.Value
		receivingRecords[i]["record_type"] = r.RecordType
	}
	d.Set("receiving_records", receivingRecords)

	sendingRecords := make([]map[string]interface{}, len(resp.SendingRecords))
	for i, r := range resp.SendingRecords {
		sendingRecords[i] = make(map[string]interface{})
		sendingRecords[i]["name"] = r.Name
		sendingRecords[i]["valid"] = r.Valid
		sendingRecords[i]["value"] = r.Value
		sendingRecords[i]["record_type"] = r.RecordType
	}
	d.Set("sending_records", sendingRecords)

	return &resp, nil
}
Exemplo n.º 2
0
func resource_mailgin_domain_retrieve(id string, client *mailgun.Client, d *schema.ResourceData) (*mailgun.DomainResponse, error) {
	resp, err := client.RetrieveDomain(id)

	if err != nil {
		return nil, fmt.Errorf("Error retrieving domain: %s", err)
	}

	d.Set("name", resp.Domain.Name)
	d.Set("smtp_password", resp.Domain.SmtpPassword)
	d.Set("smtp_login", resp.Domain.SmtpLogin)
	d.Set("wildcard", resp.Domain.Wildcard)
	d.Set("spam_action", resp.Domain.SpamAction)

	d.Set("receiving_records", make([]interface{}, len(resp.ReceivingRecords)))
	for i, r := range resp.ReceivingRecords {
		prefix := fmt.Sprintf("receiving_records.%d", i)
		d.Set(prefix+".priority", r.Priority)
		d.Set(prefix+".valid", r.Valid)
		d.Set(prefix+".value", r.Value)
		d.Set(prefix+".record_type", r.RecordType)
	}

	d.Set("sending_records", make([]interface{}, len(resp.SendingRecords)))
	for i, r := range resp.SendingRecords {
		prefix := fmt.Sprintf("sending_records.%d", i)
		d.Set(prefix+".name", r.Name)
		d.Set(prefix+".valid", r.Valid)
		d.Set(prefix+".value", r.Value)
		d.Set(prefix+".record_type", r.RecordType)
	}

	return &resp, nil
}
func resource_mailgin_domain_retrieve(id string, client *mailgun.Client, d *schema.ResourceData) (*mailgun.Domain, error) {
	domain, err := client.RetrieveDomain(id)

	if err != nil {
		return nil, fmt.Errorf("Error retrieving domain: %s", err)
	}

	d.Set("name", domain.Name)
	d.Set("smtp_password", domain.SmtpPassword)
	d.Set("smtp_login", domain.SmtpLogin)
	d.Set("wildcard", domain.Wildcard)
	d.Set("spam_action", domain.SpamAction)

	return &domain, nil
}