-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement archive provider and "archive_file" resource.
- Loading branch information
Brad Sickles
committed
Jun 25, 2016
1 parent
3c1d8e9
commit 143ecec
Showing
21 changed files
with
157 additions
and
207 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
builtin/bins/provider-zip/main.go → builtin/bins/provider-archive/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion
2
builtin/providers/zip/archiver.go → builtin/providers/archive/archiver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package zip | ||
package archive | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is file 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is file 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is file 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is test content |
2 changes: 1 addition & 1 deletion
2
builtin/providers/zip/zip_archiver.go → builtin/providers/archive/zip_archiver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package zip | ||
package archive | ||
|
||
import ( | ||
"archive/zip" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.