providers/aws: create an empty schema.Provider
This commit is contained in:
parent
968a567499
commit
776bb22e4e
|
@ -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{},
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProvider(t *testing.T) {
|
||||
if err := Provider().InternalValidate(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue