func FromProviderSchemaMap()

in provider-schema/azurerm/schema/core_schema.go [23:73]


func FromProviderSchemaMap(providerschemas map[string]*schema.Schema) *SchemaBlock {
	if len(providerschemas) == 0 {
		return &SchemaBlock{}
	}

	ret := &SchemaBlock{
		Attributes:   map[string]*SchemaAttribute{},
		NestedBlocks: map[string]*SchemaBlockType{},
	}

	for name, ps := range providerschemas {
		if ps.Elem == nil {
			ret.Attributes[name] = fromProviderSchemaAttribute(ps)
			continue
		}
		if ps.Type == schema.TypeMap {
			if _, isResource := ps.Elem.(*schema.Resource); isResource {
				sch := *ps
				sch.Elem = &schema.Schema{
					Type: schema.TypeString,
				}
				ret.Attributes[name] = fromProviderSchemaAttribute(&sch)
				continue
			}
		}
		switch ps.ConfigMode {
		case schema.SchemaConfigModeAttr:
			ret.Attributes[name] = fromProviderSchemaAttribute(ps)
		case schema.SchemaConfigModeBlock:
			ret.NestedBlocks[name] = fromProviderSchemaBlock(ps)
		default: // SchemaConfigModeAuto, or any other invalid value
			if ps.Computed && !ps.Optional {
				// Computed-only schemas are always handled as attributes,
				// because they never appear in configuration.
				ret.Attributes[name] = fromProviderSchemaAttribute(ps)
				continue
			}
			switch ps.Elem.(type) {
			case *schema.Schema, schema.ValueType:
				ret.Attributes[name] = fromProviderSchemaAttribute(ps)
			case *schema.Resource:
				ret.NestedBlocks[name] = fromProviderSchemaBlock(ps)
			default:
				// Should never happen for a valid schema
				panic(fmt.Errorf("invalid Schema.Elem %#v; need *schema.Schema or *schema.Resource", ps.Elem))
			}
		}
	}

	return ret
}