Below tf code is to create AWS RDS event subscriptions. Getting below error while running this piece of tf code. If source_ids are not passed then it seems to be using 'all' as the default value - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_event_subscription
My requirement is not to not set it to 'all' in case event_subscription_source_type is not db-parameter-group. Is there any way to do that?
variable "event_subscription_source_type" {
type = map
description = "Map of the event subscription and event source type"
default = {
"rds-events" = "db-instance"
"db-param-group-chng" = "db-parameter-group"
}
}
#creating rds event subscriptions
resource "aws_db_event_subscription" "event_subscriptions" {
for_each = toset(var.event_subscription_names)
name = each.value
sns_topic = var.sns_topic
source_type = var.event_subscription_source_type[each.value]
source_ids = var.event_subscription_source_type[each.value] != "db-parameter-group" ? null : "all"
...
Error
Error: Incorrect attribute value type
│ on base.tf line 58, in resource "aws_db_event_subscription" "event_subscriptions":
│ 58: source_ids = var.event_subscription_source_type[each.value] != "db-parameter-group" ? null : "all"
│ │ each.value will be known only after apply
│ │ var.event_subscription_source_type is a map of dynamic, known only after apply
│ Inappropriate value for attribute "source_ids": set of string required.
Related
Why i'm not using the ID directly:
I have multiple datalake's where the filesystem is deployed. It throws error "resource not found" during the deployment.
What i'm trying to achieve now:
i am trying to use concat function and create the ID's. which is throwing an error.
module.adlsfs["adlsfilesystem1"].time_sleep.wait_few_mins_fs: Refreshing state... [id=2022-07-23T21:45:55Z]
╷
│ Error: Invalid function argument
│
│ on ../../../tf-core-module/adls/fs/filesystem.tf line 20, in resource "azurerm_storage_data_lake_gen2_filesystem" "storagedlsgen2fs":
│ 20: storage_account_id = concat("/subscriptions/",data.azurerm_subscription.current.id,"/resourceGroups/rsg-test/providers/Microsoft.Storage/storageAccounts/",each.value.staname)
│
│ Invalid value for "seqs" parameter: all arguments must be lists or tuples; got string.
╵
╷
│ Error: Invalid function argument
│
│ on ../../../tf-core-module/adls/fs/filesystem.tf line 20, in resource "azurerm_storage_data_lake_gen2_filesystem" "storagedlsgen2fs":
│ 20: storage_account_id = concat("/subscriptions/",data.azurerm_subscription.current.id,"/resourceGroups/rsg-test/providers/Microsoft.Storage/storageAccounts/",each.value.staname)
│
│ Invalid value for "seqs" parameter: all arguments must be lists or tuples; got string.
data "azurerm_subscription" "current" {
}
locals {
staname = toset([
for pair in sort(var.sta_name) : {
staname = pair
}
])
}
//**********************************************************
// Create File System in Datalake
//**********************************************************
resource "azurerm_storage_data_lake_gen2_filesystem" "storagedlsgen2fs" {
for_each = { for p in local.staname : jsonencode(p) => p }
name = var.adlsfilesystems
storage_account_id = concat("/subscriptions/",data.azurerm_subscription.current.id,"/resourceGroups/resourcegroup/providers/Microsoft.Storage/storageAccounts/",each.value.staname)
}
Is it even possible to use the function here? and how can i solve this.
thank you
I think that instead of concat, you want join:
storage_account_id = join("",["/subscriptions/",data.azurerm_subscription.current.id,"/resourceGroups/resourcegroup/providers/Microsoft.Storage/storageAccounts/",each.value.staname])
I am creating a google_compute_instance through terraform. I am setting the labels block there
resource google_compute_instance
{
labels: {
osname=var.osname
//if it is linuxos i need to set this label like
//if !local.windowsos then create confidential-vm key/value:
confidential-vm=var.isConfidentialVM
//if it is not linuxos the above label should not be set , i dont want to assign null
}
}
How to do this in terraform?
i have created a locals block
I have tried ${!local.iswindowsos}?"confidential-vm=true":""
locals{
instance_labels={
${!local.iswindowsos}?"confidential-vm=true":""
confidential-vm=local.iswindowsos
}
}
but getting this errors:
Error: Invalid character
│
│ on vm_instance.tf line 397, in resource "google_compute_instance" "vm":
│
397: ${!local.iswindowsos}?"confidential-vm=true":""
│
│ This character is not used within the language. //`$`
397: ${!local.iswindowsos}?"confidential-vm=true":""
│
│ Expected the start of an expression, but found an invalid expression token.
You could probably try assigning a value to a label when the OS is not Linux, e.g.:
locals {
iswindowsos = var.windowsos
confidential_vm = local.iswindows ? true : false
}
resource "google_compute_instance" "instance_name" {
...
labels {
osname = var.osname
iswindowsos = local.iswindowsos
confidential_vm = try(local.confidential_vm, null)
}
}
I am trying to create a table and for the column I want to give the default value as current timestamp. What am I doing wrong here?
Ref -
https://registry.terraform.io/providers/chanzuckerberg/snowflake/latest/docs/resources/table
resource "snowflake_table" "snow_events_table" {
database = "SNOW"
schema = "PUBLIC"
name = "SNOW_EVENTS"
comment = "Events from S3 are transformed into this table"
cluster_by = ["org_id"]
change_tracking = false
column {
name = "_date_created"
type = "TIMESTAMP_NTZ(9)"
nullable = false
default {
expression = "CURRENT_TIMESTAMP()"
}
}
}
Error is
Error: Unsupported block type │ │ on ../../modules/snowplow-s3-storage/tables.tf line 21, in resource "snowflake_table" "snow_events_table": │ 21: default { │ │ Blocks of type "default" are not expected here.
I am learning how to use Terraform. My aim is to deploy an architecture on GCP so here's my main.tf so far :
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.85.0"
}
}
}
provider "google" {
credentials = file(var.credentials_file)
region = var.region
zone = var.zone
}
data "google_organization" "org" {
domain = var.organization.display_name
org_id = var.organization.id
directory_customer_id = var.organization.directory_customer_id
}
resource "google_folder" "shared" {
display_name = "Shared"
parent = google_organization.org_id
}
resource "google_folder" "ddm" {
display_name = "Data and Digital Marketing"
parent = google_folder.shared.name
}
resource "google_folder" "dtl" {
display_name = "DTL"
parent = google_folder.ddm.name
}
According to the documentation, org_id is within the Attributes Reference
But I get the following errors:
╷
│ Error: Computed attributes cannot be set
│
│ with data.google_organization.org,
│ on main.tf line 17, in data "google_organization" "org":
│ 17: org_id = var.organization.id
│
│ Computed attributes cannot be set, but a value was set for "org_id".
╵
╷
│ Error: Computed attributes cannot be set
│
│ with data.google_organization.org,
│ on main.tf line 18, in data "google_organization" "org":
│ 18: directory_customer_id = var.organization.directory_customer_id
│
│ Computed attributes cannot be set, but a value was set for "directory_customer_id".
╵
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 22, in resource "google_folder" "shared":
│ 22: parent = google_organization.org_id
│
│ A managed resource "google_organization" "org_id" has not been declared in the root module.
What am I doing wrong?
The organization is set as a data source, but in the previous code, it is used like a resource block.
What needs to be done to reference the organization is this :
data "google_organization" "org" {
organization = var.organization.id
}
org_id is an output, not an input. The only acceptable inputs are organization ordomain; they are mutually exclusive.
And use its outputs like this :
resource "google_folder" "shared" {
display_name = "Shared"
parent = data.google_organization.org.org_id
}
EDIT : This, although syntactically correct, it might not work because the account used must be organization administrator on the organization level. I do not recomment using the google_organization data sourcejust to fetch the ID and other info, I ended up writing those in a variable and just calling it this way :
resource "google_folder" "shared" {
display_name = "Shared"
parent = "organizations/${var.organization.id}"
}
I am trying to use terraform string function and string concatenation on a terraform tfvars variable. but when run the terraform plan it through the below exception
Error: A reference to a resource type must be followed by at least one attribute
access, specifying the resource name.
Following is the terraform code
locals {
name_suffix = "${var.namespace != "" ? var.namespace : var.env}"
}
resource "azurerm_container_registry" "my_acr" {
name = "myacr${replace(name_suffix, "-", "")}"
location = "${azurerm_resource_group.location}"
resource_group_name = "${azurerm_resource_group.name}"
sku = "Basic"
admin_enabled = true
}
Here namespace value will be resolved at runtime.
Terraform version 0.12.7
it was a silly mistake. instead of name_suffix, I should have written it like local.name_suffix inside the acr resource
Had a similar issue when setting up Terraform configuration files for AWS Fargate.
Got the error below:
│ Error: Invalid reference
│
│ on ../ecs/main.tf line 72, in resource "aws_ecs_service" "aes":
│ 72: type = order_placement_type
│
│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
╵
╷
│ Error: Invalid reference
│
│ on ../ecs/main.tf line 73, in resource "aws_ecs_service" "aes":
│ 73: field = order_placement_field
│
│ A reference to a resource type must be followed by at least one attribute access, specifying the resource name.
The issue was that I missed the var prefix for variables, so instead of this:
ordered_placement_strategy {
type = order_placement_type
field = order_placement_field
}
I corrected it to this:
ordered_placement_strategy {
type = var.order_placement_type
field = var.order_placement_field
}
That's all.
Another thing to check. Make sure you have the index specifier in the correct position.
I had the following code and ran into this problem:
data "cloudflare_origin_ca_root_certificate" "current" {
count = var.domain == null ? 0 : 1
algorithm = tls_private_key.privateKey[0].algorithm
}
resource "aws_acm_certificate" "cert" {
count = var.domain == null ? 0 : 1
#...
certificate_chain = data.cloudflare_origin_ca_root_certificate[0].current.cert_pem
}
Turns out I made the mistake of putting the [0] before the current selector instead of after. So I just had to change the certificate_chain line to the following:
certificate_chain = data.cloudflare_origin_ca_root_certificate.current[0].cert_pem