github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/heroku/resource_heroku_pipeline_coupling.go (about) 1 package heroku 2 3 import ( 4 "context" 5 "fmt" 6 "log" 7 8 "github.com/cyberdelia/heroku-go/v3" 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func resourceHerokuPipelineCoupling() *schema.Resource { 13 return &schema.Resource{ 14 Create: resourceHerokuPipelineCouplingCreate, 15 Read: resourceHerokuPipelineCouplingRead, 16 Delete: resourceHerokuPipelineCouplingDelete, 17 18 Schema: map[string]*schema.Schema{ 19 "app": { 20 Type: schema.TypeString, 21 Required: true, 22 ForceNew: true, 23 }, 24 "pipeline": { 25 Type: schema.TypeString, 26 Required: true, 27 ForceNew: true, 28 ValidateFunc: validateUUID, 29 }, 30 "stage": { 31 Type: schema.TypeString, 32 Required: true, 33 ForceNew: true, 34 ValidateFunc: validatePipelineStageName, 35 }, 36 }, 37 } 38 } 39 40 func resourceHerokuPipelineCouplingCreate(d *schema.ResourceData, meta interface{}) error { 41 client := meta.(*heroku.Service) 42 43 opts := heroku.PipelineCouplingCreateOpts{ 44 App: d.Get("app").(string), 45 Pipeline: d.Get("pipeline").(string), 46 Stage: d.Get("stage").(string), 47 } 48 49 log.Printf("[DEBUG] PipelineCoupling create configuration: %#v", opts) 50 51 p, err := client.PipelineCouplingCreate(context.TODO(), opts) 52 if err != nil { 53 return fmt.Errorf("Error creating pipeline: %s", err) 54 } 55 56 d.SetId(p.ID) 57 58 log.Printf("[INFO] PipelineCoupling ID: %s", d.Id()) 59 60 return resourceHerokuPipelineCouplingRead(d, meta) 61 } 62 63 func resourceHerokuPipelineCouplingDelete(d *schema.ResourceData, meta interface{}) error { 64 client := meta.(*heroku.Service) 65 66 log.Printf("[INFO] Deleting pipeline: %s", d.Id()) 67 68 _, err := client.PipelineCouplingDelete(context.TODO(), d.Id()) 69 if err != nil { 70 return fmt.Errorf("Error deleting pipeline: %s", err) 71 } 72 73 return nil 74 } 75 76 func resourceHerokuPipelineCouplingRead(d *schema.ResourceData, meta interface{}) error { 77 client := meta.(*heroku.Service) 78 79 p, err := client.PipelineCouplingInfo(context.TODO(), d.Id()) 80 if err != nil { 81 return fmt.Errorf("Error retrieving pipeline: %s", err) 82 } 83 84 d.Set("app", p.App) 85 d.Set("pipeline", p.Pipeline) 86 d.Set("stage", p.Stage) 87 88 return nil 89 }