// backendConfig returns the local configuration for the backend
backendConfig returns the local configuration for the backend
// backendConfig returns the local configuration for the backend
func (m *Meta) backendConfig(opts *BackendOpts) (*configs.Backend, int, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	if opts.Config == nil {
		conf, moreDiags := m.loadBackendConfig(".")
		diags = diags.Append(moreDiags)
		if moreDiags.HasErrors() {
			return nil, 0, diags
		}
		if conf == nil {
			log.Println("[TRACE] Meta.Backend: no config given or present on disk, so returning nil config")
			return nil, 0, nil
		}
		log.Printf("[TRACE] Meta.Backend: BackendOpts.Config not set, so using settings loaded from %s", conf.DeclRange)
		opts.Config = conf
	}
	c := opts.Config
	if c == nil {
		log.Println("[TRACE] Meta.Backend: no explicit backend config, so returning nil config")
		return nil, 0, nil
	}
	bf := backendInit.Backend(c.Type)
	if bf == nil {
		diags = diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Invalid backend type",
			Detail:   fmt.Sprintf("There is no backend type named %q.", c.Type),
			Subject:  &c.TypeRange,
		})
		return nil, 0, diags
	}
	b := bf()
	configSchema := b.ConfigSchema()
	configBody := c.Config
	configHash := c.Hash(configSchema)
	if opts.ConfigOverride != nil {
		log.Println("[TRACE] Meta.Backend: merging -backend-config=... CLI overrides into backend configuration")
		configBody = configs.MergeBodies(configBody, opts.ConfigOverride)
	}
	log.Printf("[TRACE] Meta.Backend: built configuration for %q backend with hash value %d", c.Type, configHash)
	configCopy := *c
	configCopy.Config = configBody
	return &configCopy, configHash, diags
}
func ( m * Meta ) backendConfig ( opts * BackendOpts ) ( * configs . Backend , int , tfdiags . Diagnostics ) { var diags tfdiags . Diagnostics if opts . Config == nil { conf , moreDiags := m . loadBackendConfig ( " " ) diags = diags . Append ( moreDiags ) if moreDiags . HasErrors ( ) { return nil , 0 , diags } if conf == nil { log . Println ( " " ) return nil , 0 , nil } log . Printf ( " " , conf . DeclRange ) opts . Config = conf } c := opts . Config if c == nil { log . Println ( " " ) return nil , 0 , nil } bf := backendInit . Backend ( c . Type ) if bf == nil { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : fmt . Sprintf ( " " , c . Type ) , Subject : & c . TypeRange , } ) return nil , 0 , diags } b := bf ( ) configSchema := b . ConfigSchema ( ) configBody := c . Config configHash := c . Hash ( configSchema ) if opts . ConfigOverride != nil { log . Println ( " " ) configBody = configs . MergeBodies ( configBody , opts . ConfigOverride ) } log . Printf ( " " , c . Type , configHash ) configCopy := * c configCopy . Config = configBody return & configCopy , configHash , diags }
backendConfig returns the local configuration for the backend
backendConfig returns the local configuration for the backend
// check if the config was missing, or just not required // If we have an override configuration body then we must apply it now. // We'll shallow-copy configs.Backend here so that we can replace the // body without affecting others that hold this reference.