diff --git a/builtin/providers/mailgun/resource_mailgun_domain.go b/builtin/providers/mailgun/resource_mailgun_domain.go index d08fbb639..6a56f34da 100644 --- a/builtin/providers/mailgun/resource_mailgun_domain.go +++ b/builtin/providers/mailgun/resource_mailgun_domain.go @@ -46,6 +46,56 @@ func resourceMailgunDomain() *schema.Resource { ForceNew: true, Optional: true, }, + + "receiving_records": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "priority": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "record_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "valid": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "value": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + + "sending_records": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "record_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "valid": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "value": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, } } @@ -121,5 +171,25 @@ func resource_mailgin_domain_retrieve(id string, client *mailgun.Client, d *sche d.Set("wildcard", resp.Domain.Wildcard) d.Set("spam_action", resp.Domain.SpamAction) + log.Println(resp.ReceivingRecords) + + 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 } diff --git a/builtin/providers/mailgun/resource_mailgun_domain_test.go b/builtin/providers/mailgun/resource_mailgun_domain_test.go index a55cabab5..2da07240f 100644 --- a/builtin/providers/mailgun/resource_mailgun_domain_test.go +++ b/builtin/providers/mailgun/resource_mailgun_domain_test.go @@ -30,6 +30,10 @@ func TestAccMailgunDomain_Basic(t *testing.T) { "mailgun_domain.foobar", "smtp_password", "foobar"), resource.TestCheckResourceAttr( "mailgun_domain.foobar", "wildcard", "true"), + resource.TestCheckResourceAttr( + "mailgun_domain.foobar", "receiving_records.0.priority", "10"), + resource.TestCheckResourceAttr( + "mailgun_domain.foobar", "sending_records.0.name", "terraform.example.com"), ), }, }, @@ -73,6 +77,14 @@ func testAccCheckMailgunDomainAttributes(DomainResp *mailgun.DomainResponse) res return fmt.Errorf("Bad smtp_password: %s", DomainResp.Domain.SmtpPassword) } + if DomainResp.ReceivingRecords[0].Priority == "" { + return fmt.Errorf("Bad receiving_records: %s", DomainResp.ReceivingRecords) + } + + if DomainResp.SendingRecords[0].Name == "" { + return fmt.Errorf("Bad sending_records: %s", DomainResp.SendingRecords) + } + return nil } }