diff --git a/DESIGN.md b/DESIGN.md index c3776e31..77d6b1f2 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -1,7 +1,7 @@ # Archive Provider Design -The Archive Provider offers focussed functionality specifically geared towards archiving files. Specifically, -the provider data source generates zip archives of individual or multiple files. +The Archive Provider offers focussed functionality specifically geared towards archiving files. The provider generates +zip archives of individual or multiple files. Below we have a collection of _Goals_ and _Patterns_: they represent the guiding principles applied during the development of this provider. Some are in place, others are ongoing processes, others are still just inspirational. @@ -9,7 +9,7 @@ development of this provider. Some are in place, others are ongoing processes, o ## Goals * [_Stability over features_](.github/CONTRIBUTING.md) -* Provide data source for generating zip archives. +* Provide a mechanism for generating zip archives. General to development: diff --git a/docs/resources/file.md b/docs/resources/file.md index 11ab1c66..e8dad5bd 100644 --- a/docs/resources/file.md +++ b/docs/resources/file.md @@ -1,16 +1,56 @@ --- -# generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "archive_file Resource - terraform-provider-archive" subcategory: "" description: |- - NOTE: This resource is deprecated, use data source instead. + Generates an archive from content, a file, or directory of files. --- # archive_file (Resource) -**NOTE**: This resource is deprecated, use data source instead. +Generates an archive from content, a file, or directory of files. +## Example Usage +```terraform +# Archive a single file. + +resource "archive_file" "init" { + type = "zip" + source_file = "${path.module}/init.tpl" + output_path = "${path.module}/files/init.zip" +} +``` + +```terraform +# Archive multiple files and exclude file. + +resource "archive_file" "dotfiles" { + type = "zip" + output_path = "${path.module}/files/dotfiles.zip" + excludes = ["${path.module}/unwanted.zip"] + + source { + content = data.template_file.vimrc.rendered + filename = ".vimrc" + } + + source { + content = data.template_file.ssh_config.rendered + filename = ".ssh/config" + } +} +``` + +```terraform +# Archive a file to be used with Lambda using consistent file mode + +resource "archive_file" "lambda_my_function" { + type = "zip" + source_file = "${path.module}/../lambda/my-function/index.js" + output_file_mode = "0666" + output_path = "${path.module}/files/lambda-my-function.js.zip" +} +``` ## Schema diff --git a/examples/resources/file/lambda.tf b/examples/resources/file/lambda.tf new file mode 100644 index 00000000..5d7b8e46 --- /dev/null +++ b/examples/resources/file/lambda.tf @@ -0,0 +1,8 @@ +# Archive a file to be used with Lambda using consistent file mode + +resource "archive_file" "lambda_my_function" { + type = "zip" + source_file = "${path.module}/../lambda/my-function/index.js" + output_file_mode = "0666" + output_path = "${path.module}/files/lambda-my-function.js.zip" +} diff --git a/examples/resources/file/multiple-files.tf b/examples/resources/file/multiple-files.tf new file mode 100644 index 00000000..3a138319 --- /dev/null +++ b/examples/resources/file/multiple-files.tf @@ -0,0 +1,17 @@ +# Archive multiple files and exclude file. + +resource "archive_file" "dotfiles" { + type = "zip" + output_path = "${path.module}/files/dotfiles.zip" + excludes = ["${path.module}/unwanted.zip"] + + source { + content = data.template_file.vimrc.rendered + filename = ".vimrc" + } + + source { + content = data.template_file.ssh_config.rendered + filename = ".ssh/config" + } +} diff --git a/examples/resources/file/resource.tf b/examples/resources/file/resource.tf new file mode 100644 index 00000000..8a4963de --- /dev/null +++ b/examples/resources/file/resource.tf @@ -0,0 +1,7 @@ +# Archive a single file. + +resource "archive_file" "init" { + type = "zip" + source_file = "${path.module}/init.tpl" + output_path = "${path.module}/files/init.zip" +} diff --git a/internal/provider/resource_archive_file.go b/internal/provider/resource_archive_file.go index 22368fe6..fe06d56f 100644 --- a/internal/provider/resource_archive_file.go +++ b/internal/provider/resource_archive_file.go @@ -44,8 +44,7 @@ func (d *archiveFileResource) ConfigValidators(context.Context) []resource.Confi func (d *archiveFileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - Description: `**NOTE**: This resource is deprecated, use data source instead.`, - DeprecationMessage: `**NOTE**: This resource is deprecated, use data source instead.`, + Description: "Generates an archive from content, a file, or directory of files.", Blocks: map[string]schema.Block{ "source": schema.SetNestedBlock{ Description: "Specifies attributes of a single source file to include into the archive. " + diff --git a/templates/resources/file.md.tmpl b/templates/resources/file.md.tmpl new file mode 100644 index 00000000..a99c1089 --- /dev/null +++ b/templates/resources/file.md.tmpl @@ -0,0 +1,20 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +--- + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +## Example Usage + +{{ tffile "examples/resources/file/resource.tf" }} + +{{ tffile "examples/resources/file/multiple-files.tf" }} + +{{ tffile "examples/resources/file/lambda.tf" }} + +{{ .SchemaMarkdown | trimspace }}