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

Looping & conditionals alternative syntax #44

Closed
wants to merge 3 commits into from

Conversation

shenglol
Copy link
Contributor

Converted the template that Lei checked in. Ideas were explained in the comments in the converted .arm file.

@@ -0,0 +1,193 @@
// Ideas demonstrated in this file:
// Decorators for metadata.
// Reference a parameter: @parameterName
Copy link
Contributor Author

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.

Copy link
Member

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)

Copy link
Collaborator

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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #47 to track that discussion.


In reply to: 443728139 [](ancestors = 443728139)

Copy link
Member

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: {
Copy link
Member

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?

Copy link
Contributor Author

@shenglol shenglol Jun 22, 2020

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 ...

Copy link
Member

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.

Copy link
Contributor Author

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: {
Copy link
Member

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?

Copy link
Contributor Author

@shenglol shenglol Jun 22, 2020

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,
  }]
}

Copy link
Contributor Author

@shenglol shenglol Jun 22, 2020

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,
  }
}]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.

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

Successfully merging this pull request may close these issues.

4 participants