Merge pull request #3891 from nouney/f-generated-files
Add "generated" file tag to allow users to upload files created on the fly.
This commit is contained in:
commit
56dd8cdb63
|
@ -26,6 +26,9 @@ type Config struct {
|
||||||
// Direction
|
// Direction
|
||||||
Direction string
|
Direction string
|
||||||
|
|
||||||
|
// False if the sources have to exist.
|
||||||
|
Generated bool
|
||||||
|
|
||||||
ctx interpolate.Context
|
ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +64,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
|
|
||||||
if p.config.Direction == "upload" {
|
if p.config.Direction == "upload" {
|
||||||
for _, src := range p.config.Sources {
|
for _, src := range p.config.Sources {
|
||||||
if _, err := os.Stat(src); err != nil {
|
if _, err := os.Stat(src); p.config.Generated == false && err != nil {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
errs = packer.MultiErrorAppend(errs,
|
||||||
fmt.Errorf("Bad source '%s': %s", src, err))
|
fmt.Errorf("Bad source '%s': %s", src, err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,12 @@ func TestProvisionerPrepare_InvalidSource(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("should require existing file")
|
t.Fatalf("should require existing file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config["generated"] = false
|
||||||
|
err = p.Prepare(config)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should required existing file")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProvisionerPrepare_ValidSource(t *testing.T) {
|
func TestProvisionerPrepare_ValidSource(t *testing.T) {
|
||||||
|
@ -58,11 +64,28 @@ func TestProvisionerPrepare_ValidSource(t *testing.T) {
|
||||||
|
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
config["source"] = tf.Name()
|
config["source"] = tf.Name()
|
||||||
|
|
||||||
err = p.Prepare(config)
|
err = p.Prepare(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should allow valid file: %s", err)
|
t.Fatalf("should allow valid file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config["generated"] = false
|
||||||
|
err = p.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should allow valid file: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProvisionerPrepare_GeneratedSource(t *testing.T) {
|
||||||
|
var p Provisioner
|
||||||
|
|
||||||
|
config := testConfig()
|
||||||
|
config["source"] = "/this/should/not/exist"
|
||||||
|
config["generated"] = true
|
||||||
|
err := p.Prepare(config)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should allow non-existing file: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProvisionerPrepare_EmptyDestination(t *testing.T) {
|
func TestProvisionerPrepare_EmptyDestination(t *testing.T) {
|
||||||
|
|
|
@ -48,6 +48,9 @@ The available configuration options are listed below. All elements are required.
|
||||||
"upload". If it is set to "download" then the file "source" in the machine
|
"upload". If it is set to "download" then the file "source" in the machine
|
||||||
will be downloaded locally to "destination"
|
will be downloaded locally to "destination"
|
||||||
|
|
||||||
|
- `generated` (boolean) - If true, check the file existence only before uploading.
|
||||||
|
This allows to upload files created on-the-fly. This defaults to false.
|
||||||
|
|
||||||
## Directory Uploads
|
## Directory Uploads
|
||||||
|
|
||||||
The file provisioner is also able to upload a complete directory to the remote
|
The file provisioner is also able to upload a complete directory to the remote
|
||||||
|
|
Loading…
Reference in New Issue