"sync"
"github.com/hashicorp/go-multierror"
+ "github.com/hashicorp/terraform/config"
+ "github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/terraform"
)
meta interface{}
- // a mutex is required because TestReset can directly repalce the stopCtx
+ // a mutex is required because TestReset can directly replace the stopCtx
stopMu sync.Mutex
stopCtx context.Context
stopCtxCancel context.CancelFunc
stopOnce sync.Once
+
+ TerraformVersion string
}
// ConfigureFunc is the function used to configure a Provider.
validationErrors = multierror.Append(validationErrors, err)
}
+ // Provider-specific checks
+ for k, _ := range sm {
+ if isReservedProviderFieldName(k) {
+ return fmt.Errorf("%s is a reserved field name for a provider", k)
+ }
+ }
+
for k, r := range p.ResourcesMap {
if err := r.InternalValidate(nil, true); err != nil {
validationErrors = multierror.Append(validationErrors, fmt.Errorf("resource %s: %s", k, err))
return validationErrors
}
+func isReservedProviderFieldName(name string) bool {
+ for _, reservedName := range config.ReservedProviderFields {
+ if name == reservedName {
+ return true
+ }
+ }
+ return false
+}
+
// Meta returns the metadata associated with this provider that was
// returned by the Configure call. It will be nil until Configure is called.
func (p *Provider) Meta() interface{} {
return nil
}
+// GetSchema implementation of terraform.ResourceProvider interface
+func (p *Provider) GetSchema(req *terraform.ProviderSchemaRequest) (*terraform.ProviderSchema, error) {
+ resourceTypes := map[string]*configschema.Block{}
+ dataSources := map[string]*configschema.Block{}
+
+ for _, name := range req.ResourceTypes {
+ if r, exists := p.ResourcesMap[name]; exists {
+ resourceTypes[name] = r.CoreConfigSchema()
+ }
+ }
+ for _, name := range req.DataSources {
+ if r, exists := p.DataSourcesMap[name]; exists {
+ dataSources[name] = r.CoreConfigSchema()
+ }
+ }
+
+ return &terraform.ProviderSchema{
+ Provider: schemaMap(p.Schema).CoreConfigSchema(),
+ ResourceTypes: resourceTypes,
+ DataSources: dataSources,
+ }, nil
+}
+
// Input implementation of terraform.ResourceProvider interface.
func (p *Provider) Input(
input terraform.UIInput,
// Get a ResourceData for this configuration. To do this, we actually
// generate an intermediary "diff" although that is never exposed.
- diff, err := sm.Diff(nil, c)
+ diff, err := sm.Diff(nil, c, nil, p.meta, true)
if err != nil {
return err
}
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
}
- return r.Diff(s, c)
+ return r.Diff(s, c, p.meta)
+}
+
+// SimpleDiff is used by the new protocol wrappers to get a diff that doesn't
+// attempt to calculate ignore_changes.
+func (p *Provider) SimpleDiff(
+ info *terraform.InstanceInfo,
+ s *terraform.InstanceState,
+ c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
+ r, ok := p.ResourcesMap[info.Type]
+ if !ok {
+ return nil, fmt.Errorf("unknown resource type: %s", info.Type)
+ }
+
+ return r.simpleDiff(s, c, p.meta)
}
// Refresh implementation of terraform.ResourceProvider interface.
// Resources implementation of terraform.ResourceProvider interface.
func (p *Provider) Resources() []terraform.ResourceType {
keys := make([]string, 0, len(p.ResourcesMap))
- for k, _ := range p.ResourcesMap {
+ for k := range p.ResourcesMap {
keys = append(keys, k)
}
sort.Strings(keys)
result = append(result, terraform.ResourceType{
Name: k,
Importable: resource.Importer != nil,
+
+ // Indicates that a provider is compiled against a new enough
+ // version of core to support the GetSchema method.
+ SchemaAvailable: true,
})
}
return nil, fmt.Errorf("unknown data source: %s", info.Type)
}
- return r.Diff(nil, c)
+ return r.Diff(nil, c, p.meta)
}
// RefreshData implementation of terraform.ResourceProvider interface.
for _, k := range keys {
result = append(result, terraform.DataSource{
Name: k,
+
+ // Indicates that a provider is compiled against a new enough
+ // version of core to support the GetSchema method.
+ SchemaAvailable: true,
})
}