11package archive
22
33import (
4+ "bytes"
45 "crypto/md5"
56 "crypto/sha1"
67 "crypto/sha256"
@@ -11,6 +12,7 @@ import (
1112 "os"
1213 "path"
1314
15+ "github.com/hashicorp/terraform/helper/hashcode"
1416 "github.com/hashicorp/terraform/helper/schema"
1517)
1618
@@ -24,6 +26,33 @@ func dataSourceFile() *schema.Resource {
2426 Required : true ,
2527 ForceNew : true ,
2628 },
29+ "source" : & schema.Schema {
30+ Type : schema .TypeSet ,
31+ Optional : true ,
32+ Computed : true ,
33+ Elem : & schema.Resource {
34+ Schema : map [string ]* schema.Schema {
35+ "content" : & schema.Schema {
36+ Type : schema .TypeString ,
37+ Required : true ,
38+ ForceNew : true ,
39+ },
40+ "filename" : & schema.Schema {
41+ Type : schema .TypeString ,
42+ Required : true ,
43+ ForceNew : true ,
44+ },
45+ },
46+ },
47+ ConflictsWith : []string {"source_file" , "source_dir" , "source_content" , "source_content_filename" },
48+ Set : func (v interface {}) int {
49+ var buf bytes.Buffer
50+ m := v .(map [string ]interface {})
51+ buf .WriteString (fmt .Sprintf ("%s-" , m ["filename" ].(string )))
52+ buf .WriteString (fmt .Sprintf ("%s-" , m ["content" ].(string )))
53+ return hashcode .String (buf .String ())
54+ },
55+ },
2756 "source_content" : & schema.Schema {
2857 Type : schema .TypeString ,
2958 Optional : true ,
@@ -138,6 +167,16 @@ func archive(d *schema.ResourceData) error {
138167 if err := archiver .ArchiveContent ([]byte (content ), filename .(string )); err != nil {
139168 return fmt .Errorf ("error archiving content: %s" , err )
140169 }
170+ } else if v , ok := d .GetOk ("source" ); ok {
171+ vL := v .(* schema.Set ).List ()
172+ content := make (map [string ][]byte )
173+ for _ , v := range vL {
174+ src := v .(map [string ]interface {})
175+ content [src ["filename" ].(string )] = []byte (src ["content" ].(string ))
176+ }
177+ if err := archiver .ArchiveMultiple (content ); err != nil {
178+ return fmt .Errorf ("error archiving content: %s" , err )
179+ }
141180 } else {
142181 return fmt .Errorf ("one of 'source_dir', 'source_file', 'source_content_filename' must be specified" )
143182 }
0 commit comments