'Terraform plan fails due to content argument missing in local_file resource
I have been testing out something using the terraform for_each loop method and ran into this error with the local_file resource.
$ cat main.tf
resource "local_file" "pet" {
filename = each.value
for_each = var.filename
}
$ cat variables.tf
variable "filename" {
type = set(string)
default = [
"/home/user/pets.txt",
"/home/user/dogs.txt",
"/home/user/cats.txt"
]
}
when I run terraform plan
after init, I see the following errors:
$ terraform plan
╷
│ Error: Invalid combination of arguments
│
│ with local_file.pet,
│ on main.tf line 1, in resource "local_file" "pet":
│ 1: resource "local_file" "pet" {
│
│ "content_base64": one of `content,content_base64,sensitive_content,source` must be specified
╵
╷
│ Error: Invalid combination of arguments
│
│ with local_file.pet,
│ on main.tf line 1, in resource "local_file" "pet":
│ 1: resource "local_file" "pet" {
│
│ "source": one of `content,content_base64,sensitive_content,source` must be specified
╵
╷
│ Error: Invalid combination of arguments
│
│ with local_file.pet,
│ on main.tf line 1, in resource "local_file" "pet":
│ 1: resource "local_file" "pet" {
│
│ "content": one of `content,content_base64,sensitive_content,source` must be specified
╵
╷
│ Error: Invalid combination of arguments
│
│ with local_file.pet,
│ on main.tf line 1, in resource "local_file" "pet":
│ 1: resource "local_file" "pet" {
│
│ "sensitive_content": one of `content,content_base64,sensitive_content,source` must be specified
╵
From the documentation, I can see argument content
is optional:
so I am confused with the above error.
Solution 1:[1]
As the error message says:
one of
content,content_base64,sensitive_content,source
must be specified
The documentation states for each of content
, content_base64
, sensitive_content
, and source
, that they are optional but also that they do conflict with the other three of them, and it also does not specify a default value.
In consequence, you need to specify exactly one of these four arguments.
Also it makes much sense, as you need to define the content of the file you want to be created.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |