-
Notifications
You must be signed in to change notification settings - Fork 38
Issue #95 - support for user-defined resource attribute values. #142
Issue #95 - support for user-defined resource attribute values. #142
Conversation
The reason for the One obvious course of action would be to copy the behaviour of the What do you think @martysweet, @akdor1154 and anyone else? |
What happens if multiple custom resources are present in one template? |
In hope that this is what you're referring to, let's assume the following template:
As you can see from the previous examples, the value of the PS: the above examples are with all the relevant PR's merged. |
I've just managed to merge the current |
If I understand correctly (PR has no added tests and no docs, wink wink) this lets the user specify the attributes to mock by the logical resource name? git checkout -b fn_getatt_custom_resource_saved # just in case
# update your master
git checkout master
git fetch upstream master
git reset --hard upstream/master
# rebase your branch
git checkout fn_getatt_custom_resource
git reset --hard c02edb5 # reset to before your merge commits
git rebase master # rebase on master
# you might need to fix conflicts here, git will walk you through it. Generally just
# edit conflicting files
# git add file
# git rebase --continue If something goes wrong your branch as now is saved as fn_getatt_custom_resource_saved. |
10ad14b
to
13487b5
Compare
Hi @akdor1154, thank you very much for the rebasing advice, I've adjusted the PR so that the changes are finally legible 😁 In regards, to the lack of documentation and tests, I've intentionally omitted them due to the fact that I wasn't really sure if my implementation was adequate and I was envisioning this PR to be more of a preliminary version / collaborative effort than a penultimatum. Last but not least, you are correct, my vision for the Now, AFAICT and please correct me if I'm wrong, you are suggesting that the aforementioned value format should be something like: |
So we also have #149 "AWS::CloudFormation::Stack", which raises the need for other resources which might have variable attribute output - yay CFN Specification! This should no longer be focused on just Custom resource types. I'm sure there are other resources which probably have variable attribute output. I feel overriding a whole type can be useful in some scenarios, but heavy-handed in others, so perhaps this calls for a dynamic way to give power users the flexibility they desire.
In fact, we could allow both on a single cli parameter, as a logical name can never be the same as a resource name - a simple regex of allowed logical name characters can confirm this. Then it would be
At validation time for !GetAtt
|
Could this be an augmented version of |
re types - yeah. I was actually thinking about the arbitrary part of the Overriding per name would be also be a nice general purpose way for users to be able to do Stack Attributes though, maybe it's worth implementing both ways. Not sure how useful it would be though, as it means all of your templates would need special attention for cfn-lint to work with them. Targeting by type means your could preconfigure cfn-lint in a script or something (I have it wrapped in something similar) to already know about all your custom resources. |
This is certainly something I want to avoid, I don't want any learning curve to using the tool, so assumptions (like we currently have) would probably be the best way to go. Most users, unless they are aware of the advanced techniques they are using, will be returning strings from custom attributes, so this should be assumed if there is no additional CLI information to suggest otherwise. |
AFAICT, everyone agrees that the way to move forward with this is by allowing user-defined attributes to be set at the resource-Type level (something similar to what @martysweet suggested above) and perhaps if it's not too difficult and doesn't impose any special attention on behalf of the user at the resource-Name level too. Hope I got that right if not then please advise. PS: I am currently experimenting with the resource-Type version ... so stay tuned, more to follow 😁 |
93d74b2
to
f90fba7
Compare
I've just managed to write up the initial version for user-defined resource attribute values that are matched based on the resource type. How does this look? |
In hopes that what I've just done is ok, a short summary of what remains:
@akdor1154, @martysweet if you could both verify that I'm not missing something from this list and please advise if you would prefer a certain behaviour. |
The approach seems sane. It would be good if we can emit an A logical resource attr should take precedence over a base resource type attr. |
Hi @martysweet and @akdor1154, sorry for taking so long with this but I was working on something else that sparked my personal curiosity, which I'll be sharing with you shortly. |
d79a0d6
to
edc5c76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of things. @akdor1154 Any thoughts?
README.md
Outdated
@@ -73,6 +73,11 @@ Template invalid! | |||
`--only-guess-parameters <param names>`: Only guess the provided parameters, and disable the guessing of all others without Defaults. A critical error will be raised for missing parameters, as above. e.g. | |||
- `--only-guess-parameters InstanceType,Memory` | |||
|
|||
`--custom-resource-attributes <attribute values>`: Provide a list of comma-separated key=value pairs of resource attributes using either resource-type notation (e.g. `AWS::CloudFormation:: | |||
CustomResource.SomeAttribute`) or logical-name notation (e.g. `SomethingPretty.SomeAttribute`) and their expected values, to use when validating your template. If a custom resource attribute is not specified here, `cfn-lint` will guess a mock value. e.g. | |||
- `--custom-resource-attributes AWS::CloudFormation:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't format properly, is the bullet point is in the wrong place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few others which don't format correctly. Leave this and I will clean it up afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
@@ -82,6 +84,18 @@ program | |||
} | |||
} | |||
|
|||
if(cmd.customResourceAttributes){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need tests for this block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added in b0c9a22. Please let me know if this new style is ok otherwise I'll change it to reflect the others.
if (!specification.ResourceTypes[type]) { | ||
type = 'AWS::CloudFormation::CustomResource'; | ||
} | ||
return specification.ResourceTypes[type]!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does the cheeky !
do on the end of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, the cheeky !
disables validation as Typescript believes that type
can be undefined
or at least non-existent in ResourceTypes
however, this should not occur in this particular scenario. I actually borrowed it from the previous code.
src/validator.ts
Outdated
}; | ||
|
||
// extend defintion for existing resource type | ||
if (RegExp(/::/).test(resource)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use indexof() for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why not ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I remember, by using indexOf
we either have to use!!~
or == -1
, which both seem kind of cheeky to me ;) but sure I'll change it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str.indexOf("::") > -1
?
I dunno, @akdor1154 any suggestions on the neatest/cleanest way of simple substring checking in TS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
@RazzM13 I will be looking at merging this and publishing v1.7.0, probably on Sunday. |
package.json
Outdated
"opn": "^5.2.0", | ||
"winston": "^2.4.0", | ||
"source-map-support": "^0.5.0", | ||
"safe-buffer": "^5.1.1" | ||
"safe-buffer": "^5.1.1", | ||
"proxyquire-2": "^1.0.7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a devdependancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Affirmative, thank you.
9c0c773
to
c7b2f03
Compare
c7b2f03
to
601674d
Compare
…lied based on the resource type or logical name.
I believe I've finally managed to integrate master without losing history :) |
Added support for user-defined custom resource attribute values.