9 Writing an infrastructure DSL
This chapter covers
- Grasping the ideas behind Infrastructure as Code
- Parsing a custom syntax with structs and keywords
- Thinking about parsing tradeoffs
- Avoiding duplication by combining procedural and declarative macros
- Calling asynchronous functions in a macro and creating cloud resources
Most of the macros we have created thus far work within Rust, generating new functions, adding methods to enums, etc. But we also know macros can do more than that. For example, they allow you to generate compile-time checked HTML (Yew), or they create infrastructure for your code based on annotations (Shuttle).
This chapter features a macro that boldly goes beyond the confines of Rust and creates infrastructure in Amazon Web Services (AWS). This is interesting because it allows us to manage both application and infrastructure logic in the same repository and the same language, which might make expanding and maintaining the code easier. And, hopefully, the example also offers inspiration to readers as to what else they might do with procedural macros. But first let’s take a step back to make sure we are all on the same page.