Reputation: 662
I want to create GCS bucket with versioning.
I created sub-module.
resource "google_storage_bucket" "cloud_storage" {
project = "${var.project}"
name = "${var.storage_name}"
location = "${var.location}"
storage_class = "${var.storage_class}"
versioning = "${var.versioning}"
}
As per Terraform doc, I can pass versioning arguments to configure versioning.
I don't know what kind of data versioning argument accepts. I tried passing bool (true), map and list as follow.
map
variable "versioning" {
type = list
default = {
generation = true,
metageneration = true
}
}
List
variable "versioning" {
type = list
default = [
"generation",
"metageneration"
]
description = "Enable versioning on Bucket"
}
I tried this after reading this GCP Doc
Error error I am getting it as below.
Error: Unsupported argument
on ../modules/storage/main.tf line 6, in resource "google_storage_bucket" "cloud_storage":
6: versioning = "${var.versioning}"
An argument named "versioning" is not expected here. Did you mean to define a
block of type "versioning"?
The module works fine, if I don't use versioning arguments. But, I want to create module which can configure versioning too.
Please let me know if I am going in wrong direction.
Any help would be appreciated.
Upvotes: 2
Views: 3762
Reputation: 41
The error message is indicating that the versioning argument is a block (not a map), thus including the '=' confuses Terraform.
Use:
resource "google_storage_bucket" "foo" {
...
versioning {
enabled = true
}
}
NOT
resource "google_storage_bucket" "foo" {
...
versioning = {
enabled = true
}
}
Upvotes: 4