diff --git a/builtin/providers/aws/provider.go b/builtin/providers/aws/provider.go new file mode 100644 index 000000000..d343ff370 --- /dev/null +++ b/builtin/providers/aws/provider.go @@ -0,0 +1,20 @@ +package aws + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +// Provider returns a schema.Provider for AWS. +// +// NOTE: schema.Provider became available long after the AWS provider +// was started, so resources may not be converted to this new structure +// yet. This is a WIP. To assist with the migration, make sure any resources +// you migrate are acceptance tested, then perform the migration. +func Provider() *schema.Provider { + // TODO: Move the validation to this, requires conditional schemas + // TODO: Move the configuration to this, requires validation + + return &schema.Provider{ + ResourcesMap: map[string]*schema.Resource{}, + } +} diff --git a/builtin/providers/aws/provider_test.go b/builtin/providers/aws/provider_test.go new file mode 100644 index 000000000..480c88bf8 --- /dev/null +++ b/builtin/providers/aws/provider_test.go @@ -0,0 +1,11 @@ +package aws + +import ( + "testing" +) + +func TestProvider(t *testing.T) { + if err := Provider().InternalValidate(); err != nil { + t.Fatalf("err: %s", err) + } +} diff --git a/builtin/providers/aws/resource_provider.go b/builtin/providers/aws/resource_provider.go index 92a7b544c..1d9b1b3bc 100644 --- a/builtin/providers/aws/resource_provider.go +++ b/builtin/providers/aws/resource_provider.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform/helper/config" "github.com/hashicorp/terraform/helper/multierror" + "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/goamz/autoscaling" "github.com/mitchellh/goamz/ec2" @@ -24,6 +25,10 @@ type ResourceProvider struct { s3conn *s3.S3 rdsconn *rds.Rds route53 *route53.Route53 + + // This is the schema.Provider. Eventually this will replace much + // of this structure. For now it is an element of it for compatiblity. + p *schema.Provider } func (p *ResourceProvider) Validate(c *terraform.ResourceConfig) ([]string, []error) { @@ -98,26 +103,44 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error { return &multierror.Error{Errors: errs} } + // Create the provider, set the meta + p.p = Provider() + p.p.SetMeta(p) + return nil } func (p *ResourceProvider) Apply( s *terraform.ResourceState, d *terraform.ResourceDiff) (*terraform.ResourceState, error) { + if _, ok := p.p.ResourcesMap[s.Type]; ok { + return p.p.Apply(s, d) + } + return resourceMap.Apply(s, d, p) } func (p *ResourceProvider) Diff( s *terraform.ResourceState, c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) { + if _, ok := p.p.ResourcesMap[s.Type]; ok { + return p.p.Diff(s, c) + } + return resourceMap.Diff(s, c, p) } func (p *ResourceProvider) Refresh( s *terraform.ResourceState) (*terraform.ResourceState, error) { + if _, ok := p.p.ResourcesMap[s.Type]; ok { + return p.p.Refresh(s) + } + return resourceMap.Refresh(s, p) } func (p *ResourceProvider) Resources() []terraform.ResourceType { - return resourceMap.Resources() + result := resourceMap.Resources() + result = append(result, p.p.Resources()...) + return result } diff --git a/builtin/providers/aws/resource_provider_test.go b/builtin/providers/aws/resource_provider_test.go index d3393caeb..b376f62b8 100644 --- a/builtin/providers/aws/resource_provider_test.go +++ b/builtin/providers/aws/resource_provider_test.go @@ -52,6 +52,13 @@ func TestResourceProvider_Configure(t *testing.T) { if !reflect.DeepEqual(rp.Config, expected) { t.Fatalf("bad: %#v", rp.Config) } + + if rp.p == nil { + t.Fatal("provider should be set") + } + if !reflect.DeepEqual(rp, rp.p.Meta()) { + t.Fatalf("meta should be set") + } } func TestResourceProvider_ConfigureBadRegion(t *testing.T) {