Comments (6)
I have two projects, Project A and Project B and under each Project, I would like two create multiple buckets using same terraform script and state file
Based on your modules/storage/main.tf
you will need to invoke module "usis-auto-test-bucket"
twice to pass in different project_id.
module "usis-auto-test-bucket-project1"{
...
project_id = "project-1-id"
names = ["foo","bar"]
}
module "usis-auto-test-bucket-project2"{
...
project_id = "project-2-id"
names = ["baz","qux"]
}
from terraform-google-cloud-storage.
can you be more specific what value are you referring to here as "whenever a new value is passed" I see moreorless your issue is the way you are structuring , we do the same scenario as that you referred but we extensively avoid modules but we have structured our infra entities through folder structures and our jenkins pipeline understands our folder structure, but it depends from use case to use case
from terraform-google-cloud-storage.
I was passing buket_name from Jenkins pipeline to terraform, so that team members can create any bucket, with any value they want. Goal is to create multiple buckets using same terraform script for different projects.
config.tf
terraform {
backend "gcs" {
bucket = "test-bucket-state"
prefix = "terraform/test-bucket/"
}
}
main.tf
module "usis-auto-test-bucket" {
source = "./modules/storage"
names = "${var.bucket_name}"
project = "project_id_value
labels = merge(var.tf_labels, {
app_id = "" # app_id must be from SNow CMDB
component_labels = "none"
tier = "app"
costcenter = "$1234"
name = "none" # Name of the Microservice
})
versioning = var.versioning
encryption = {
default_kms_key_name = var.kms_key_name_auto
}
lifecycle_rule = [
{
condition = {
matches_storage_class = ["REGIONAL"]
}
action = {
type = "Delete"
}
}
]
}
modules/storage/main.tf - resource being referred by above module
resource "google_storage_bucket" "bucket" {
count = var.enabled ? 1 : 0
name = var.names
project = var.project
dynamic "versioning" {
for_each = var.versioning
content {
enabled = versioning.key == "enabled" ? versioning.value : false
}
}
labels = merge(var.labels, {
terraform_module_version = "v1-0-4"
terraform_module_git = "bitbucket_terraform_repo"
is_public = "no"
})
dynamic "encryption" {
for_each = var.encryption
content {
default_kms_key_name = encryption.key == "default_kms_key_name" ? encryption.value : null
}
}
dynamic "lifecycle_rule" {
for_each = var.lifecycle_rule
content {
action {
type = lookup(lifecycle_rule.value["action"], "type", null)
storage_class = lookup(lifecycle_rule.value["action"], "storage_class", null)
}
condition {
age = lookup(lifecycle_rule.value["condition"], "age", null)
created_before = lookup(lifecycle_rule.value["condition"], "created_before", null)
with_state = lookup(lifecycle_rule.value["condition"], "with_state", null)
matches_storage_class = lookup(lifecycle_rule.value["condition"], "matches_storage_class", null)
num_newer_versions = lookup(lifecycle_rule.value["condition"], "num_newer_versions", null)
}
}
}
}
from terraform-google-cloud-storage.
I have two projects, Project A and Project B and under each Project, I would like two create multiple buckets using same terraform script and state file
Based on your
modules/storage/main.tf
you will need to invokemodule "usis-auto-test-bucket"
twice to pass in different project_id.module "usis-auto-test-bucket-project1"{ ... project_id = "project-1-id" names = ["foo","bar"] } module "usis-auto-test-bucket-project2"{ ... project_id = "project-2-id" names = ["baz","qux"] }
@bharathkkb Thanks for your response.I have followed what you have mentioned and see an error mentioned below, and am using terraform v 0.12.20 here.
Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.
Error: Invalid expression
<value for var.names> line 1:
(source code not available)
Expected the start of an expression, but found an invalid expression token.
Error: No value for required variable on vars.tf line 7: variable "names"
The root module input variable "names" is not set, and has no default value.
Use a -var or -var-file command line argument to provide a value for this
variable.
Here is my updated code
main.tf
module "usis-auto-test-bucket" {
source = "./modules/storage"
names = ["test-bucket-1", "test-bucket-2"]
.
.
.
}
modules/storage/main.tf - resource being referred by above module
resource "google_storage_bucket" "bucket" {
count = var.enabled ? 1 : 0
name = "${var.names}"
.
.
.
}
variables.tf
variable "names" {
description = "Names of the buckets to create."
type = list(string)
}
from terraform-google-cloud-storage.
@MounicaRamini resource "google_storage_bucket" "bucket"
cannot take in a list of strings as names. My example above was when using this cft module in particular. I would also recommend you use for_each
instead of count
to iterate over bucket names.
It also seems to be complaining about interpolation, which can be fixed by"${var.names}"
=> var.names
.
from terraform-google-cloud-storage.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days
from terraform-google-cloud-storage.
Related Issues (20)
- CI failing
- Add support for public_access_prevention
- Provisioning fails when creating buckets with labels: "Provider produced inconsistent final plan" HOT 4
- Allow configure the autoclass argument HOT 2
- Include a matches_prefix variable in this module HOT 2
- Specifying `bucket_admins` has no effect HOT 3
- Fix documentation for encryption_key_names variable HOT 1
- Doesn't work with apple silicone HOT 1
- Set versioning for all buckets in module HOT 1
- bucket_lifecycle_rules cannot be used without specifying lifecycle_rules
- The "logging" input parameter is not taken into account HOT 1
- On module "buckets", using action type "SetStorageClass" on the "lifecycle_rules" is not working HOT 10
- Dependency requirement conflict when using this module along GKE module HOT 2
- Allow CORS and website configurations only for one bucket HOT 8
- matches_prefix on gcs lifecycle management not working with terraform HOT 1
- Support for configuring soft-deletes in GCS buckets HOT 1
- bucket destroying after adding default value in var.tf HOT 2
- Out of date gcp provider (Support version 5+)
- Bucket names are not validated HOT 2
- soft_delete_policy default value is incorrect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-google-cloud-storage.