(schemas map[addrs.Provider]*ProviderSchema, config *configs.Config, state *states.State, components contextComponentFactory)
| 96 | } |
| 97 | |
| 98 | func loadProviderSchemas(schemas map[addrs.Provider]*ProviderSchema, config *configs.Config, state *states.State, components contextComponentFactory) tfdiags.Diagnostics { |
| 99 | var diags tfdiags.Diagnostics |
| 100 | |
| 101 | ensure := func(fqn addrs.Provider) { |
| 102 | name := fqn.String() |
| 103 | |
| 104 | if _, exists := schemas[fqn]; exists { |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | log.Printf("[TRACE] LoadSchemas: retrieving schema for provider type %q", name) |
| 109 | provider, err := components.ResourceProvider(fqn) |
| 110 | if err != nil { |
| 111 | // We'll put a stub in the map so we won't re-attempt this on |
| 112 | // future calls. |
| 113 | schemas[fqn] = &ProviderSchema{} |
| 114 | diags = diags.Append( |
| 115 | fmt.Errorf("Failed to instantiate provider %q to obtain schema: %w", name, err), |
| 116 | ) |
| 117 | return |
| 118 | } |
| 119 | defer func() { |
| 120 | provider.Close(context.Background()) |
| 121 | }() |
| 122 | |
| 123 | resp := provider.GetProviderSchema(context.Background()) |
| 124 | if resp.Diagnostics.HasErrors() { |
| 125 | // We'll put a stub in the map so we won't re-attempt this on |
| 126 | // future calls. |
| 127 | schemas[fqn] = &ProviderSchema{} |
| 128 | diags = diags.Append( |
| 129 | fmt.Errorf("Failed to retrieve schema from provider %q: %w", name, resp.Diagnostics.Err()), |
| 130 | ) |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | s := &ProviderSchema{ |
| 135 | Provider: resp.Provider.Block, |
| 136 | ResourceTypes: make(map[string]*configschema.Block), |
| 137 | DataSources: make(map[string]*configschema.Block), |
| 138 | |
| 139 | ResourceTypeSchemaVersions: make(map[string]uint64), |
| 140 | } |
| 141 | |
| 142 | if resp.Provider.Version < 0 { |
| 143 | // We're not using the version numbers here yet, but we'll check |
| 144 | // for validity anyway in case we start using them in future. |
| 145 | diags = diags.Append( |
| 146 | fmt.Errorf("invalid negative schema version provider configuration for provider %q", name), |
| 147 | ) |
| 148 | } |
| 149 | |
| 150 | for t, r := range resp.ResourceTypes { |
| 151 | s.ResourceTypes[t] = r.Block |
| 152 | s.ResourceTypeSchemaVersions[t] = uint64(r.Version) |
| 153 | if r.Version < 0 { |
| 154 | diags = diags.Append( |
| 155 | fmt.Errorf("invalid negative schema version for resource type %s in provider %q", t, name), |
no test coverage detected