agent/taskresource/asmsecret/asmsecret.go
func (secret *ASMSecretResource) Create() error {

	// To fail fast, check execution role first
	executionCredentials, ok := secret.credentialsManager.GetTaskCredentials(secret.getExecutionCredentialsID())
	if !ok {
		// No need to log here. managedTask.applyResourceState already does that
		err := errors.New("ASM secret resource: unable to find execution role credentials")
		secret.setTerminalReason(err.Error())
		return err
	}
	iamCredentials := executionCredentials.GetIAMRoleCredentials()

	var wg sync.WaitGroup

	// Get the maximum number of errors to be returned, which will be one error per goroutine
	errorEvents := make(chan error, len(secret.requiredSecrets))

	seelog.Infof("ASM secret resource: retrieving secrets for containers in task: [%s]", secret.taskARN)
	secret.secretData = make(map[string]string)

	for _, asmsecret := range secret.getRequiredSecrets() {
		wg.Add(1)
		// Spin up goroutine per secret to speed up processing time
		go secret.retrieveASMSecretValue(asmsecret, iamCredentials, &wg, errorEvents)
	}

	wg.Wait()
	close(errorEvents)

	if len(errorEvents) > 0 {
		var terminalReasons []string
		for err := range errorEvents {
			terminalReasons = append(terminalReasons, err.Error())
		}

		errorString := strings.Join(terminalReasons, ";")
		secret.setTerminalReason(errorString)
		return errors.New(errorString)
	}
	return nil
}
func (secret *ASMSecretResource) Create() error {

	// To fail fast, check execution role first
	executionCredentials, ok := secret.credentialsManager.GetTaskCredentials(secret.getExecutionCredentialsID())
	if !ok {
		// No need to log here. managedTask.applyResourceState already does that
		err := errors.New("ASM secret resource: unable to find execution role credentials")
		secret.setTerminalReason(err.Error())
		return err
	}
	iamCredentials := executionCredentials.GetIAMRoleCredentials()

	var wg sync.WaitGroup

	// Get the maximum number of errors to be returned, which will be one error per goroutine
	errorEvents := make(chan error, len(secret.requiredSecrets))

	seelog.Infof("ASM secret resource: retrieving secrets for containers in task: [%s]", secret.taskARN)
	secret.secretData = make(map[string]string)

	for _, asmsecret := range secret.getRequiredSecrets() {
		wg.Add(1)
		// Spin up goroutine per secret to speed up processing time
		go secret.retrieveASMSecretValue(asmsecret, iamCredentials, &wg, errorEvents)
	}

	wg.Wait()
	close(errorEvents)

	if len(errorEvents) > 0 {
		var terminalReasons []string
		for err := range errorEvents {
			terminalReasons = append(terminalReasons, err.Error())
		}

		errorString := strings.Join(terminalReasons, ";")
		secret.setTerminalReason(errorString)
		return errors.New(errorString)
	}
	return nil
}
// It spins up multiple goroutines in order to retrieve values in parallel.