-
Notifications
You must be signed in to change notification settings - Fork 775
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
Looping & conditionals alternative syntax #44
Conversation
@@ -0,0 +1,193 @@ | |||
// Ideas demonstrated in this file: | |||
// Decorators for metadata. | |||
// Reference a parameter: @parameterName |
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.
Stole Lei's idea but changed input.parameterName
to @parameterName
so there's less typing.
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 missed that part in Lei's idea, but I think we will need to consider it. I'm not sure I like using @
for decorators and parameter references, but a different character could work I think. (Brian T was proposing using $
for variable/parameter references like Perl or PHP.) I'll write up a separate issue to discuss this.
In reply to: 443018747 [](ancestors = 443018747)
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.
strong +1 on separating how we reference params/vars/resource/etc. I have strong opinions, but it's not relevant to this discussion :)
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 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.
That discussion is now captured in #47.
}, | ||
}]; | ||
|
||
resource[] dbContainers: "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2020-03-01" = [for containerReference, i in containerReferences: { |
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.
How to specify copy mode (serial vs. parallel) and batch size?
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.
Personally I think it makes more sense to separate metadata from resource declaration syntax, so I'm thinking about using a metadata decorator like this:
@copy(mode="serial", batchSize=2)
resource[] dbContainers ...
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 think it's done with the @
annotations/decorators.
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.
Yeah I have no strong opinion / preference on the decorator syntax, just using @
to demonstrate my idea. The C# like syntax [copy(mode="serial", batchSize=2]
might be another option. We can design the syntax later if we decided to go with decorators.
// Reference a parameter with @parameterName. | ||
// Reference a varialbe with $variableName. | ||
resource dbAccount: "Microsoft.DocumentDB/databaseAccounts@2020-03-01" = switch (@createNewAccount) { | ||
case true: { |
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.
Is it possible to include multiple resources in this case 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.
If it is for expressing "deploying a list of resources of the same type when some condition is met", then yes we can do the following:
resource[] dbAccout "Microsoft.DocumentDB/databaseAccounts@2020-03-01" = switch ($fooVariable) {
case "foo": [for bar in $barVariable: {
prop1: bar.prop1,
prop2: bar.prop2,
}]
}
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.
And it's also possible to revert the switch and the for...in generator expressions so we could say "check some condition for all resources in a list, if it is met for a resource, deploy that resource":
resource[] dbAccout "Microsoft.DocumentDB/databaseAccounts@2020-03-01" = [for bar, i in $barVariable: switch ($fooVariable[i]) {
case true: {
prop1: bar.prop1,
prop2: bar.prop2,
}
}]
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.
Good question.
Converted the template that Lei checked in. Ideas were explained in the comments in the converted .arm file.