Hi everyone, I was wondering if it was possible to...
# terraform
d
Hi everyone, I was wondering if it was possible to stop the regex from stripping “/” from the name of cloudwatch log groups, we use these to create virtual directory paths https://github.com/cloudposse/terraform-aws-cloudwatch-logs
r
try setting that to
"/[^a-zA-Z0-9-\/]/"
(or similar) to avoid the replacement
d
Thank you so much, this should work and I should have spotted this earlier, will report back 🙌
r
that's ok. i think this is a bug. we should create a separate null label reference with this argument just for the log group name.
d
So i had a look at this, but the above didn’t work, it wasn’t escaping with one slash so I had to add two which gave me a plan
Copy code
"/[^a-zA-Z0-9-\\/]/"
however, it still removes the
Copy code
/
the one
Copy code
\
gave me tf errors
something really wacky going on with this module
Copy code
# module.cloudwatchlogs.aws_cloudwatch_log_group.default[0] will be created
  + resource "aws_cloudwatch_log_group" "default" {
      + arn               = (known after apply)
      + id                = (known after apply)
      + name              = "dev"
      + retention_in_days = 14
      + tags              = {
          + "Name"  = "/aws/kinesisfirehose/aws-waf-logs-dev-app"
          + "Stage" = "dev"
        }
      + tags_all          = {
          + "Name"  = "/aws/kinesisfirehose/aws-waf-logs-dev-app"
          + "Stage" = "dev"
        }
    }

  # module.cloudwatchlogs.aws_cloudwatch_log_stream.default[0] will be created
  + resource "aws_cloudwatch_log_stream" "default" {
      + arn            = (known after apply)
      + id             = (known after apply)
      + log_group_name = "dev"
      + name           = "/aws/kinesisfirehose/aws-waf-logs-dev-app"
    }
I would’ve expected log_group_name to be /aws/kinesisfirehose/aws-waf-logs-dev-app
r
the Name tag looks correct. the name argument should match that of the Name tag. looks like something isn't getting cleared. try consuming this cloudwatch logs module in a separate terraform directory and just run a plan.
d
Copy code
# module.cloudwatchlogs.aws_cloudwatch_log_stream.default[0] will be created
  + resource "aws_cloudwatch_log_stream" "default" {
      + arn            = (known after apply)
      + id             = (known after apply)
      + log_group_name = "awskinesisfirehoseaws-waf-logs-dev-app"
      + name           = "/aws/kinesisfirehose/aws-waf-logs-dev-app"
    }
this looks better, the reason it’s being changed to ‘dev’ is because ‘stage’ is being populated which we use elsewhere, but still can’t get past this issue where the ‘/’ are being stripped by the regex
i could make an MR to the repository so that the log group name/stream name is not validated by the id field?
just let me know thoughts on moving this forward
r
I'll have to test this out locally and get back to you. there must be a way to override this. if not, maybe we need a new escape hatch in the module itself
🙌 1
d
ok let me know if there’s anything i can do to facilitate i’ve tried setting regex_replace_chars = “” regex_replace_chars = null regex_replace_chars = “/[^a-zA-Z0-9-\/]/” regex_replace_chars = “/[^a-zA-Z0-9-\\/]/”
r
so it looks like it needs a custom label i put in this pr and it shows the correct log group https://github.com/cloudposse/terraform-aws-cloudwatch-logs/pull/26
we’ll have to wait until it’s approved. for now, you can use the source in the pr description until its merged 🙂
d
Thank you! 🙂
np 1