-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
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,22 @@ | ||
formatter: "markdown" | ||
output: | ||
file: "README.md" | ||
mode: inject | ||
template: |- | ||
<!-- BEGIN_TF_DOCS --> | ||
{{ .Content }} | ||
<!-- END_TF_DOCS --> | ||
settings: | ||
indent: 2 | ||
content: |- | ||
{{ .Requirements }} | ||
{{ .Providers }} | ||
{{ .Modules }} | ||
{{ .Resources }} | ||
{{ .Inputs }} | ||
{{ .Outputs }} |
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,45 @@ | ||
# Creates a local file | ||
|
||
Creates a single file if the file name does **not** exist. | ||
|
||
If the file already exists or has been modified, the Terraform state is only updated during `terraform apply`. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 | | ||
| <a name="requirement_local"></a> [local](#requirement\_local) | >= 2.4.1 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.4.1 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [local_file.this](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_content"></a> [content](#input\_content) | Content to store in the file, expected to be a UTF-8 encoded string. | `string` | n/a | yes | | ||
| <a name="input_directory_permission"></a> [directory\_permission](#input\_directory\_permission) | Permissions to set for directories created (before umask), expressed as string in numeric notation. Default value is 0755. | `string` | `"0755"` | no | | ||
| <a name="input_file_permission"></a> [file\_permission](#input\_file\_permission) | Permissions to set for the output file (before umask), expressed as string in numeric notation. Default value is 0644. | `string` | `"0644"` | no | | ||
| <a name="input_filename"></a> [filename](#input\_filename) | The path to the file that will be created. Missing parent directories will be created. If the file already exists, it will NOT be overridden. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_file_id"></a> [file\_id](#output\_file\_id) | The hexadecimal encoding of the SHA1 checksum of the file content. | | ||
<!-- END_TF_DOCS --> |
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 @@ | ||
# Examples |
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,25 @@ | ||
formatter: "markdown" | ||
output: | ||
file: "README.md" | ||
mode: inject | ||
template: |- | ||
<!-- BEGIN_TF_DOCS --> | ||
{{ .Content }} | ||
<!-- END_TF_DOCS --> | ||
settings: | ||
indent: 2 | ||
content: |- | ||
```hcl | ||
{{ include "main.tf" }} | ||
``` | ||
{{ .Providers }} | ||
{{ .Modules }} | ||
{{ .Resources }} | ||
{{ .Inputs }} | ||
{{ .Outputs }} |
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,73 @@ | ||
# Creates a local file | ||
|
||
Creates a single file. | ||
|
||
Run: | ||
|
||
```bash | ||
echo "Test" > /tmp/test | ||
chmod 644 /tmp/test | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
## Example | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
|
||
```hcl | ||
# Example | ||
locals { | ||
new_file_name = "/tmp/${random_pet.this.id}" | ||
existing_file_name = "/tmp/test" | ||
} | ||
# Creates new file | ||
module "new_file" { | ||
source = "../../" | ||
filename = local.new_file_name | ||
content = "Test" | ||
} | ||
# Does not create a file (file name already exists) | ||
# Note: Terraform state will be updated if necessary (first apply). | ||
module "existing_file" { | ||
source = "../../" | ||
filename = local.existing_file_name | ||
content = "Overwrite" | ||
} | ||
# Helper | ||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
``` | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_existing_file"></a> [existing\_file](#module\_existing\_file) | ../../ | n/a | | ||
| <a name="module_new_file"></a> [new\_file](#module\_new\_file) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
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,25 @@ | ||
# Example | ||
locals { | ||
new_file_name = "/tmp/${random_pet.this.id}" | ||
existing_file_name = "/tmp/test" | ||
} | ||
|
||
# Creates new file | ||
module "new_file" { | ||
source = "../../" | ||
filename = local.new_file_name | ||
content = "Test" | ||
} | ||
|
||
# Does not create a file (file name already exists) | ||
# Note: Terraform state will be updated if necessary (first apply). | ||
module "existing_file" { | ||
source = "../../" | ||
filename = local.existing_file_name | ||
content = "Overwrite" | ||
} | ||
|
||
# Helper | ||
resource "random_pet" "this" { | ||
length = 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,10 @@ | ||
terraform { | ||
required_version = ">= 1.5.7" | ||
|
||
required_providers { | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 3.6" | ||
} | ||
} | ||
} |
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,11 @@ | ||
locals { | ||
content = fileexists(var.filename) ? file(var.filename) : var.content | ||
} | ||
|
||
resource "local_file" "this" { | ||
# Create file only if file does not exists | ||
file_permission = var.file_permission | ||
directory_permission = var.directory_permission | ||
filename = var.filename | ||
content = local.content | ||
} |
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,4 @@ | ||
output "file_id" { | ||
description = "The hexadecimal encoding of the SHA1 checksum of the file content." | ||
value = try(local_file.this.id, null) | ||
} |
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,21 @@ | ||
variable "filename" { | ||
description = "The path to the file that will be created. Missing parent directories will be created. If the file already exists, it will NOT be overridden." | ||
type = string | ||
} | ||
|
||
variable "content" { | ||
description = "Content to store in the file, expected to be a UTF-8 encoded string." | ||
type = string | ||
} | ||
|
||
variable "directory_permission" { | ||
description = "Permissions to set for directories created (before umask), expressed as string in numeric notation. Default value is 0755." | ||
type = string | ||
default = "0755" | ||
} | ||
|
||
variable "file_permission" { | ||
description = "Permissions to set for the output file (before umask), expressed as string in numeric notation. Default value is 0644." | ||
type = string | ||
default = "0644" | ||
} |
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,10 @@ | ||
terraform { | ||
required_version = ">= 1.5.7" | ||
|
||
required_providers { | ||
local = { | ||
source = "hashicorp/local" | ||
version = ">= 2.4.1" | ||
} | ||
} | ||
} |