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

aws_ami data source with a name_regex including ** causes terraform to crash #9608

Closed
paulte opened this issue Oct 25, 2016 · 5 comments
Closed

Comments

@paulte
Copy link

paulte commented Oct 25, 2016

Low priority bug report. It looks like name_regex within aws_ami doesn't handle the regular expression of **

I'm not suggesting there's a use case where ** would be considered required / desirable, more that it would be preferable that it didn't crash terraform.

Terraform Version

Terraform v0.7.7

Affected Resource(s)

  • aws_ami

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "aws" {
    region="eu-west-1"
}

data "aws_ami" "example" {
  owners = ["self"]
  name_regex = "^example**"
  most_recent = true
}

output "myami" {
        value = "${data.aws_ami.example.id}"
}

Panic Output

https://gist.github.com/paulte/73d2709161842737aa6fd4810664e80b

Expected Behavior

The regular expression ** should be considered equivalent to * and not crash terraform

Actual Behavior

Terraform crash

Steps to Reproduce

  1. terraform apply
@apparentlymart
Copy link
Contributor

Relevant chunk of the Panic output, for easier reference:

2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: panic: regexp: Compile(`^example**`): error parsing regexp: invalid nested repetition operator: `**`
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: 
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: goroutine 86 [running]:
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: panic(0x2310fa0, 0xc420446d70)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/runtime/panic.go:500 +0x1a1
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: regexp.MustCompile(0xc420698a50, 0xa, 0xc420698d30)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/regexp/regexp.go:237 +0x17a
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: github.com/hashicorp/terraform/builtin/providers/aws.dataSourceAwsAmiRead(0xc4205a2de0, 0x2220fc0, 0xc4204b6180, 0xc00000000000007, 0x0)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/data_source_aws_ami.go:240 +0x338
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: github.com/hashicorp/terraform/helper/schema.(*Resource).ReadDataApply(0xc42026c9c0, 0xc420697380, 0x2220fc0, 0xc4204b6180, 0xc42057d9d8, 0x1, 0x0)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/gopath/src/github.com/hashicorp/terraform/helper/schema/resource.go:207 +0xda
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: github.com/hashicorp/terraform/helper/schema.(*Provider).ReadDataApply(0xc420274030, 0xc42040d380, 0xc420697380, 0x0, 0x18, 0x18)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/gopath/src/github.com/hashicorp/terraform/helper/schema/provider.go:317 +0x91
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).ReadDataApply(0xc4201ca080, 0xc420698600, 0xc420698c60, 0x0, 0x0)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/gopath/src/github.com/hashicorp/terraform/plugin/resource_provider.go:537 +0x4e
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: reflect.Value.call(0xc420485620, 0xc4201be040, 0x13, 0x2a8503f, 0x4, 0xc420795ed0, 0x3, 0x3, 0x22fb6e0, 0xc4205a2cc0, ...)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/reflect/value.go:434 +0x5c8
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: reflect.Value.Call(0xc420485620, 0xc4201be040, 0x13, 0xc420795ed0, 0x3, 0x3, 0xc42073e014, 0x100000000, 0xc4204bff01)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/reflect/value.go:302 +0xa4
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: net/rpc.(*service).call(0xc42000a3c0, 0xc42000a380, 0xc4203784a0, 0xc4203ae500, 0xc4203765e0, 0x22230c0, 0xc420698600, 0x16, 0x2223100, 0xc420698c60, ...)
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/net/rpc/server.go:383 +0x148
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7: created by net/rpc.(*Server).ServeCodec
2016/10/25 22:54:37 [DEBUG] plugin: terraform.0.7.7:    /opt/go/src/net/rpc/server.go:477 +0x421

@kwilczynski
Copy link
Contributor

@paulte hi there! Thank you for getting in touch!

I have added a pre-flight, so to speak, validation of the regular expression that is passed down via the name_regex attribute. It should help to catch issues earlier in the process. Sorry for any troubles!

@stack72
Copy link
Contributor

stack72 commented Oct 26, 2016

Closed via #9622

@stack72 stack72 closed this as completed Oct 26, 2016
@kwilczynski
Copy link
Contributor

@paulte hi there! Just to add for the record - the ** is definitely not a valid operation, and would trip a lot of regular expression engines (e.g. JavaScript, Perl, Ruby, etc.), thus we cannot support it, but we can fail early to improve the feedback to the user before the issue manifests itself.

@ghost
Copy link

ghost commented Apr 21, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants