Search code examples
terraformterraform-provider-aws

Terraform error for creating VPC flow logs ( error Unsuitable value for right operand: a number is required)


I am trying to add resource for creating the VPC flow logs.

Here is the snippet

 resource "aws_flow_log" "vpc_flow_log" {
    log_destination      = "${var.s3_bucket_arn/var.environment/data.aws_region.current.name/aws_vpc.network.id}"
    log_destination_type = "s3"
    traffic_type         = "ALL"
     vpc_id          = aws_vpc.network.id
    
}

Here is the variable I am using

variable "s3_bucket_arn"{
  type = any
   description = "S3 bucket for VPC flow logs"
  default = "arn:aws:s3:::centralized-vpcflowlogs-logging"
}

I am getting this error on TF planning

 Error: Invalid operand
│ 
│   on .terraform/modules/vpc/main.tf line 247, in resource "aws_flow_log" "vpc_flow_log":
│  247:     log_destination      = "${var.s3_bucket_arn/var.environment/data.aws_region.current.name/aws_vpc.network.id}"
│     ├────────────────
│     │ var.environment is "dev"
│ 
│ Unsuitable value for right operand: a number is required.

My initial thought was it's because of the variable type was not defined and that's not the case.

Any help is appreciated.


Solution

  • Instead of

    log_destination = "${var.s3_bucket_arn/var.environment/data.aws_region.current.name/aws_vpc.network.id}"
    

    Try:

    log_destination = "${var.s3_bucket_arn}/${var.environment}/${data.aws_region.current.name}/${aws_vpc.network.id}"