(window.webpackJsonp=window.webpackJsonp||[]).push([[3],{115:function(e,t,n){"use strict";var o=n(0),a=n(34);t.a=function(){return Object(o.useContext)(a.a)}},116:function(e,t,n){"use strict";n.d(t,"a",(function(){return u})),n.d(t,"b",(function(){return m}));var o=n(0),a=n.n(o);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t){if(null==e)return{};var n,o,a=function(e,t){if(null==e)return{};var n,o,a={},r=Object.keys(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var s=a.a.createContext({}),p=function(e){var t=a.a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):c(c({},t),e)),n},u=function(e){var t=p(e.components);return a.a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},b=a.a.forwardRef((function(e,t){var n=e.components,o=e.mdxType,r=e.originalType,i=e.parentName,s=l(e,["components","mdxType","originalType","parentName"]),u=p(n),b=o,m=u["".concat(i,".").concat(b)]||u[b]||d[b]||r;return n?a.a.createElement(m,c(c({ref:t},s),{},{components:n})):a.a.createElement(m,c({ref:t},s))}));function m(e,t){var n=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var r=n.length,i=new Array(r);i[0]=b;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c.mdxType="string"==typeof e?e:o,i[1]=c;for(var s=2;s<r;s++)i[s]=n[s];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,n)}b.displayName="MDXCreateElement"},117:function(e,t,n){"use strict";n.d(t,"a",(function(){return r}));var o=n(115),a=n(118);function r(e,{forcePrependBaseUrl:t=!1,absolute:n=!1}={}){const{siteConfig:{baseUrl:r="/",url:i}={}}=Object(o.a)();if(!e)return e;if(t)return r+e;if(!Object(a.a)(e))return e;const c=r+e.replace(/^\//,"");return n?i+c:c}},118:function(e,t,n){"use strict";function o(e){return!1===/^(https?:|\/\/|mailto:|tel:)/.test(e)}n.d(t,"a",(function(){return o}))},97:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return c})),n.d(t,"rightToc",(function(){return l})),n.d(t,"default",(function(){return p}));var o=n(2),a=n(6),r=(n(0),n(116)),i=(n(117),{id:"cf-cookbook",title:"Cookbook",sidebar_label:"Cookbook"}),c={id:"aws/cloudformation/cf-cookbook",isDocsHomePage:!1,title:"Cookbook",description:"The following is a selection of interesting things that you can do using the CloudFormation plugin to organize and deploy your stacks.",source:"@site/docs/aws/cloudformation/cookbook.md",permalink:"/gradle-infrastructure-plugins/docs/aws/cloudformation/cf-cookbook",sidebar_label:"Cookbook",sidebar:"mainSidebar",previous:{title:"CloudFormation Configuration",permalink:"/gradle-infrastructure-plugins/docs/aws/cloudformation/cf-config"},next:{title:"Roadmap",permalink:"/gradle-infrastructure-plugins/docs/aws/roadmap"}},l=[{value:"Parameterized Deployments",id:"parameterized-deployments",children:[]},{value:"Using Dependencies for Complex Deployments",id:"using-dependencies-for-complex-deployments",children:[]},{value:"Task Groups",id:"task-groups",children:[]}],s={rightToc:l};function p(e){var t=e.components,n=Object(a.a)(e,["components"]);return Object(r.b)("wrapper",Object(o.a)({},s,n,{components:t,mdxType:"MDXLayout"}),Object(r.b)("p",null,"The following is a selection of interesting things that you can do using the CloudFormation plugin to organize and deploy your stacks."),Object(r.b)("h2",{id:"parameterized-deployments"},"Parameterized Deployments"),Object(r.b)("p",null,Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"https://github.com/cloudmation-llc/gradle-infrastructure-plugins/tree/master/examples/src/cloudformation/cookbook-params-and-dependencies"}),Object(r.b)("strong",{parentName:"a"},"Example in Github"))),Object(r.b)("p",null,"This has been touched on in the ",Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"cf-config"}),"configuration")," page, but I wanted to reiterate the value gained from parameterizing templates. Using parameters effectively opens an opportunity to use ",Object(r.b)("em",{parentName:"p"},"one template")," for multiple stack deployments. Doing so cuts down on the number of template files that need to be maintained."),Object(r.b)("p",null,"The default design of the plugin is to read your template files, and come up with a sensible assumption about how to deploy them. In the situation of wanting to use single template, and deploy it multiple times with varying parameter values, the plugin cannot guess what needs to be done, and instead you need to provide the config."),Object(r.b)("p",null,"Take a look at the ",Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"https://github.com/cloudmation-llc/gradle-infrastructure-plugins/tree/master/examples/src/cloudformation/cookbook-params-and-dependencies"}),"parameterization example"),". In the build config, you can exclude tasks that were created automatically by the plugin, and instead define the specific stacks that you want deployed and their parameters. Note how the same template file is used repeatedly."),Object(r.b)("h2",{id:"using-dependencies-for-complex-deployments"},"Using Dependencies for Complex Deployments"),Object(r.b)("p",null,Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"https://github.com/cloudmation-llc/gradle-infrastructure-plugins/tree/master/examples/src/cloudformation/cookbook-params-and-dependencies"}),Object(r.b)("strong",{parentName:"a"},"Example in Github"))),Object(r.b)("p",null,"Gradle provides really nice tools to organize the task graph, and arrange the order of how tasks should be deployed. Since the plugin creates a task for each stack deployment, you can take advantage of task ordering to define complex deployments."),Object(r.b)("p",null,"Use an ",Object(r.b)("inlineCode",{parentName:"p"},"afterEvaluate")," block to configure task dependencies. In the ",Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"https://github.com/cloudmation-llc/gradle-infrastructure-plugins/tree/master/examples/src/cloudformation/cookbook-params-and-dependencies"}),"provided example"),", note how the subnet stacks are not deployed until the VPC stack is first created successfully."),Object(r.b)("p",null,"Use Gradle properties such as ",Object(r.b)("inlineCode",{parentName:"p"},"dependsOn"),", ",Object(r.b)("inlineCode",{parentName:"p"},"mustRunBefore"),", and ",Object(r.b)("inlineCode",{parentName:"p"},"mustRunAfter")," to chain together tasks."),Object(r.b)("pre",null,Object(r.b)("code",Object(o.a)({parentName:"pre"},{className:"language-groovy"}),"afterEvaluate {\n    deployNetworkZoneA.dependsOn deployVpc\n    deployNetworkZoneB.dependsOn deployVpc\n    deployNetworkZoneC.dependsOn deployVpc\n    deployNetworkZoneD.dependsOn deployVpc\n}\n")),Object(r.b)("h2",{id:"task-groups"},"Task Groups"),Object(r.b)("p",null,Object(r.b)("a",Object(o.a)({parentName:"p"},{href:"https://github.com/cloudmation-llc/gradle-infrastructure-plugins/tree/master/examples/src/cloudformation/cookbook-params-and-dependencies"}),Object(r.b)("strong",{parentName:"a"},"Example in Github"))),Object(r.b)("p",null,"Setting task dependencies is nice, but what if you want to run them all in one shot? You can create custom tasks in Gradle that simply call other tasks according to the define dependencies."),Object(r.b)("pre",null,Object(r.b)("code",Object(o.a)({parentName:"pre"},{className:"language-groovy"}),'afterEvaluate {\n    // Define a task to deploy all of the others\n    task "deployNetwork" {\n        group = "AWS Network"\n        description = "Deploy all of the network resources"\n        dependsOn deployNetworkZoneA, deployNetworkZoneB, deployNetworkZoneC, deployNetworkZoneD\n    }\n}\n')))}p.isMDXComponent=!0}}]);