// Prepare ready the resource pre-requisites.
Prepare ready the resource pre-requisites.
// Prepare ready the resource pre - requisites .
func (r *Resource) Prepare(rawConfig map[string]interface{}) error {
	var c Config
	var md mapstructure.Metadata
	defer func() {
		if r := recover(); r != nil {
			log.Fatalln(r)
		}
	}()
	clogger.Warn("Gathering Information...")
	if err := mapstructure.DecodeMetadata(rawConfig, &c, &md); err != nil {
		return err
	}
	r.Config = c
	r.Config.SrcAmiInfo = prepareSrcAmiInfo(r.Config.Source)
	sess, err := awscommon.GetAwsSession(r.Config.SrcAmiInfo.CredsInfo)
	if err != nil {
		return err
	}
	svc := sts.New(sess)
	callerInfo, err := awscommon.GetCallerInfo(svc)
	if err != nil {
		return err
	}
	iamSVC := iam.New(sess)
	accountAlias, err := awscommon.GetAccountAlias(iamSVC)
	if err != nil {
		return err
	}
	r.Config.SrcAmiInfo.AccountID = callerInfo.Account
	r.Config.SrcAmiInfo.AccountAlias = accountAlias
	regions := r.Config.Target.getTargetRegions()
	r.Config.SrcAmiInfo.RegionalRecord = make(map[*string]awscommon.AmiMeta)
	r.Config.SrcAmiInfo.AccountRecord = make(map[*string]AccountImage)
	if err := r.Config.SrcAmiInfo.prepareTargetRegionAmiMapping(regions); err != nil {
		for region, amiInfo := range r.Config.SrcAmiInfo.RegionAmiErrMap {
			if amiInfo.Error != nil {
				clogger.Infof("Source AMI Not Found In Account: %s Region: %s", *r.Config.SrcAmiInfo.AccountID, *region)
				clogger.Error(amiInfo.Error)
			}
		}
		return fmt.Errorf("failed: To Get Source AMI Information For Some Region(s)")
	}
	r.prepareAccountRegionMappingList()
	r.Config.Target.setCommonPropertiesIfAny()
	clogger.Success("Successfully Gathered All Info Needed For Source")
	clogger.Info("")
	return nil
}
func ( r * Resource ) Prepare ( rawConfig map [ string ] interface { } ) error { var c Config var md mapstructure . Metadata defer func ( ) { if r := recover ( ) ; r != nil { log . Fatalln ( r ) } } ( ) clogger . Warn ( " " ) if err := mapstructure . DecodeMetadata ( rawConfig , & c , & md ) ; err != nil { return err } r . Config = c r . Config . SrcAmiInfo = prepareSrcAmiInfo ( r . Config . Source ) sess , err := awscommon . GetAwsSession ( r . Config . SrcAmiInfo . CredsInfo ) if err != nil { return err } svc := sts . New ( sess ) callerInfo , err := awscommon . GetCallerInfo ( svc ) if err != nil { return err } iamSVC := iam . New ( sess ) accountAlias , err := awscommon . GetAccountAlias ( iamSVC ) if err != nil { return err } r . Config . SrcAmiInfo . AccountID = callerInfo . Account r . Config . SrcAmiInfo . AccountAlias = accountAlias regions := r . Config . Target . getTargetRegions ( ) r . Config . SrcAmiInfo . RegionalRecord = make ( map [ * string ] awscommon . AmiMeta ) r . Config . SrcAmiInfo . AccountRecord = make ( map [ * string ] AccountImage ) if err := r . Config . SrcAmiInfo . prepareTargetRegionAmiMapping ( regions ) ; err != nil { for region , amiInfo := range r . Config . SrcAmiInfo . RegionAmiErrMap { if amiInfo . Error != nil { clogger . Infof ( " " , * r . Config . SrcAmiInfo . AccountID , * region ) clogger . Error ( amiInfo . Error ) } } return fmt . Errorf ( " " ) } r . prepareAccountRegionMappingList ( ) r . Config . Target . setCommonPropertiesIfAny ( ) clogger . Success ( " " ) clogger . Info ( " " ) return nil }
Prepare ready the resource pre-requisites.
Prepare ready the resource pre - requisites .
// Initialize record store.