Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing multiline filter values as strings is not working with escape and heredoc #6801

Closed
crisalid opened this issue Jul 16, 2020 · 11 comments
Assignees
Labels
bug forward/review In review; remove label to forward service/logging

Comments

@crisalid
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v0.12.28

  • provider.google v3.29.0

Affected Resource(s)

"google_logging_organization_sink"

Terraform Configuration Files

variable "events" {
  #type = "map"
  default = {
    "Admin permissions" = "(protoPayload.methodName=\"google.admin.AdminService.assignRole\" OR protoPayload.methodName=\"google.admin.AdminService.addPrivilege\")"
  }
}

resource "google_logging_organization_sink" "static_filters" {
  org_id           = var.org_id
  destination      = "pubsub.googleapis.com/projects/${var.project}/topics/${google_pubsub_topic.high_priority_events_topic.name}"
  include_children = true
  for_each = var.high_priority_events
  name   = each.key
  filter = each.value 
}

Debug Output

https://gist.github.com/crisalid/79f766a34ea1f992966b31a18ea9ef2f

Panic Output

Error: googleapi: Error 400: Resource id contains illegal character, badRequest

on main.tf line 40, in resource "google_logging_organization_sink" "static_filters":
40: resource "google_logging_organization_sink" "static_filters" {

Expected Behavior

escaped double-quote symbols inside filter strings should not produce an error.

Actual Behavior

the resource did not get created

Steps to Reproduce

  1. terraform apply

Important Factoids

I have 20 filters to be created. To make a perfectly readable code it would be best to put those filter values as string variables. However, some of them contain multiple double quote character "

This caused me to try like 4 or 5 different ways to work around this issue, as you know - a double quote is used to describe s single string variable in TF. But when there are several " in a line - TF goes crazy :)
so I tried using \ and \\ as escape characters
tried heredoc format
tried putting those strings to text files and a function to read from them
none of that worked
TF argues on illegal characters :)

@ghost ghost added the bug label Jul 16, 2020
@edwardmedia edwardmedia self-assigned this Jul 16, 2020
@edwardmedia
Copy link
Contributor

@crisalid your log does not contain the ERROR section. But from your plan, I am able to mimic and create the sink with below filter. Do I miss your point? Please provide the filter values that could trigger the error along with your longer debug log. Thanks

filter = "(protoPayload.methodName=\"google.admin.AdminService.assignRole\" OR protoPayload.methodName=\"google.admin.AdminService.addPrivilege\")"

@crisalid
Copy link
Author

@edwardmedia thanks for your reply!
so the issue does not occur when the filter is assigned in a plain value inside resource, but when I put for_each and assign filter value through variable:

Error: googleapi: Error 400: Resource id contains illegal character, badRequest

on main.tf line 40, in resource "google_logging_organization_sink" "static_filters":
40: resource "google_logging_organization_sink" "static_filters" {

it's generated by the code above.

@ghost ghost removed the waiting-response label Jul 16, 2020
@edwardmedia
Copy link
Contributor

@crisalid can you post your code showing how you assign the filter values through variables?

@crisalid
Copy link
Author

crisalid commented Jul 16, 2020

variable "events" {
  #type = "map"
  default = {
    "Admin permissions" = "(protoPayload.methodName=\"google.admin.AdminService.assignRole\" OR protoPayload.methodName=\"google.admin.AdminService.addPrivilege\")"
  }
}

resource "google_logging_organization_sink" "static_filters" {
  org_id           = var.org_id
  destination      = "pubsub.googleapis.com/projects/${var.project}/topics/${google_pubsub_topic.high_priority_events_topic.name}"
  include_children = true
  for_each = var.events
  name   = each.key
  filter = each.value 
}

@ghost ghost removed the waiting-response label Jul 16, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented Jul 16, 2020

@crisalid by using for_each, do you expect it can create multiple sinks? I don't think it supports that

@crisalid
Copy link
Author

ok, I removed for_each.
I put my filter just like you did.
the plan runs Ok
apply fails due to illegal character, \

@ghost ghost removed the waiting-response label Jul 16, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented Jul 16, 2020

@crisalid can you post your updated code which yields illegal character error? Below link has a pretty good example https://www.terraform.io/docs/providers/google/r/logging_organization_sink.html

@crisalid
Copy link
Author

@edwardmedia I think this might be related to the backslash symbol not being url encoded for being used with google rest api
https://gist.github.com/crisalid/2e761ae1708c920253827f5ad1f51032

@ghost ghost removed the waiting-response label Jul 16, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented Jul 16, 2020

@crisalid I was using below filter in the code and apply was complete successfully. Could you be more specific about the backslash symbol which causes problem? Please share your code so I can repro the problem. Thanks
filter = "(protoPayload.methodName=\"google.admin.AdminService.assignRole\" OR protoPayload.methodName=\"google.admin.AdminService.addPrivilege\")"

@crisalid
Copy link
Author

my fault.
dumb.
spaces in resource name :)

@ghost ghost removed the waiting-response label Jul 17, 2020
@ghost
Copy link

ghost commented Aug 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 16, 2020
@github-actions github-actions bot added service/logging forward/review In review; remove label to forward labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/logging
Projects
None yet
Development

No branches or pull requests

2 participants