// Initiailizing an unchanged saved backend
Initiailizing an unchanged saved backend
// Initiailizing an unchanged saved backend
func (m *Meta) backend_C_r_S_unchanged(c *configs.Backend, cHash int, sMgr *clistate.LocalState) (backend.Backend, tfdiags.Diagnostics) {
	var diags tfdiags.Diagnostics
	s := sMgr.State()
	if c != nil && s.Backend.Hash != uint64(cHash) {
		s.Backend.Hash = uint64(cHash)
		if err := sMgr.WriteState(s); err != nil {
			diags = diags.Append(err)
			return nil, diags
		}
	}
	f := backendInit.Backend(s.Backend.Type)
	if f == nil {
		diags = diags.Append(fmt.Errorf(strings.TrimSpace(errBackendSavedUnknown), s.Backend.Type))
		return nil, diags
	}
	b := f()
	schema := b.ConfigSchema()
	configVal, err := s.Backend.Config(schema)
	if err != nil {
		diags = diags.Append(tfdiags.Sourceless(
			tfdiags.Error,
			"Failed to decode current backend config",
			fmt.Sprintf("The backend configuration created by the most recent run of \"terraform init\" could not be decoded: %s. The configuration may have been initialized by an earlier version that used an incompatible configuration structure. Run \"terraform init -reconfigure\" to force re-initialization of the backend.", err),
		))
		return nil, diags
	}
	newVal, validDiags := b.PrepareConfig(configVal)
	diags = diags.Append(validDiags)
	if validDiags.HasErrors() {
		return nil, diags
	}
	configDiags := b.Configure(newVal)
	diags = diags.Append(configDiags)
	if configDiags.HasErrors() {
		return nil, diags
	}
	return b, diags
}
func ( m * Meta ) backend_C_r_S_unchanged ( c * configs . Backend , cHash int , sMgr * clistate . LocalState ) ( backend . Backend , tfdiags . Diagnostics ) { var diags tfdiags . Diagnostics s := sMgr . State ( ) if c != nil && s . Backend . Hash != uint64 ( cHash ) { s . Backend . Hash = uint64 ( cHash ) if err := sMgr . WriteState ( s ) ; err != nil { diags = diags . Append ( err ) return nil , diags } } f := backendInit . Backend ( s . Backend . Type ) if f == nil { diags = diags . Append ( fmt . Errorf ( strings . TrimSpace ( errBackendSavedUnknown ) , s . Backend . Type ) ) return nil , diags } b := f ( ) schema := b . ConfigSchema ( ) configVal , err := s . Backend . Config ( schema ) if err != nil { diags = diags . Append ( tfdiags . Sourceless ( tfdiags . Error , " " , fmt . Sprintf ( " \" \" \" \" " , err ) , ) ) return nil , diags } newVal , validDiags := b . PrepareConfig ( configVal ) diags = diags . Append ( validDiags ) if validDiags . HasErrors ( ) { return nil , diags } configDiags := b . Configure ( newVal ) diags = diags . Append ( configDiags ) if configDiags . HasErrors ( ) { return nil , diags } return b , diags }
Initiailizing an unchanged saved backend
Initiailizing an unchanged saved backend
// it's possible for a backend to be unchanged, and the config itself to // have changed by moving a parameter from the config to `-backend-config` // In this case we only need to update the Hash. // Get the backend // The configuration saved in the working directory state file is used // in this case, since it will contain any additional values that // were provided via -backend-config arguments on terraform init. // Validate the config and then configure the backend