diff --git a/builtin/bins/provider-zip/main.go b/builtin/bins/provider-archive/main.go similarity index 56% rename from builtin/bins/provider-zip/main.go rename to builtin/bins/provider-archive/main.go index fd7dd9709159..994b5776b36d 100644 --- a/builtin/bins/provider-zip/main.go +++ b/builtin/bins/provider-archive/main.go @@ -1,12 +1,12 @@ package main import ( - "github.com/hashicorp/terraform/builtin/providers/zip" + "github.com/hashicorp/terraform/builtin/providers/archive" "github.com/hashicorp/terraform/plugin" ) func main() { plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: zip.Provider, + ProviderFunc: archive.Provider, }) } diff --git a/builtin/providers/archive/archive-content.zip b/builtin/providers/archive/archive-content.zip new file mode 100644 index 000000000000..be74d13a7667 Binary files /dev/null and b/builtin/providers/archive/archive-content.zip differ diff --git a/builtin/providers/archive/archive-dir.zip b/builtin/providers/archive/archive-dir.zip new file mode 100644 index 000000000000..1780db33a342 Binary files /dev/null and b/builtin/providers/archive/archive-dir.zip differ diff --git a/builtin/providers/archive/archive-file.zip b/builtin/providers/archive/archive-file.zip new file mode 100644 index 000000000000..a8cdb575ddda Binary files /dev/null and b/builtin/providers/archive/archive-file.zip differ diff --git a/builtin/providers/zip/archiver.go b/builtin/providers/archive/archiver.go similarity index 98% rename from builtin/providers/zip/archiver.go rename to builtin/providers/archive/archiver.go index 935374523d3c..cdf2c3a68e46 100644 --- a/builtin/providers/zip/archiver.go +++ b/builtin/providers/archive/archiver.go @@ -1,4 +1,4 @@ -package zip +package archive import ( "fmt" diff --git a/builtin/providers/zip/provider.go b/builtin/providers/archive/provider.go similarity index 82% rename from builtin/providers/zip/provider.go rename to builtin/providers/archive/provider.go index d2cbf98cd1f3..1c968058ae74 100644 --- a/builtin/providers/zip/provider.go +++ b/builtin/providers/archive/provider.go @@ -1,4 +1,4 @@ -package zip +package archive import ( "github.com/hashicorp/terraform/helper/schema" @@ -10,7 +10,7 @@ func Provider() terraform.ResourceProvider { Schema: map[string]*schema.Schema{}, ResourcesMap: map[string]*schema.Resource{ - "zip_file": resourceZipFile(), + "archive_file": resourceArchiveFile(), }, } } diff --git a/builtin/providers/zip/provider_test.go b/builtin/providers/archive/provider_test.go similarity index 88% rename from builtin/providers/zip/provider_test.go rename to builtin/providers/archive/provider_test.go index 5489ec38f799..13cd92e3015a 100644 --- a/builtin/providers/zip/provider_test.go +++ b/builtin/providers/archive/provider_test.go @@ -1,4 +1,4 @@ -package zip +package archive import ( "testing" @@ -8,7 +8,7 @@ import ( ) var testProviders = map[string]terraform.ResourceProvider{ - "zip": Provider(), + "archive": Provider(), } func TestProvider(t *testing.T) { diff --git a/builtin/providers/zip/resource_zip_file.go b/builtin/providers/archive/resource_archive_file.go similarity index 83% rename from builtin/providers/zip/resource_zip_file.go rename to builtin/providers/archive/resource_archive_file.go index fd614ecd48f6..57534eed11ac 100644 --- a/builtin/providers/zip/resource_zip_file.go +++ b/builtin/providers/archive/resource_archive_file.go @@ -1,4 +1,4 @@ -package zip +package archive import ( "crypto/sha1" @@ -9,13 +9,13 @@ import ( "os" ) -func resourceZipFile() *schema.Resource { +func resourceArchiveFile() *schema.Resource { return &schema.Resource{ - Create: resourceZipFileCreate, - Read: resourceZipFileRead, - Update: resourceZipFileUpdate, - Delete: resourceZipFileDelete, - Exists: resourceZipFileExists, + Create: resourceArchiveFileCreate, + Read: resourceArchiveFileRead, + Update: resourceArchiveFileUpdate, + Delete: resourceArchiveFileDelete, + Exists: resourceArchiveFileExists, Schema: map[string]*schema.Schema{ "type": &schema.Schema{ @@ -66,14 +66,14 @@ func resourceZipFile() *schema.Resource { } } -func resourceZipFileCreate(d *schema.ResourceData, meta interface{}) error { - if err := resourceZipFileUpdate(d, meta); err != nil { +func resourceArchiveFileCreate(d *schema.ResourceData, meta interface{}) error { + if err := resourceArchiveFileUpdate(d, meta); err != nil { return err } - return resourceZipFileRead(d, meta) + return resourceArchiveFileRead(d, meta) } -func resourceZipFileRead(d *schema.ResourceData, meta interface{}) error { +func resourceArchiveFileRead(d *schema.ResourceData, meta interface{}) error { output_path := d.Get("output_path").(string) fi, err := os.Stat(output_path) if os.IsNotExist(err) { @@ -93,7 +93,7 @@ func resourceZipFileRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceZipFileUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceArchiveFileUpdate(d *schema.ResourceData, meta interface{}) error { archiveType := d.Get("type").(string) outputPath := d.Get("output_path").(string) @@ -137,7 +137,7 @@ func resourceZipFileUpdate(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceZipFileDelete(d *schema.ResourceData, meta interface{}) error { +func resourceArchiveFileDelete(d *schema.ResourceData, meta interface{}) error { output_path := d.Get("output_path").(string) fi, err := os.Stat(output_path) if os.IsNotExist(err) { @@ -151,7 +151,7 @@ func resourceZipFileDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceZipFileExists(d *schema.ResourceData, meta interface{}) (bool, error) { +func resourceArchiveFileExists(d *schema.ResourceData, meta interface{}) (bool, error) { output_path := d.Get("output_path").(string) _, err := os.Stat(output_path) if os.IsNotExist(err) { diff --git a/builtin/providers/archive/resource_archive_file_test.go b/builtin/providers/archive/resource_archive_file_test.go new file mode 100644 index 000000000000..eb6c47a9a4b6 --- /dev/null +++ b/builtin/providers/archive/resource_archive_file_test.go @@ -0,0 +1,92 @@ +package archive + +import ( + "fmt" + r "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "os" + "testing" +) + +func TestAccArchiveFile_Basic(t *testing.T) { + var fileSize string + r.Test(t, r.TestCase{ + Providers: testProviders, + CheckDestroy: r.ComposeTestCheckFunc( + testAccArchiveFileMissing("zip_file_acc_test.zip"), + ), + Steps: []r.TestStep{ + r.TestStep{ + Config: testAccArchiveFileContentConfig, + Check: r.ComposeTestCheckFunc( + testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), + r.TestCheckResourceAttrPtr("archive_file.foo", "output_size", &fileSize), + ), + }, + r.TestStep{ + Config: testAccArchiveFileFileConfig, + Check: r.ComposeTestCheckFunc( + testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), + r.TestCheckResourceAttrPtr("archive_file.foo", "output_size", &fileSize), + ), + }, + r.TestStep{ + Config: testAccArchiveFileDirConfig, + Check: r.ComposeTestCheckFunc( + testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize), + r.TestCheckResourceAttrPtr("archive_file.foo", "output_size", &fileSize), + ), + }, + }, + }) +} + +func testAccArchiveFileExists(filename string, fileSize *string) r.TestCheckFunc { + return func(s *terraform.State) error { + *fileSize = "" + fi, err := os.Stat(filename) + if err != nil { + return err + } + *fileSize = fmt.Sprintf("%d", fi.Size()) + return nil + } +} + +func testAccArchiveFileMissing(filename string) r.TestCheckFunc { + return func(s *terraform.State) error { + _, err := os.Stat(filename) + if err != nil { + if os.IsNotExist(err) { + return nil + } + return err + } + return fmt.Errorf("found file expected to be deleted: %s", filename) + } +} + +var testAccArchiveFileContentConfig = ` +resource "archive_file" "foo" { + type = "zip" + source_content = "This is some content" + source_content_filename = "content.txt" + output_path = "zip_file_acc_test.zip" +} +` + +var testAccArchiveFileFileConfig = ` +resource "archive_file" "foo" { + type = "zip" + source_file = "test-fixtures/test-file.txt" + output_path = "zip_file_acc_test.zip" +} +` + +var testAccArchiveFileDirConfig = ` +resource "archive_file" "foo" { + type = "zip" + source_dir = "test-fixtures/test-dir" + output_path = "zip_file_acc_test.zip" +} +` diff --git a/builtin/providers/archive/test-fixtures/test-dir/file1.txt b/builtin/providers/archive/test-fixtures/test-dir/file1.txt new file mode 100644 index 000000000000..28bf5b1fb91b --- /dev/null +++ b/builtin/providers/archive/test-fixtures/test-dir/file1.txt @@ -0,0 +1 @@ +This is file 1 \ No newline at end of file diff --git a/builtin/providers/archive/test-fixtures/test-dir/file2.txt b/builtin/providers/archive/test-fixtures/test-dir/file2.txt new file mode 100644 index 000000000000..4419d52b7a5c --- /dev/null +++ b/builtin/providers/archive/test-fixtures/test-dir/file2.txt @@ -0,0 +1 @@ +This is file 2 \ No newline at end of file diff --git a/builtin/providers/archive/test-fixtures/test-dir/file3.txt b/builtin/providers/archive/test-fixtures/test-dir/file3.txt new file mode 100644 index 000000000000..819cd4d4832e --- /dev/null +++ b/builtin/providers/archive/test-fixtures/test-dir/file3.txt @@ -0,0 +1 @@ +This is file 3 \ No newline at end of file diff --git a/builtin/providers/archive/test-fixtures/test-file.txt b/builtin/providers/archive/test-fixtures/test-file.txt new file mode 100644 index 000000000000..417be07f3a69 --- /dev/null +++ b/builtin/providers/archive/test-fixtures/test-file.txt @@ -0,0 +1 @@ +This is test content \ No newline at end of file diff --git a/builtin/providers/zip/zip_archiver.go b/builtin/providers/archive/zip_archiver.go similarity index 99% rename from builtin/providers/zip/zip_archiver.go rename to builtin/providers/archive/zip_archiver.go index 10ff996b62df..499c17e563de 100644 --- a/builtin/providers/zip/zip_archiver.go +++ b/builtin/providers/archive/zip_archiver.go @@ -1,4 +1,4 @@ -package zip +package archive import ( "archive/zip" diff --git a/builtin/providers/zip/zip_archiver_test.go b/builtin/providers/archive/zip_archiver_test.go similarity index 56% rename from builtin/providers/zip/zip_archiver_test.go rename to builtin/providers/archive/zip_archiver_test.go index 8ff731fd676e..5eb7a8a1591f 100644 --- a/builtin/providers/zip/zip_archiver_test.go +++ b/builtin/providers/archive/zip_archiver_test.go @@ -1,21 +1,13 @@ -package zip +package archive import ( "archive/zip" "io/ioutil" - "os" - "path/filepath" "testing" ) func TestZipArchiver_Content(t *testing.T) { - dir, err := createTestDestination() - if err != nil { - t.Fatalf("could not prepare temporary files: %s", err) - } - defer dropTestDestination(dir) - - zipfilepath := filepath.Join(dir, "content.zip") + zipfilepath := "archive-content.zip" archiver := NewZipArchiver(zipfilepath) if err := archiver.ArchiveContent([]byte("This is some content"), "content.txt"); err != nil { t.Fatalf("unexpected error: %s", err) @@ -27,18 +19,9 @@ func TestZipArchiver_Content(t *testing.T) { } func TestZipArchiver_File(t *testing.T) { - dir, err := createTestDestination() - if err != nil { - t.Fatalf("could not prepare temporary files: %s", err) - } - defer dropTestDestination(dir) - - testfilename := filepath.Join(dir, "test-file.txt") - ioutil.WriteFile(testfilename, []byte("This is test content"), os.FileMode(0666)) - - zipfilepath := filepath.Join(dir, "content.zip") + zipfilepath := "archive-file.zip" archiver := NewZipArchiver(zipfilepath) - if err := archiver.ArchiveFile(testfilename); err != nil { + if err := archiver.ArchiveFile("./test-fixtures/test-file.txt"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -48,21 +31,9 @@ func TestZipArchiver_File(t *testing.T) { } func TestZipArchiver_Dir(t *testing.T) { - dir, err := createTestDestination() - if err != nil { - t.Fatalf("could not prepare temporary files: %s", err) - } - defer dropTestDestination(dir) - - testdirpath := filepath.Join(dir, "contents") - os.MkdirAll(testdirpath, os.FileMode(0666)) - ioutil.WriteFile(filepath.Join(testdirpath, "file1.txt"), []byte("This is file 1"), os.FileMode(0666)) - ioutil.WriteFile(filepath.Join(testdirpath, "file2.txt"), []byte("This is file 2"), os.FileMode(0666)) - ioutil.WriteFile(filepath.Join(testdirpath, "file3.txt"), []byte("This is file 3"), os.FileMode(0666)) - - zipfilepath := filepath.Join(dir, "content.zip") + zipfilepath := "archive-dir.zip" archiver := NewZipArchiver(zipfilepath) - if err := archiver.ArchiveDir(testdirpath); err != nil { + if err := archiver.ArchiveDir("./test-fixtures/test-dir"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -73,14 +44,6 @@ func TestZipArchiver_Dir(t *testing.T) { }) } -func createTestDestination() (string, error) { - return ioutil.TempDir("./", "zip_archiver_") -} - -func dropTestDestination(dir string) { - os.RemoveAll(dir) -} - func ensureContents(t *testing.T, zipfilepath string, wants map[string][]byte) { r, err := zip.OpenReader(zipfilepath) if err != nil { diff --git a/builtin/providers/zip/resource_zip_file_test.go b/builtin/providers/zip/resource_zip_file_test.go deleted file mode 100644 index 7eb381d9722a..000000000000 --- a/builtin/providers/zip/resource_zip_file_test.go +++ /dev/null @@ -1,109 +0,0 @@ -package zip - -import ( - "fmt" - r "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" - "io/ioutil" - "os" - "path/filepath" - "testing" -) - -func TestAccZipFile_Basic(t *testing.T) { - // setup test content file - testfilename := "test_file.txt" - ioutil.WriteFile(testfilename, []byte("This is a test file"), os.FileMode(0666)) - defer func() { - os.Remove("test_file.txt") - }() - - // setup test content dir - testdirname := "test_dir" - os.MkdirAll(testdirname, os.FileMode(0666)) - ioutil.WriteFile(filepath.Join(testdirname, testfilename), []byte("This is a test file in a test dir"), os.FileMode(0666)) - defer func() { - os.RemoveAll(testdirname) - }() - - var fileSize string - r.Test(t, r.TestCase{ - Providers: testProviders, - CheckDestroy: r.ComposeTestCheckFunc( - testAccZipFileMissing("zip_file_acc_test.zip"), - ), - Steps: []r.TestStep{ - r.TestStep{ - Config: testAccZipFileContentConfig, - Check: r.ComposeTestCheckFunc( - testAccZipFileExists("zip_file_acc_test.zip", &fileSize), - r.TestCheckResourceAttrPtr("zip_file.foo", "output_size", &fileSize), - ), - }, - r.TestStep{ - Config: testAccZipFileFileConfig, - Check: r.ComposeTestCheckFunc( - testAccZipFileExists("zip_file_acc_test.zip", &fileSize), - r.TestCheckResourceAttrPtr("zip_file.foo", "output_size", &fileSize), - ), - }, - r.TestStep{ - Config: testAccZipFileDirConfig, - Check: r.ComposeTestCheckFunc( - testAccZipFileExists("zip_file_acc_test.zip", &fileSize), - r.TestCheckResourceAttrPtr("zip_file.foo", "output_size", &fileSize), - ), - }, - }, - }) -} - -func testAccZipFileExists(filename string, fileSize *string) r.TestCheckFunc { - return func(s *terraform.State) error { - *fileSize = "" - fi, err := os.Stat(filename) - if err != nil { - return err - } - *fileSize = fmt.Sprintf("%d", fi.Size()) - return nil - } -} - -func testAccZipFileMissing(filename string) r.TestCheckFunc { - return func(s *terraform.State) error { - _, err := os.Stat(filename) - if err != nil { - if os.IsNotExist(err) { - return nil - } - return err - } - return fmt.Errorf("found file expected to be deleted: %s", filename) - } -} - -var testAccZipFileContentConfig = ` -resource "zip_file" "foo" { - type = "zip" - source_content = "This is some content" - source_content_filename = "content.txt" - output_path = "zip_file_acc_test.zip" -} -` - -var testAccZipFileFileConfig = ` -resource "zip_file" "foo" { - type = "zip" - source_file = "test_file.txt" - output_path = "zip_file_acc_test.zip" -} -` - -var testAccZipFileDirConfig = ` -resource "zip_file" "foo" { - type = "zip" - source_dir = "test_dir" - output_path = "zip_file_acc_test.zip" -} -` diff --git a/command/internal_plugin_list.go b/command/internal_plugin_list.go index 51749c481eae..e1e9205ccc2f 100644 --- a/command/internal_plugin_list.go +++ b/command/internal_plugin_list.go @@ -48,7 +48,7 @@ import ( ultradnsprovider "github.com/hashicorp/terraform/builtin/providers/ultradns" vcdprovider "github.com/hashicorp/terraform/builtin/providers/vcd" vsphereprovider "github.com/hashicorp/terraform/builtin/providers/vsphere" - zipprovider "github.com/hashicorp/terraform/builtin/providers/zip" + archiveprovider "github.com/hashicorp/terraform/builtin/providers/archive" chefresourceprovisioner "github.com/hashicorp/terraform/builtin/provisioners/chef" fileresourceprovisioner "github.com/hashicorp/terraform/builtin/provisioners/file" localexecresourceprovisioner "github.com/hashicorp/terraform/builtin/provisioners/local-exec" @@ -101,7 +101,7 @@ var InternalProviders = map[string]plugin.ProviderFunc{ "ultradns": ultradnsprovider.Provider, "vcd": vcdprovider.Provider, "vsphere": vsphereprovider.Provider, - "zip": zipprovider.Provider, + "archive": archiveprovider.Provider, } var InternalProvisioners = map[string]plugin.ProvisionerFunc{ diff --git a/website/source/docs/providers/archive/index.html.markdown b/website/source/docs/providers/archive/index.html.markdown new file mode 100644 index 000000000000..d4169db668e0 --- /dev/null +++ b/website/source/docs/providers/archive/index.html.markdown @@ -0,0 +1,20 @@ +--- +layout: "archive" +page_title: "Provider: Archive" +sidebar_current: "docs-archive-index" +description: |- + The Archive provider is used to manage archive files. +--- + +# Archive Provider + +The archive provider exposes resources to manage archive files. + +Use the navigation to the left to read about the available resources. + +## Example Usage + +``` +provider "archive" { +} +``` diff --git a/website/source/docs/providers/zip/r/file.html.md b/website/source/docs/providers/archive/r/file.html.md similarity index 85% rename from website/source/docs/providers/zip/r/file.html.md rename to website/source/docs/providers/archive/r/file.html.md index 8e3d9b103d77..f5af4d9564c7 100644 --- a/website/source/docs/providers/zip/r/file.html.md +++ b/website/source/docs/providers/archive/r/file.html.md @@ -1,19 +1,19 @@ --- -layout: "zip" -page_title: "Zip: zip_file" -sidebar_current: "docs-zip-resource-file" +layout: "archive" +page_title: "Archive: archive_file" +sidebar_current: "docs-archive-resource-file" description: |- Generates an archive from content, a file, or directory of files. --- -# zip\_file +# archive\_file Generates an archive from content, a file, or directory of files. ## Example Usage ``` -resource "zip_file" "init" { +resource "archive_file" "init" { template = "${file("${path.module}/init.tpl")}" } ``` @@ -25,7 +25,7 @@ The following arguments are supported: NOTE: One of `source_content_filename` (with `source_content`), `source_file`, or `source_dir` must be specified. * `type` - (required) The type of archive to generate. - NOTE: `zip` is supported. + NOTE: `archive` is supported. * `output_path` - (required) The output of the archive file. diff --git a/website/source/docs/providers/zip/index.html.markdown b/website/source/docs/providers/zip/index.html.markdown deleted file mode 100644 index e2dc6ab269b1..000000000000 --- a/website/source/docs/providers/zip/index.html.markdown +++ /dev/null @@ -1,20 +0,0 @@ ---- -layout: "zip" -page_title: "Provider: Zip" -sidebar_current: "docs-zip-index" -description: |- - The Zip provider is used to manage archive files. ---- - -# Zip Provider - -The zip provider exposes resources to manage archive files. - -Use the navigation to the left to read about the available resources. - -## Example Usage - -``` -provider "zip" { -} -``` diff --git a/website/source/layouts/zip.erb b/website/source/layouts/archive.erb similarity index 59% rename from website/source/layouts/zip.erb rename to website/source/layouts/archive.erb index 722407fd5062..07565d2c4839 100644 --- a/website/source/layouts/zip.erb +++ b/website/source/layouts/archive.erb @@ -6,15 +6,15 @@ « Documentation Home -