func resourceRage4RecordUpdate(d *schema.ResourceData, meta interface{}) error { // get which record we want to update recordId, err := strconv.Atoi(d.Id()) domain, err := strconv.Atoi(d.Get("domain").(string)) log.Printf("[INFO] Updating Rage4 Record %d in domain %s", recordId, domain) record := new(rage4.Record) record.Name = d.Get("name").(string) record.Content = d.Get("content").(string) record.Type = "A" client := meta.(*rage4.Client) _, err = client.UpdateRecord(recordId, *record) return err }
func resourceRage4RecordCreate(d *schema.ResourceData, meta interface{}) error { // get id of domain we are going to add server to value, _ := d.Get("domain").(string) log.Printf("[TRACE] domain = %s", value) domain := value // need to get domainId as that's what CreateRecord needs client := meta.(*rage4.Client) domainInfo, err := client.GetDomainByName(domain) if err != nil { fmt.Printf("[ERROR] could not find domain - %s", err) return fmt.Errorf("Could not find domain - %s", err) } if domainInfo.Id == 0 { fmt.Printf("[ERROR] domain Id = 0") return fmt.Errorf("Domain id is 0") } else { log.Printf("[INFO] domain Id = %d", domainInfo.Id) } // create new A record newRecord := new(rage4.Record) newRecord.Name = d.Get("name").(string) + "." + domainInfo.Name newRecord.Content = d.Get("content").(string) newRecord.Type = "A" // newRecord.TTL = d.Get("ttl") log.Printf("[DEBUG] Rage4 Record create configuration: %#v", newRecord) // ask Rage4 to add A record to domain status, err := client.CreateRecord(domainInfo.Id, *newRecord) if err != nil { return fmt.Errorf("Failed to create Rage4 Record: %s", err) } // need to extract record id & save recId := status.Id d.SetId(strconv.Itoa(recId)) log.Printf("[INFO] created record ID: %s", d.Id()) return nil }