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

ValueError: Fn::Ref - EdgeFunction.Version is not a valid Resource or Parameter #91

Closed
dunnmj42 opened this issue Nov 7, 2022 · 5 comments

Comments

@dunnmj42
Copy link

dunnmj42 commented Nov 7, 2022

Getting a little bit farther in this conversion with the latest update, but have a couple of errors.

The first is listed in the title. The offending line of my CF template is as follows:

LambdaFunctionAssociations: - EventType: origin-request LambdaFunctionARN: !Ref EdgeFunction.Version

Just removing .Version from this seems to allow it to continue, up until my other error, which I will report separately, as I don't think they are related.

@shadycuz
Copy link
Member

shadycuz commented Nov 8, 2022

@dunnmj42 Thanks for reporting this. Having a template to use would be helpful but I cant probably put together a simple one to replicate this issue. It should work as is if you are on version 0.4, so this is likely a bug then.

This was referenced Nov 9, 2022
@shadycuz
Copy link
Member

shadycuz commented Nov 9, 2022

I just fixed several bugs related to this ^, but I forgot to test this exact situation. Can you let me know if it still errors, if it does can you post the Exception dump?

@dunnmj42
Copy link
Author

dunnmj42 commented Nov 9, 2022

So I'm not sure this is the same error or not, as the Traceback has less clues than it did previously. The other issue I opened was closed, so I'm not sure if this new error is more relevant to this issue or that one, but here is the Traceback:

Traceback (most recent call last):
  File "/Users/***/Library/Python/3.9/bin/cf2tf", line 8, in <module>
    sys.exit(cli())
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/app.py", line 44, in cli
    config = TemplateConverter(tmpl_path.stem, cf_template, search_manger).convert()
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 94, in convert
    tf_resources = self.convert_to_tf(self.manifest)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 146, in convert_to_tf
    tf_resources.extend(converter(resources))
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 331, in convert_resources
    resolved_values = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  [Previous line repeated 3 more times]
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 193, in resolve_values
    return allowed_func[key](self, value)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/conversion/expressions.py", line 679, in sub
    return sub_s(template, values)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/conversion/expressions.py", line 710, in sub_s
    return StringType(re.sub(reVar, replace_var, value).replace("${!", "${"))
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/conversion/expressions.py", line 703, in replace_var
    result = get_att(template, var.split(".")) if "." in var else ref(template, var)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/conversion/expressions.py", line 421, in get_att
    raise ValueError(
ValueError: Could not convert Cloudformation property Arn to Terraform attribute of ['id'].

@dunnmj42
Copy link
Author

dunnmj42 commented Nov 9, 2022

Not sure if this will be helpful or not, but I rolled back to 0.4.0 and did the patch that you mentioned in my other issue, and I still get this:

  File "/Users/***/Library/Python/3.9/bin/cf2tf", line 8, in <module>
    sys.exit(cli())
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/app.py", line 44, in cli
    config = TemplateConverter(tmpl_path.stem, cf_template, search_manger).convert()
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 94, in convert
    tf_resources = self.convert_to_tf(self.manifest)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 146, in convert_to_tf
    tf_resources.extend(converter(resources))
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 331, in convert_resources
    resolved_values = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 197, in resolve_values
    resolved_list_values = [
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 198, in <listcomp>
    self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 181, in resolve_values
    data[key] = self.resolve_values(
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/convert.py", line 176, in resolve_values
    return functions.ref(self, value)
  File "/Users/***/Library/Python/3.9/lib/python/site-packages/cf2tf/conversion/expressions.py", line 807, in ref
    raise ValueError(f"Fn::Ref - {var_name} is not a valid Resource or Parameter.")
ValueError: Fn::Ref - EdgeFunction.Version is not a valid Resource or Parameter.

@shadycuz
Copy link
Member

I have good news and bad news and then more bad news and more bad news and mostly bad news.

So the good news is that this is a new error, which is some progress.

The bad news is this a new error 🙃. Also it's not a very good error msg. I think in the next version I'm going to work on having these little hicups just print an error msg and skip the thing that caused it so at least the program finishes.

The really bad news is that this template is a a SAM template. Which currently is not supported, #42. You can see the Cloudformation resource here https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html. Unfortunately Terraform does not have a direct match for SAM resources. Meaning there isn't really anything I can convert this resource too. Well it's more complicated than that... Basically SAM resources typically are not a single resource but sometimes a collection of resources. So to do the conversion you have to know what resources Cloudformation creates in the background for every SAM resource and then when you convert to Terraform you have to add those additional resources to the template. I actually think with the changes in v0.4 this conversion could be done but someone would have to hard code it into the override system. I just dont know enough about SAM to do it right now.

I'm going to close this issue in favor of the other one.

But thanks for opening and helping me debug it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants