pulumi/pkg/resource/deploy/source_fixed.go
joeduffy 35aa6b7559 Rename pulumi/lumi to pulumi/pulumi-fabric
We are renaming Lumi to Pulumi Fabric.  This change simply renames the
pulumi/lumi repo to pulumi/pulumi-fabric, without the CLI tools and other
changes that will follow soon afterwards.
2017-08-02 09:25:22 -07:00

59 lines
1.4 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package deploy
import (
"github.com/pulumi/pulumi-fabric/pkg/resource"
"github.com/pulumi/pulumi-fabric/pkg/tokens"
)
// NewFixedSource returns a valid planning source that is comprised of a list of pre-computed resource objects.
func NewFixedSource(ctx tokens.Module, resources []*resource.Object) Source {
return &fixedSource{ctx: ctx, resources: resources}
}
// A fixedSource just returns from a fixed set of resource states.
type fixedSource struct {
ctx tokens.Module
resources []*resource.Object
}
func (src *fixedSource) Close() error {
return nil // nothing to do.
}
func (src *fixedSource) Info() interface{} {
return nil
}
func (src *fixedSource) Iterate() (SourceIterator, error) {
return &fixedSourceIterator{
src: src,
current: -1,
}, nil
}
// fixedSourceIterator always returns nil, nil in response to Next, indicating that it is done.
type fixedSourceIterator struct {
src *fixedSource
current int
}
func (iter *fixedSourceIterator) Close() error {
return nil // nothing to do.
}
func (iter *fixedSourceIterator) Produce(res *resource.Object) {
// ignore
}
func (iter *fixedSourceIterator) Next() (*SourceAllocation, *SourceQuery, error) {
iter.current++
if iter.current >= len(iter.src.resources) {
return nil, nil, nil
}
return &SourceAllocation{
Obj: iter.src.resources[iter.current],
Ctx: iter.src.ctx,
}, nil, nil
}