// CreateResources attempts to dynamically create the supplied resources.
// This function returns `trace.AlreadyExistsError` if one or more resources
// would be overwritten, and `trace.NotImplementedError` if any resources
// are of an unsupported type (see `ItemsFromResources(...)`).
//
// NOTE: This function is non-atomic and performs no internal synchronization;
// backend must be locked by caller when operating in parallel environment.
CreateResources attempts to dynamically create the supplied resources.
This function returns `trace.AlreadyExistsError` if one or more resources
would be overwritten, and `trace.NotImplementedError` if any resources
are of an unsupported type `).

This function is non-atomic and performs no internal synchronization;
backend must be locked by caller when operating in parallel environment.
// CreateResources attempts to dynamically create the supplied resources . // This function returns ` trace . AlreadyExistsError ` if one or more resources // would be overwritten and ` trace . NotImplementedError ` if any resources // are of an unsupported type ( see ` ItemsFromResources ( ... ) ` ) . // // NOTE : This function is non - atomic and performs no internal synchronization ; // backend must be locked by caller when operating in parallel environment .
func CreateResources(ctx context.Context, b backend.Backend, resources ...services.Resource) error {
	items, err := ItemsFromResources(resources...)
	if err != nil {
		return trace.Wrap(err)
	}
	for _, item := range items {
		_, err = b.Get(ctx, item.Key)
		if !trace.IsNotFound(err) {
			if err != nil {
				return trace.Wrap(err)
			}
			return trace.AlreadyExists("resource %q already exists", string(item.Key))
		}
	}
	for _, item := range items {
		_, err := b.Create(ctx, item)
		if err != nil {
			return trace.Wrap(err)
		}
	}
	return nil
}
func CreateResources ( ctx context . Context , b backend . Backend , resources ... services . Resource ) error { items , err := ItemsFromResources ( resources ... ) if err != nil { return trace . Wrap ( err ) } for _ , item := range items { _ , err = b . Get ( ctx , item . Key ) if ! trace . IsNotFound ( err ) { if err != nil { return trace . Wrap ( err ) } return trace . AlreadyExists ( " " , string ( item . Key ) ) } } for _ , item := range items { _ , err := b . Create ( ctx , item ) if err != nil { return trace . Wrap ( err ) } } return nil }
CreateResources attempts to dynamically create the supplied resources.
CreateResources attempts to dynamically create the supplied resources .
// ensure all items do not exist before continuing. // create all items.