terraform/builtin/providers/consul/resource_provider.go

68 lines
1.5 KiB
Go
Raw Normal View History

2014-07-25 23:03:17 +02:00
package consul
import (
"log"
"github.com/armon/consul-api"
"github.com/hashicorp/terraform/helper/config"
"github.com/hashicorp/terraform/terraform"
)
type ResourceProvider struct {
Config Config
client *consulapi.Client
}
func (p *ResourceProvider) Validate(c *terraform.ResourceConfig) ([]string, []error) {
v := &config.Validator{
Optional: []string{
"datacenter",
"address",
},
}
return v.Validate(c)
}
func (p *ResourceProvider) ValidateResource(
t string, c *terraform.ResourceConfig) ([]string, []error) {
2014-07-26 21:14:41 +02:00
return resourceMap.Validate(t, c)
2014-07-25 23:03:17 +02:00
}
func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
if _, err := config.Decode(&p.Config, c.Config); err != nil {
return err
}
2014-07-26 04:14:48 +02:00
log.Printf("[INFO] Initializing Consul client")
2014-07-25 23:03:17 +02:00
var err error
p.client, err = p.Config.Client()
if err != nil {
return err
}
return nil
}
func (p *ResourceProvider) Apply(
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.ResourceDiff) (*terraform.InstanceState, error) {
return resourceMap.Apply(info, s, d, p)
2014-07-25 23:03:17 +02:00
}
func (p *ResourceProvider) Diff(
info *terraform.InstanceInfo,
s *terraform.InstanceState,
2014-07-25 23:03:17 +02:00
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return resourceMap.Diff(info, s, c, p)
2014-07-25 23:03:17 +02:00
}
func (p *ResourceProvider) Refresh(
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
return resourceMap.Refresh(info, s, p)
2014-07-25 23:03:17 +02:00
}
func (p *ResourceProvider) Resources() []terraform.ResourceType {
return resourceMap.Resources()
}