<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Avi Friedman on Medium]]></title>
        <description><![CDATA[Stories by Avi Friedman on Medium]]></description>
        <link>https://medium.com/@avifr?source=rss-5205d10b6022------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XKrKDioqamaDmBl9fjdc2Q.jpeg</url>
            <title>Stories by Avi Friedman on Medium</title>
            <link>https://medium.com/@avifr?source=rss-5205d10b6022------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:39:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@avifr/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Slack Killed My Productivity]]></title>
            <link>https://medium.com/@avifr/how-slack-killed-my-productivity-e078c3561804?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/e078c3561804</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[messaging]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[workplace-culture]]></category>
            <category><![CDATA[slack]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 15:04:24 GMT</pubDate>
            <atom:updated>2019-04-01T12:06:49.699Z</atom:updated>
            <content:encoded><![CDATA[<h4>And how you can take back yours</h4><blockquote><strong>tl;dr:</strong></blockquote><blockquote>1. Promote Slack etiquette as part of your corporate culture and onboarding process</blockquote><blockquote>2. Create channels for specific domains/modules/teams and separate development and production channels.</blockquote><blockquote>3. Force people using @channel to confirm before sending the message</blockquote><blockquote>4. Limit who can use slack @mentions in your public Slack channels</blockquote><blockquote>5. In the meanwhile, minimize your “<strong>Slack attack vector</strong>”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKBnwU7hO0cQK90U-CBfXg.jpeg" /></figure><p>I love Slack. We all do. That’s why it’s <a href="https://techcrunch.com/2018/08/07/slack-raising/">valuated at around $7B</a> (!) right now. It’s a great tool for communicating within and between teams. It pretty much completely replaced email for me. It has done to emails what Whatsapp did for sms: about 90% of the emails I get now are basically spam.</p><p>But it has completely ruined my productivity, and my ability to manage my own time.</p><p>Don’t get me wrong. Slack does appear to have productivity in mind. It integrates with virtually anything, supports building custom bots, and uses @mentions as a great way to selectively ping the people you need, unintrusively.</p><p>As a matter of fact, the @mentions is one of the things that are really missing for me on other messaging apps, like Whatsapp. There’s nothing more annoying than having Whatsapp groups constantly pop up as notifications everytime someone writes anything on a group. On Slack, you won’t get notified of anything in a channel (or group) unless someone mentions you specifically (of course you can tweak that in the settings, but other than adding an alert for when someone writes “chocolates in the kitchen” why would you). That’s a great way for managing who exactly needs to be weighed in on a conversation currently being held inside a multi-participant channel without having to intrude on everyone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*PKBZmVBUNg8r_RUfUbshww.png" /></figure><h3>Introducing “@here” &amp; “@channel”</h3><p>The most powerful mentions on Slack are: @here &amp; @channel. They basically notify everyone in the channel. But there’s a big difference between the two, a difference that most people don’t make. You can read more about the two <a href="https://get.slack.help/hc/en-us/articles/202009646-Notify-a-channel-or-workspace">here</a>. In a nutshell:</p><ul><li>@here notifies people who are currently online and active</li><li>@channel notifies <strong>everybody</strong> in the channel.</li></ul><p>Basically, @here would only notify people currently active in the Slack app, while @channel notifies everyone, whether they’re offline, sleeping, on vacation etc. If you have the Slack app installed on your phone, you’ll get a notification. With @here, if you’re not active in the app, you won’t.</p><h3>The proliferation of “@channel”</h3><p>At my workplace, people found out about @channel and pretty much started using it for everything:</p><ul><li>Someone’s taking down some DB you’re not even using? on a Sunday?</li><li>Someone has a “lesson learned” to share?</li><li>A new version is being branched-out in our legacy repo?</li><li>Someone has a birthday?</li><li>There’s cake in the kitchen? (ok, that one’s crucial)</li></ul><p>Everything will be sent with @channel. You should really know about this. <strong>Now</strong>.</p><p>Around 90% of all messages on our wide R&amp;D or office channels are being sent with the @channel mention.</p><h3>The boy who cried “@channel wolf!”</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*JKWlNDsW_7dbQC3ooZzPtg.jpeg" /></figure><p>This is pretty much the tragedy of the @channel mention: it’s really only effective if used wisely, and with good measure. Once it becomes ubiquitous, it becomes a nuisance. Worst case scenario: people keep getting notified over stuff they don’t need to know <strong>right now</strong> and experience constant context-switching. This takes its toll on people’s ability to make the most of their time. It’s a real shame, because the @mention system is one of Slack’s most powerful features (together with the ability to react to a message with a Ron Swanson emoji. Get with the program, Whatsapp!).</p><h3>If a message has no `@mention`, was it ever really sent?</h3><p>When most people use @mentions all the time, everyone has to use them. It promotes an office culture in which you know you’ll get notified of everything, so you don’t have to actively look at channels. This way, if a message isn’t sent with a @mention no one really reads it. People feel if they simply write their message, without any @mention, then no one will ever know.</p><p>So how can we control this mess?</p><h3>Talk about it</h3><p>Start by trying and making this a part of your work environment etiquette. Have the conversation. Understand the difference between @mentions , why you should try and avoid the @channel mention like the plague, and even why sometimes (or most of the times, believe it or not) you don’t really need to use <strong>any</strong> mention at all.</p><p>If you’re working on something that might break something, try a “pull” approach, rather than a “push” approach: instead of notifying <strong>everyone</strong> in the appropriate channel (which still might have a lot of people, most uninterested), just write the message. Don’t mention anyone. If something breaks for someone, he can go into the channel and check to see if anyone wrote something valuable. You’ll be wasting less time for fewer people. This translates to more productivity, more working hours, less money wasted.</p><p>Slack etiquette should be part of any onboarding process for new employees joining the Slack team.</p><h3>Separate development and production channels</h3><p>Of course production issues require immediate attention and intervention, but you can try and limit the exposure of people to production issues by separating channels into development and production channels (and separate those into your company’s modules, domains or teams working on those production systems). If there are any production issues that require <strong>immediate</strong> attention and alert, you’d know you’re really notifying the people who can actually do something about it. Only production channels should have @channels mentions in them.</p><h3>Alert anyone who uses “@channel”</h3><p>Slack has the ability to alert anyone sending a message with a @channel mention in a channel with more than 6 people. It will ask the person to confirm sending the message. This can be very helpful in alerting people that they’re about to send a very intrusive message, and might reduce the amount of people who are simply using this out of lack of understanding. Just make sure this feature is enabled in your Slack space (workspace owners can control this, so <strong>contact your congressman</strong>)</p><h3>Control who can use widespread “@mentions”</h3><p>Workspace owners also control who can use these mentions. It might be a little excessive to restrict some people from completely using @channel, but then again, why should everyone even have the ability to notify <strong>everyone else in R&amp;D</strong> about something? It might be a good idea to have only team-leads be able to use it, and act as some low-pass-filter for this. They might exercise better judgement, as they probably know better about how urgent something really is.</p><h3>What you can do right now</h3><p>Trying and making a change in your workplace is the long game. What can you do now to control your own time?</p><p>Start thinking of your time as a valuable asset that you should try and guard at all cost. Start thinking of this as a security issue. Here’s what I did to minimize the <a href="https://searchsecurity.techtarget.com/definition/attack-vector">attack vector</a>:</p><ol><li>Turned off <strong>all</strong> notifications on my Slack. Both on my desktop and mobile app. This way, I control when I actively look for messages and updates. If someone needs me <strong>now</strong>, he knows where to find me (it helps to have a small office). If I need something, I actively look for it on Slack, or I go to that person and ask. I still keep the mobile app — for my own convenience. But I’ve switched off all notifications from it.</li><li>Muted almost every inessential channel.</li><li>Removed myself from any and all unnecessary, irrelevant or old Slack channels I was in.</li><li>I Periodically review all Slack channels I’m a member of. I hold them close to my chest, and ask myself: Does this channel <a href="https://konmari.com/">spark joy in my heart</a>?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMFlw6vdkk4fT6XvUepR3w.png" /><figcaption>my Slack status</figcaption></figure><h3>Slack isn’t an Email replacement</h3><p>Now yes, there’s a big downside to these steps, and it stems from Slack’s biggest problem: though it aims to replace the office email, and it has done so for me to some extent as I’ve mentioned, it really isn’t an actual email replacement. It’s a messaging app, and as a messaging app people regard it as a more immediate communication interface. If someone sends me an email, he doesn’t expect an immediate answer. If someone slacks me, he’ll probably start getting restless if I don’t answer within the first 10 minutes.</p><p>There’s no real solution for this. People will just have to either accept the fact that not everyone will be responsive immediately on Slack, or we can start making company-wide changes to promote more use of Slack as a productivity enhancer, and not a productivity killer.</p><p>In the meantime, hop off the grid for a while. You’ll have more time you can waste by being unproductive in different ways.</p><p>You’ll also miss all of the “cake in the kitchen” alerts. You can thank me later.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e078c3561804" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Smart(er) Home for under $400]]></title>
            <link>https://medium.com/@avifr/a-smart-er-home-for-under-400-c7a93ec4d5c8?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a93ec4d5c8</guid>
            <category><![CDATA[sensibo]]></category>
            <category><![CDATA[google-home]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[yeelight]]></category>
            <category><![CDATA[smart-home]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Wed, 28 Mar 2018 15:00:23 GMT</pubDate>
            <atom:updated>2018-03-28T15:00:23.272Z</atom:updated>
            <content:encoded><![CDATA[<h4>A smart home using Xiaomi Yeelight, Sensibo, Switcher &amp; Homeassistant</h4><p>Building a smart home sounds futuristic, and futuristic sounds expensive. But nowadays, it’s totally affordable. How much affordable? Depends on how smart you want your home to be…</p><p>What exactly constitutes an entire home as “smart”? Well, what exactly constitutes an entire human being as “smart”? Smart is a big word, and it really just boils down to one thing: demands and expecta… Two things: demands and expectations. And work.</p><p>What I wanted most of my house is:</p><ul><li>A smart water heater</li><li>A smart air conditioner</li><li>Smart lights</li></ul><p>That for me would be the bear minimum for my smart home to earn this title. I learned quickly that this was a slippery slope. But hey, people pay big money for slippery slopes…</p><p>So I started off by using these three brands:</p><ul><li><a href="https://www.switcher.co.il/">Switcher</a> smart water heater: <strong>$78</strong> (only applicable to Israel, but you can probably find even cheaper local stuff)</li><li><a href="https://sensibo.com/products/sensibo-sky">Sensibo Sky</a> smart AC remote: <strong>$119</strong> (but sometimes there are special sales, like last Valentine’s Day or this Easter, when it went for only $99)</li><li><a href="https://www.gearbest.com/smart-lighting/pp_361555.html">Yeelight LED Bulbs</a>: <strong>$19</strong> (with a usual, almost all-year discount). Much cheaper than the competitors, and don’t require a hub or gateway (also a disadvantage, this can clutter your router quite fast if you buy a bunch of them, as they each connect to your router as separate clients)</li></ul><p>So far: <strong>$216</strong>.</p><p>All of these come with dedicated apps. Nice, but not convenient-nice. I wanted one place to control all of these stuff (ready to hit the slopes). So, I bought a Google Home Mini to control all of these with my voice. This set me back another <strong>$40 </strong>(this was after the $30 sale).</p><p>Already: <strong>$256</strong></p><p><a href="https://medium.com/@avifr/using-google-home-to-turn-on-your-switcher-smart-water-heater-ee511f140226">Using Google Home to Turn on Your Switcher Smart Water Heater</a></p><p>So far I already have a home with smart lights, water heater and AC for less than $260.</p><p>This was nice, but now my living room lights (bought 4) were only switchable using the app or Google Home (the light switch itself has to remain on). What if I wanted to just turn them on with a switch?</p><p>Well for that I wanted to buy a smart switch: a button that could control my lights if someone (perhaps less tech-savvy) wants to just turn on the lights by hand. The cheapest options were, again, <a href="https://www.gearbest.com/access-control/pp_626695.html">Xiaomi</a> (Aqara, to be exact). They run for around $9, but alas: They require the Xiaomi Gateway, which is Xiaomi’s hub for smart devices. There are two main types, the <a href="https://www.gearbest.com/living-appliances/pp_344667.html">2nd</a> &amp; <a href="https://www.gearbest.com/power-strips/pp_640724.html">3rd</a> generation. They cost $27 and $34, respectively, but the good news is that the 3rd generation also functions as a smart AC remote (which can replace the Sensibo Sky). I went for the 2nd generation, since I don’t need an AC remote, but it might be a good options for whomever is just starting to build his smart home (again, haven’t tried it, can’t recommend it).</p><p>The gateway gives you additional options for your smart home. For example, I added a <a href="https://www.gearbest.com/access-control/pp_626703.html">door sensor</a> so I could tell when the front door is open. This is an additional $13, but was a really good thing for me.</p><p>This sets you back an additional $49 for a total of : <strong>$305.</strong></p><p>Now here’s the catch: The Yeelight light bulbs only work with Google Home if they are set to the Singapore server (or any other server which isn’t Mainland China, because well, China…). But the gateway only works with the Mainland China server (here’s a very long forum entry about this, with the confusing title <a href="http://forum.yeelight.com/t/finally-mihome-gateway-supports-singapore-server/2470"><em>Finally, MiHome gateway supports Singapore server</em></a>).</p><p>So, I couldn’t use the smart switch I bought, which worked using the gateway, with the Yeelights, and still be able to use Google Home with the lights. Real annoying.</p><p>My solution, and as I’ve mentioned before this is going to be a ride, was to use another component, which could communicate with everything, to solve this issue. In comes <a href="https://home-assistant.io/">Home-assistant</a>. It’s an open source home automation platform… you know what, I’ll let them explain:</p><blockquote>Home Assistant is an open-source home automation platform running on Python 3. Track and control all devices at home and automate control. Perfect to run on a Raspberry Pi.</blockquote><p>What started as a solution to connect between my gateway and Yeelight bulbs turned out to be much more powerful and handy. It’s easy to use, but offers extensive capabilities. It caters to both people with experience in code and networking, and to the less knowledgeable (though you do need to be at least a little technically inclined). You can simply add capabilities to it by editing YAML configurations, or you can go even deeper and write Python scripts, or fork it and add support for other devices (as it is open source). Plus, you get the full advantage of an open source project, with a big community and support.</p><p>I’ve been running it on a Raspberry Pi Zero W (with wifi connectivity), which cost me an additional <strong>$30 </strong>with all the accessories:</p><ul><li><a href="https://www.gearbest.com/raspberry-pi/pp_1088924.html">Ras Pi Zero W with case</a></li><li><a href="https://www.gearbest.com/raspberry-pi/pp_437602.html">Power Adapter</a></li><li><a href="https://www.gearbest.com/tablet-accessories/pp_715479.html">Micro USB to USB OTG adapter</a></li></ul><p><strong>Total cost: $335.</strong></p><p>On the next posts I’ll try and dive a little more into how I set up my home-assistant, how I use it to link between the Xiaomi switches and Yeelight bulbs and how I configured it to send me messages every time the front door opens.</p><p>I should mention that by this time my router was starting to choke. Weird things started to happen, which led me to the inevitable conclusion that my cheap router isn’t going to handle this for too long. Also, now that I have so much crucial stuff connected to my home wifi I needed a better, more robust and more secure router. I ended up buying another router for an additional $150…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a93ec4d5c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Road To Infrastructure as Code: Part 2]]></title>
            <link>https://medium.com/innovid/the-road-to-infrastructure-as-code-part-2-f02943af47d9?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/f02943af47d9</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[troposphere]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 11:37:51 GMT</pubDate>
            <atom:updated>2018-02-22T11:37:51.414Z</atom:updated>
            <content:encoded><![CDATA[<h4>Cloud Formation caveats and how to avoid them</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1y8OMQqMkT97ekfi84nU9A.jpeg" /></figure><p>On <a href="https://engineering.innovid.com/the-road-to-infrastructure-as-code-part-1-8d65c336ad92">part 1</a> of this series of posts we talked a little about why we chose <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a> to manage our infrastructure. On this part we’ll focus on some issues we had when creating our CF framework, and what are the things you should be aware of when working with CF.</p><p><a href="https://engineering.innovid.com/the-road-to-infrastructure-as-code-part-1-8d65c336ad92">The Road To Infrastructure as Code: Part 1</a></p><p>Just to recap: We’re using CloudFormation and <a href="https://github.com/cloudtools/troposphere">Troposphere</a> to generate templates to describe our infrastructure, using different main Python files for each stack we’re creating. Specific resource parameters were defined in configuration YAML files, while utilizing some common code to create common cross-stack resources based on the configuration.</p><p>We decided on creating CF templates for each of our main business domains, rather than for each module separately. This was mainly because it’s actually easier to manage a small number of big stacks (given you’re managing them as code, and not big JSON files) than to manage a large number of small stacks, each one dependent on other stacks. The latter leads to a huge puzzle you need to start figuring how to build when first creating all of your infrastructure, and when updating or deleting resources which depend on other resources.</p><p>Having big stacks leads to other issues, and we’ve hit them pretty fast.</p><h4>Problem: Stack file size is limited</h4><p>Right off the bat we hit our first wall: stacks are limited in file size: 51,200 bytes.</p><h4>Solution: Go through S3</h4><p>To avoid this issue you have the choice of going through S3 when uploading and updating your stacks. We had to start going through S3 for all of our stack operations. You should take this into consideration right from the start, designing your pipeline accordingly (even when <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-validate-template.html">validating</a> your stacks). We don’t even use S3 to save our templates, we have our build server for that (and the state itself is being managed by AWS). We just use it as a “relay station” to circumvent the size limitation. It can be a little annoying.</p><p>Even after that, you’ll discover there’s a limitation even on S3 stacks: 460,800 bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6SuLtczWDdlVP7i35a9Gg.png" /><figcaption>Stack size limitations. See all limitations <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html">here</a></figcaption></figure><h4>Problem: Number of resources per stack is limited</h4><p>Each stack is also limited by the number of resources you can declare: 200. We reached this pretty quickly on at least one of our more heavy stacks.</p><h4>Solution 1: Use nested stacks or stack exports</h4><p>The oficial AWS recommendation when hitting the number of resources limit is to separate and nest.</p><p>When we first created our stacks, we had a base layer stack, which we used to declare basic infrastructure and networking that all stacks had in common (for example: VPC, subnets, route tables, internet gateways, DHCP, etc.). This was nested in all other stacks. What nesting basically allows you is to divide your stacks into smaller stacks and avoid this limitation (see: <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-nested-stacks.html">nesting stacks</a>). So all of our main stacks would just need to declare load balancers, target groups, CloudWatch alarms for the LBs and TGs and security groups. That, however, turned out to be also quite a lot of resources, as we were creating a lot of CW alarms for each LB and TG.</p><h4>Solution 2: Defining your security group rules more effectively</h4><p>When we first declared our security groups and security groups rules we used 3 types of resources:</p><ul><li>AWS::EC2::SecurityGroup</li><li>AWS::EC2::SecurityGroupIngress</li><li>AWS::EC2::SecurityGroupEgress</li></ul><p>These are 3 different resources. You first declare all of your SGs, then all of the rules. You have to do this when your SG rules reference other SGs in the template, but when you have rules for fixed IPs (or open for all rules, which allow access from 0.0.0.0/0) you can nest these rules inside the main SG resource, saving on number of resources. This, however, can lead to some exotic issues like <a href="#12f8">this</a> one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*2rieMmcRm3bHQ3_Km_O55Q.png" /><figcaption>A SG ingress rule defined inside a SG resource</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*4iAgXVsU1gRwf77MmYqu7w.png" /><figcaption>A SG ingress rule defined as a separate SG Ingress resource</figcaption></figure><p>When we hit the number of resources limit we had to start dividing the stack into several stacks. We seperated our CW alarms stack into a separate stack. We didn’t have to nest this stack in the main stack, because nothing in the main stack referenced the CW alarms stack. However the CW alarms stack did need values from the main stack to create alarms for the resources there. So, we had to use <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-exports.html">exported output values</a> to export LB and TG IDs and use them in the CW alarms stack.</p><p>We deploy updates on the main stack, and then auto-trigger updates to the alarms stack. This adds some complications, mainly when you want to remove a resource (or even change a resource in a manner that requires a replacement, which is done automatically by CF). Now, you can’t deploy this change as you would normally would, because you can’t remove a resource which has another resource depending on its exported value (all the CW alarms). You would need to run your update in reverse, first running it on the CW alarms stack, then on the main stack. This isn’t always intuitive.</p><h4>Problem: Nested stacks reduce your ability to review changes</h4><p>Using nested stacks has some big disadvantages too. Mainly: reducing your ability to overview your changesets before applying these changes to a stack. We’re utilizing the process of <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets.html">create-changeset</a> &amp; execute-changeset (as opposed to straight template-update) so we can review big changes before we apply them. When working with a single stack this is very easy and straightforward: you execute a changeset, go into the dashboard, and review it. You could see exactly what’s about to change:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*GBwlzW_OvKESc1VD3XKKbg.png" /><figcaption>An example of a changeset</figcaption></figure><p>So you would see exactly what would be removed, created or modified. The problem is that nested stacks work by uploading the nested stack to S3, and linking to it on the father stack. So, when creating a changeset, CF has no real idea whether the resources on the nested stack have changed. Thus, every resource that depends on them in the father stack might also need a change, but CF can’t tell you for certain. All of these “possible changes” appear on the changeset. The only way to know they are changes created because of a nested stack dependency is to look at the details of the changeset, which is a json file in the changeset section in the dashboard. These changes will appear with a property of: evaluation: Dynamic which means they will be evaluated for changes by looking if the nested stack has changed. Since you can’t update nested stacks using changesets (as they are just files on S3) you have to take a leap of faith here, relying on your build server. In addition, this adds a lot of white noise to the changeset-validation process.</p><p>Here’s how this change looks when you analyze the changeset details (note the evaluation type):</p><pre>&quot;resourceChange&quot;: {<br>      &quot;logicalResourceId&quot;: &quot;AragornappStageELB&quot;,<br>      &quot;action&quot;: &quot;Modify&quot;,<br>      &quot;physicalResourceId&quot;: &quot;SomeAutoGeneratedID-withrandomhash&quot;,<br>      &quot;resourceType&quot;: &quot;AWS::ElasticLoadBalancing::LoadBalancer&quot;,<br>      &quot;replacement&quot;: &quot;Conditional&quot;,<br>      &quot;details&quot;: [<br>        {<br>          &quot;target&quot;: {<br>            &quot;name&quot;: &quot;Subnets&quot;,<br>            &quot;requiresRecreation&quot;: &quot;Conditionally&quot;,<br>            &quot;attribute&quot;: &quot;Properties&quot;<br>          },<br>          &quot;causingEntity&quot;: &quot;BaseVpcStage.Outputs.CSubnet&quot;,<br>          &quot;evaluation&quot;: &quot;Dynamic&quot;,<br>          &quot;changeSource&quot;: &quot;ResourceAttribute&quot;<br>        },<br>...</pre><h4>Problem: Changing SG rules may have unexpected consequences</h4><p>As <a href="#2a6d">mentioned</a>, in order to reduce the number of resources we also changed our code to distinguish between fixed IP rules and rules that depend on other SGs, moving the fixed IP rules inside the SG resource itself in the template. Once doing that, and running the update, we suddenly noticed a drop in requests for some of our services, followed by a correction. Finding out what happened required some digging, as it wasn’t that obvious from the changeset, nor from looking at the actual events that occurred during the update.</p><p>Here’s what happened:</p><p>CF is usually pretty smart when it needs to replace existing resources. It will add a new resource, then delete the old one, thus preventing a situation where the resource disappears before it is replaced. However, the change we made resulted in some SG rules being moved from being a separate AWS::EC2::SecurityGroupIngress resource to being a rule inside a AWS::EC2::SecurityGroup resource. CF couldn’t tell this is the same rule, so it didn’t make sure to create the new rule before removing the old one. The end result was instances that couldn’t be reached for a short period of time as the changeset was being executed.</p><p>This is something that you can’t really tell reviewing the changeset beforehand.</p><h4>Solution: Run on development environments first, review events.</h4><p>Always start by running your changes on some sort of test environment (even a live environment that you’re using to run unit and system tests). Review the events that occurred during the change, and make sure nothing looks odd or unexpected. Make sure any resource replacements you see occur in the expected order.</p><h4>Problem: Template changes are always changes, even when they’re not</h4><p>Cloud Formation doesn’t really know the state of your resources. It manages its own state, based on the templates it has. This means that even if you add an attribute to a resource which is essentially identical to its current state in the resource, CF still looks at this as a change in the resource’s state. This might lead you to a situation where a resource would be replaced even though nothing has really changed.</p><p>Take for example the following scenario (this is a true story, the events depicted took place… at the request of the survivors, the names have been changed… etc.): You have an ALB (application load balancer) resource in your template for which you haven’t specified any scheme (internet-facing or internal). The default is internet-facing, thus the ALB created is internet-facing. Later on, you add a scheme attribute to the template, specifying internet-facing for this ALB. Cloud formation will register this as a change, and not just a regular change, but one that requires a replacement of the current ALB.</p><h4>Solution: Always review your changeset.</h4><p>There are no small changes, only careless developers.</p><h4>Problem: Using the “name” attribute for ALBs leads to some unexpected issues</h4><p>The aforementioned ALB changeset led to an even bigger problem, stemming from a bug on AWS’s side: the end result of this changeset has been a <strong>complete removal</strong> of the aforementioned ALB. As explained by a support representative, what happened in reality was as follows:</p><ol><li>CF detects a change in resource which necessitates a replacement. The flow is therefore: create a new resource, then delete the old one.</li><li>A creation command is sent to the API to create a new ALB.</li><li>Because we specifically used the name attribute to explicitly name our ALBs, and CF uses this name to create the unique ALB ARN (ID) for each ALB, the API simply returns “successful” instead of failing.</li><li>A removal is then executed on what CF thinks is the old resource but is actually the same existing resource.</li><li>The ALB is therefore removed entirely.</li></ol><h4>Solution: Never use explicit names for resources</h4><p>AWS has mentioned working on a fix to this bug, and this might already be fixed, but as a good rule of thumb it’s best to always let CF create names for you instead of specifying them explicitly. CF will usually choose a name from your template’s node name, adding some random strings to it.</p><p>It might be more difficult to have resource names you don’t control and that are dynamic, since you might be relying on the names for monitoring or deployment, but you shouldn’t get too attached to resource names anyhow.</p><h4>Problem: Testing changes is limited</h4><p>One of the main disadvantages in CF (and other similar frameworks) is the lack of a good testing framework. There’s no available way to actually test your changes with even as much as a dry-run. Yes, AWS offers you the ability to validate your templates, but that’s just static validation (which even then doesn’t assure you that your template is correct). Sadly, you can’t rest assure your changes won’t have weird side effects or unexpected results.</p><p>Even worse than that, you’ll never be sure your stacks could run from scratch successfully, since with time you just run the deltas from your previous configuration. And one of the benefits of having your infrastructure as code is being able to recreate it all from scratch easily.</p><h4>Solution: Make use of different environments, test it yourself</h4><p>To make sure your stacks are well tested there are two main scenarios you need to worry about:</p><ul><li>Making sure your stacks are recreatable from start to end.</li><li>Making sure your current delta (changeset) has no unexpected side effects.</li></ul><p>Testing the 2nd scenario is pretty easy as long as you run your changes through different non-production environments before running it on your production environment. This doesn’t ensure your changeset won’t fail when running on your production environment (unless you know for sure your state wasn’t changed there), but at least the first time you’re surprised with some weird events won’t be in production.</p><p>The 1st scenario can be easily overlooked. We had changes that totally broke our ability to run our templates from scratch, but weren’t aware of that since we didn’t have any flow to test them from start to finish. Your update flow should always include creating all of your stack from scratch, and then tearing it down. AWS has a solution for this kind of pipeline <a href="https://aws.amazon.com/answers/devops/aws-cloudformation-validation-pipeline/">here</a>, but it relies on your entire tech stack being on AWS (using their CodeCommit, CodePipeline and CodeBuild). You can also create your own build pipeline to achieve this.</p><h4>Problem: Applying a lot of small, unrelated changes may lead to conflicts</h4><p>You never really want a continuously deployed CF system, for all the obvious reasons that we’ve mentioned so far. Changes have to be reviewed, even if they <strong>appear</strong> to be small changes. Real life changes will then tend to stack up sometimes. Changes that different developers pushed but haven’t executed yet, leading to changes that conflict or interfere with other changes.</p><h4>Solution: Never allow changes to stack up</h4><p>You should monitor your CF pipeline in any way you prefer, and make sure delayed deploys are alerted and treated promptly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f02943af47d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innovid/the-road-to-infrastructure-as-code-part-2-f02943af47d9">The Road To Infrastructure as Code: Part 2</a> was originally published in <a href="https://medium.com/innovid">Innovid</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Google Home to Turn on Your Switcher Smart Water Heater]]></title>
            <link>https://medium.com/@avifr/using-google-home-to-turn-on-your-switcher-smart-water-heater-ee511f140226?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee511f140226</guid>
            <category><![CDATA[ifttt]]></category>
            <category><![CDATA[smart-home]]></category>
            <category><![CDATA[google-home]]></category>
            <category><![CDATA[switcher]]></category>
            <category><![CDATA[webhooks]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 06:01:01 GMT</pubDate>
            <atom:updated>2018-01-22T06:01:01.217Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Google Home To Turn On Your Switcher Smart Water Heater</h3><h4>Google Home + IFTTT + Switcher (Israeli smart water heater)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lt5yM20HxBexWPGBofLgTw.png" /></figure><p>In Israel we have a nice and basic smart electrical water heater called <a href="https://www.switcher.co.il/">Switcher</a>. It’s a pretty basic appliance that connects to your apartment’s electrical water heater pretty easily (just need to connect some electrical wires <strong>very carefully</strong>). It has a basic android + iOS app. (everything is in Hebrew, sorry…)</p><p>I keep saying basic because it doesn’t really look like the people behind this thing are really passionate about smart homes, and smart home integrations. It has no integration with any other service (Google home, Amazon Alexa, IFTTT…) so you can’t use it with any external service. It doesn’t even have an open API you can use.</p><p>Well, it sort of does. You just have to look more deeply. Here’s how you can use IFTTT to connect your Switcher to devices like Google home or Amazon Alexa (I used Google home, but this can easily be applied to any other service) and turn your water heater on / off easily.</p><p>Note: there’s also a cheaper water heater with built-in support for Google home and Alexa called <a href="https://www.switcheat.co.il/shop">Switcheat</a> that didn’t exist when I bought my Switcher a long time ago. Never tried it though.</p><h4>Revealing the Switcher’s API</h4><p>I’m using the V1 Switcher, so this guide is only relevant for it. I’m not sure if the V2 operates any differently, but I’m pretty sure the API calls are the same. I see no reason they would maintain two flows on their server for two different APIs and not update the V1 app to use the new API.</p><p>The Switcher water heater doesn’t have any good and open documentation. I can understand that, as it seems the Switcher doesn’t really employ any decent security on its API calls, or even tries to hide any of its server errors from the user. I tried contacting support to try and understand if they intend on opening their API for easy public access, but I’ve never heard back. In general, it feels like the people behind this water heater aren’t that passionate about what they do. Luckily, we are.</p><p>You can find out what API calls your Switcher app is making pretty easily by setting up a proxy server on your computer and rerouting all your mobile traffic through it. I use <a href="https://www.charlesproxy.com/">Charles</a> which is a paid software, but you can also use any other free alternative like <a href="https://www.telerik.com/fiddler">Fiddler</a> (Windows only) or <a href="https://www.wireshark.org/">Wireshark</a>. Setting this up is pretty easy and there are many online guides on how to do this, like <a href="https://community.tealiumiq.com/t5/Tealium-for-Android/Setting-up-Charles-to-Proxy-your-Android-Device/ta-p/5121">this one</a>.</p><p>After setting the proxy and opening the switcher app, you can see all the HTTP requests it makes. Yes, that’s right, <strong>HTTP</strong> requests. not HTTPS. All the API calls are basically just HTTP requests with query parameters. You can play around with the app and see all API calls, but basically the one call relevant to us is:</p><pre>http://server.switcher.co.il/Switcher/appServiceSetSwitchState?token=&lt;TOKEN_HERE&gt;&amp;switchId=&lt;ID_HERE&gt;&amp;state=&lt;on/off&gt;</pre><p>It’s pretty straight forward. You have the heater’s ID which is a given. You can also see your token, which I can only guess changes perhaps when you log out, but I’ve never checked and it hasn’t changed. The state is the state you want to set the heater to: on or off.</p><p>That’s it. Very basic. If you own this heater I’d be aware of this when I think about using the Switcher app on any wifi network that I don’t control.</p><p>Now, we can control our Switcher ourselves with simple API calls. We can utilize IFTTT to connect our Google home to the Switcher.</p><h4>Creating an IFTTT recipe</h4><p>If you haven’t heard of <a href="https://ifttt.com/">IFTTT</a>, it’s about time you do: IFTTT stands for: “If This Then That”. It’s basically a very powerful service which lets you connect any two accounts or services and create recipes that define triggers that trigger one service using an event from another service.</p><p>For example, you can create a recipe to add a row in a google spreadsheet when you get a call on your Android device, or add a photo to your Dropbox when someone tags you in a photo on Facebook, etc.</p><p>IFTTT works with a lot of smart devices. The possibilities are practically endless with the IFTTT <a href="https://ifttt.com/maker_webhooks">webhook</a> channel: it allows you to send an HTTP request to any URL with a given body. So we can use it to create a recipe that connects the Google assistant channel with an API call to the Switcher URLs:</p><ul><li>Create a new IFTTT recipe for turning the water heater on.</li><li>On the “This” part, choose the Google assistant channel.</li><li>Choose what phrase(s) you’d like to say to activate this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*KlKHdvJurjGzLyLbIurk-Q.png" /><figcaption>An example for the Google assistant trigger</figcaption></figure><ul><li>For the “That” part, choose the Webhook channel and configure a GET request to the URL we’ve seen in the app API calls:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*gBRTWaA4t1yL8PSSp2DyHQ.png" /><figcaption>An example for the webhook configuration. All other fields are optional.</figcaption></figure><p>That’s it! Save this recipe. You should create another one identical, but for turning the heater off (that’s a home assignment).</p><p>I’ve tried making a recipe for more complicated scenarios, like turning the heater on for a given amount of time, but the webhook channel doesn’t support any math operations or any kind of manipulation on any variables, and since the duration is sent in milliseconds, and I don’t want to say “Hey, Google! Set my water heater on for 1700000 milliseconds”, I think I’ll settle for turning it on and off.</p><p>These will all work until they get their act together and switch to HTTPS with a concealed token. Maybe when they do, they’ll also add support for IFTTT, Google home and Alexa.</p><p>Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee511f140226" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a highly-available Chef cluster]]></title>
            <link>https://medium.com/innovid/setting-up-a-highly-available-chef-cluster-a790098569fe?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/a790098569fe</guid>
            <category><![CDATA[chef-cluster]]></category>
            <category><![CDATA[chefs]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[chef-ha]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Thu, 07 Sep 2017 11:32:35 GMT</pubDate>
            <atom:updated>2017-09-07T11:32:35.166Z</atom:updated>
            <content:encoded><![CDATA[<h3>Highly-available Chef cluster</h3><h4>setting up a highly-available chef cluster in AWS</h4><p>Here at <a href="http://www.innovid.com/">Innovid</a>, a leading video marketing platform where we serve 1.3 million hours of video per day, we’ve used <a href="https://www.chef.io/chef/">Chef</a> to manage our AWS instances for years now, but only recently transitioned it to a highly available cluster. In order to do so, we’ve followed the comprehensive <a href="https://docs.chef.io/install_server_ha.html">documentation</a> given by the fellows at <a href="https://www.hashicorp.com/">Hashicorp</a>. <br>Our cluster architecture was built with:</p><ul><li>3 backend nodes</li><li>2 frontend nodes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*KfeliFh-cLdw8mOrQGkC1A.png" /><figcaption>Cluster topology (adapted from: <a href="https://docs.chef.io/install_server_ha.html">https://docs.chef.io/install_server_ha.html</a>)</figcaption></figure><p>After spinning up these 5 instances in different availability zones (according to the chef-ha documentation, it currently doesn’t support cross-region deployment) in a single VPC (3 different subnets — 1 for each backend), we attached them to 2 security groups (described here in YAML form, which we parse in our <a href="https://github.com/cloudtools/troposphere">Troposphere</a>+<a href="https://aws.amazon.com/cloudformation/">CloudFormation</a> tool to create these security groups in AWS):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b5f557d5892fe9ac39d00501d293e2f/href">https://medium.com/media/7b5f557d5892fe9ac39d00501d293e2f/href</a></iframe><p>Note that we have 3 SGs: The third SG is for the <a href="https://aws.amazon.com/elasticloadbalancing/applicationloadbalancer/">ALB</a> which we connect our 2 frontends to.</p><p><strong>Important note:</strong> we started first by creating specific egress (outbound) rules, as per the documentation. That worked for quite a while. After a couple of months we started seeing issues with the cluster. After some digging, and great help from the Chef Slack community (which we highly recommend you join <a href="http://community-slack.chef.io/">here</a>), we found out these issues were caused by the clocks on the backend nodes shifting out of sync from each other (the Ubuntu NTP couldn’t sync since it needs outbound UDP on port 123). We’ve since opened the instances for all outbound traffic.</p><p>Next, we wrote the following script to create the cluster programmatically. <br>In order for it to work you’ll need:</p><ul><li>All nodes must be on the same VPC (to allow access from each node to the rest). They can be on different subnets, as long as routing is enabled between subnets.</li><li>A configured <a href="https://aws.amazon.com/cli/">AWS CLI</a>, which the script uses to extract instances info.</li><li>Nodes should have a “Name” tag, which the script uses to search for the node and extract its IP (tag: Name=some-name). You can change the names in the script.</li><li>Chef server version &gt; 12.14 (script uses 12.15.8). Earlier versions require some extra <em>.pem</em> files to be copied from the first frontend to the second before configuring it. It would still work for the cluster of backends + first frontend.</li></ul><p>You can find the script below or <a href="https://gist.github.com/innovid-rnd/0d44ca371ac040dee3b14c57c2abd17f">here</a>. You can change it to fit your needs, or even just use it as a step-by-step guide to create the cluster.</p><h3>Issues we came across</h3><p>In an earlier version of chef-backend (we used 1.3.2) there was apparently some issue with adding and removing nodes.</p><p>We wanted to replace all the nodes in the cluster, so we started off by adding 3 more nodes, then wanted to start removing old nodes. As soon as we removed the nodes, the cluster went haywire. The Elasticsearch service on all nodes started failing with weird messages in the log:</p><pre>2017-02-15_15:13:22.62732 [DEBUG][action.admin.cluster.health] [c1e85a03d38320f23e31e9c1c562f013] no known master node, scheduling a retry</pre><pre>2017-02-15_15:13:22.60354 [DEBUG][action.admin.cluster.health] [c1e85a03d38320f23e31e9c1c562f013] timed out while retrying [cluster:monitor/health] after failure (timeout [2s])</pre><pre>2017-02-15_15:13:22.60403 [WARN ][rest.suppressed          ] /_cluster/health Params: {timeout=2s}</pre><pre>2017-02-15_15:13:22.60404 MasterNotDiscoveredException[null]</pre><p>and the status of the Elasticsearch service was offline. After many attempts to understand what’s going on, the help came (again) from the Chef community. A bug in Chef (that seems to have been fixed, since this hasn’t happened to us in the newer version) caused the value of discovery.zen.minimum_master_nodes: 1 from the Elasticsearch configuration to increase when adding nodes, but not decrease upon removal of nodes.</p><p>To fix that, we did the following:</p><ol><li>Rejoin the cluster from another node (to have a 4th node). This will probably fail, due to ElasticSearch not being able to connect, however, you’ll still be a part of the cluster (you can check that 4 nodes exist with sudo chef-backend-ctl status)</li><li>Type the following command in one of the nodes (this will reduce the minimum_master_nodes back to 2):</li></ol><pre>curl -XPUT localhost:9200/_cluster/settings -d &#39;{&quot;persistent&quot; : {&quot;discovery.zen.minimum_master_nodes&quot; : 2}}&#39;</pre><p>now, remove the 4th node:</p><pre>chef-backend-ctl remove-node &lt;4th.node.ip.address&gt;</pre><p>Note: we used the IP of the node (in our case, private IP, but it depends on how you created the cluster). The node will not be showing with its name in cluster-status due to it being only partly-joined.</p><p>Next, verify your services are now ok and running 3 nodes at a healthy state by running sudo chef-backend-ctl status.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6853184f1f58edc0375473b6f921d7be/href">https://medium.com/media/6853184f1f58edc0375473b6f921d7be/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a790098569fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innovid/setting-up-a-highly-available-chef-cluster-a790098569fe">Setting up a highly-available Chef cluster</a> was originally published in <a href="https://medium.com/innovid">Innovid</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Road To Infrastructure as Code: Part 1]]></title>
            <link>https://medium.com/innovid/the-road-to-infrastructure-as-code-part-1-8d65c336ad92?source=rss-5205d10b6022------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d65c336ad92</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Avi Friedman]]></dc:creator>
            <pubDate>Wed, 30 Aug 2017 12:39:35 GMT</pubDate>
            <atom:updated>2018-03-02T14:37:45.883Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why we chose CloudFormation &amp; Troposphere to manage our infrastructure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Z7BjkasC8Kx5JtZ7N5Pe2A.gif" /><figcaption>I bet the robots knew how to do it. image from: <a href="http://giphy.com/">giphy.com</a></figcaption></figure><p>For years now at Innovid, a leading video marketing platform where we serve 1.3 million hours of video per day, we’ve been using <a href="https://www.chef.io/">Chef</a> to manage our AWS EC2 instances. Managing our machines this way is an essential part of being able to manage and configure the infrastructure for all of our different services, essentially describing our entire EC2 infrastructure as code. Writing your infrastructure as code introduces all the benefits of code into your infrastructure stack (for us: our servers), including:</p><ul><li>Version control</li><li>A single-source-of-truth</li><li>Testing</li><li>Automating deployment pipelines</li><li>Scalability</li></ul><p>There’s really no other way to do it in a company that handles a lot of resources. However, Any infrastructure outside of our EC2 instance was created, tweaked and managed manually. This included stuff like load-balancers, security groups, networking etc. We’ve managed to pull it off quite well because although server configuration might change more often (instances created and stopped, different packages, modules and plugins being updated, added or removed), the underlying infrastructure hasn’t changed that often.</p><p>Lately, we started a big shift, migrating our entire classic-EC2 infrastructure into AWS <a href="http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Introduction.html">VPC</a>. This was a golden opportunity to create our entire infrastructure in a better way: the <a href="https://en.wikipedia.org/wiki/Infrastructure_as_Code">IAC</a> way. The benefits are pretty self evident, as we’ve already known from managing our instances this way. Having our entire infrastructure handled the same way could give us all the benefits we’re getting from IAC for our entire infrastructure. Most importantly, for a company that feels just the right size between a corporate and a garage startup, managing our infrastructure this way would give our developers more freedom and control over the infrastructure they need for their modules and would alleviate the pressure on our DevOps ninjas.</p><p>When faced with the task of choosing an IAC tool, there are many solutions out there, including:</p><ul><li>Chef (or Amazon’s <a href="https://aws.amazon.com/opsworks/">OpsWorks</a>)</li><li><a href="https://puppet.com/">Puppet</a></li><li><a href="https://www.ansible.com/">Ansible</a></li><li><a href="https://www.terraform.io/">Terraform</a></li><li><a href="https://aws.amazon.com/cloudformation/">CloudFormation</a></li></ul><p>We looked for a tool that would be:</p><ul><li>Powerful &amp; versatile (to support as much as possible the available configuration on our cloud provider).</li><li>Easy to implement &amp; manage.</li><li>Well-documented, supported &amp; stable.</li></ul><p>Chef was ruled out off the bat. While it’s surely all of the above, and while we already use it extensively (as aforementioned) to manage our instances, so we have the knowledge, experience and an up-and-running chef server cluster, Chef isn’t that good yet for managing all of our AWS underlying infrastructure as-is, but more as a tool to manage the infrastructure of our different roles. We weren’t keen on using it to define and manage all of the shared infrastructure between them. <br>Eventually it came down to Terraform vs. Amazon’s CloudFormation. That was a harder choice to make.</p><h3>Terraform</h3><p>Terraform is a tool created and maintained by <a href="https://www.hashicorp.com/">HashiCorp</a>. It’s an open source tool that allows you to write your infrastructure across cloud service providers in HCL (HashiCorp Configuration Language), for example:</p><pre>provider &quot;aws&quot; {<br>  access_key <strong>=</strong> &quot;${var.access_key}&quot;<br>  secret_key <strong>=</strong> &quot;${var.secret_key}&quot;<br>  region     <strong>=</strong> &quot;${var.aws_region}&quot;<br>}</pre><pre>resource &quot;aws_vpc&quot; &quot;default&quot; {<br>    cidr_block           = &quot;172.30.0.0/16&quot;<br>    enable_dns_hostnames = <strong>true<br>    </strong>enable_dns_support   = <strong>true<br>    </strong>instance_tenancy     = &quot;default&quot;<br>}</pre><p>Currently the last stable version is 0.9.5, so it’s even pre 1.0.0. Though there’s some documentation online on the Terraform page, and some blogs describing people’s experience with Terraform, it’s still not that mature.</p><h3>CloudFormation</h3><p>In CloudFormation, the “code” is managed using json templates (YAML templates also hold). It’s a proprietary tool created and managed by Amazon specifically for use in AWS. It’s as closest as you can get to support all of AWS resources configuration, very versatile, documentation is aplenty, it’s stable (give or take some bugs, but we’ll dive into that in later posts), reliable, and as clients of Amazon’s enterprise support plan we get all the support we need.</p><p>Now, I know what you’re thinking…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*x2_5MAQTLiLiZYO8XLQUEw.jpeg" /></figure><p>That’s where <a href="https://github.com/cloudtools/troposphere">Troposphere</a> comes into play. Troposphere is a Python library for creating CloudFormation as Python code, that can be rendered into the appropriate json template. This means defining and managing all of our templates is as easy as writing Python code, with all the associated power that comes with it. The above code in Terraform would translate into:</p><pre><strong>from </strong>troposphere.ec2 <strong>import </strong>VPC</pre><pre>template = Template()</pre><pre>template.add_resource(<br>    VPC(<br>        &#39;default&#39;,<br>        CidrBlock=&#39;172.30.0.0/16&#39;,<br>        EnableDnsHostnames=True,<br>        EnableDnsSupport=True<br>    ))<br>template.to_json()</pre><p>One could argue this is uglier than HCL, But it’s a simple example. As you start to require more advanced stuff, you get really tired of HCL… It would have been much better if we could have used a combination of code and <a href="https://en.wikipedia.org/wiki/Domain-specific_language">DSL</a>, like in Chef with Ruby.</p><h3>Terraform Vs. CloudFormation</h3><h4>Powerful &amp; versatile:</h4><p>Terraform is written in declarative code. While it does have some advanced abilities, like using interpolation syntax, variables and functions, it’s still limited. You can’t read complex configuration files, iterate over arrays or objects, or even do something as simple as using a variable to define a resource’s name dynamically. This can all change of course, but you’re still bound to HCL, as opposed to Python using Troposphere.</p><p>Terraform seems to have adequate support for everything you’ll want to achieve in AWS, but it’s still in pre 1.0.0 version (started in 2014), while Troposphere is currently at v. 1.9.3 (started in 2013), and CloudFormation itself dates back to 2010, and is probably the the most accurate and up-to-date representation of your AWS configuration. This is of course at the price of using a proprietary AWS tool, meaning you’re increasing your dependency in one cloud provider. However, using Terraform still means writing twice the code for every cloud provider (unless we’re speaking about running on different cloud providers at the same time, in that case Terraform would be getting more points on this). Plus, while there’s no easy way to directly convert CF templates to use with Terraform, or to export Terraform as CF templates, switching from CF to Terraform would actually be easier than the other way around. Tools like <a href="https://github.com/dtan4/terraforming">terraforming</a> gives you the ability to import all of your infrastructure as both state files and configuration files. When we tried using it, it worked pretty well. On the other hand, choosing to migrate from Terraform to CloudFormation? That’s a nightmare.</p><p>AWS gives you the ability to export your existing infrastructure as a CloudFormation json template. It provides you with a tool called CloudFormer. This tool is, why not, given as a CloudFormation template (I’m sure there’s a recursion joke hiding here somewhere, but recursion jokes are rarely worth the digging). You use this template to create a stack of resources for a web app that is the CloudFormer tool, which you can then use (so this whole thing costs you money). This tool is still in beta, and has been since it launched way back in 2010. It wasn’t yet supported in the Ohio region (a fairly new region at the time we tinkered with it), meaning you can’t launch it in the Ohio region, or export any resources you have there (again, at least at the time). After scanning all your resources in one region, and selecting all the resources you want (a painstaking procedure), you’re left with a huge json CF template. Then, if you want to use Troposphere, you can use the Troposphere tool <a href="https://github.com/cloudtools/troposphere/blob/master/scripts/cfn2py">cfn2py</a> to convert this to a huge python code, which you’ll then have to tweak (since it’s not a perfect tool, to say the least)… So basically:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*_Fs7LcCXr-vvtkZ9sCiomw.png" /></figure><h4>Easy to implement and manage:</h4><p>Both Terraform and CloudSphere (CF+Troposphere) are basically client based, meaning you don’t need to worry about and maintain any backend servers. In Terraform your state is saved in a .tfstate file. Though you can make use of a backend to save your state (be it an open source like Consul or the HashiCorp enterprise solution) you really don’t have to, and can just manage it anywhere you’d like (like on S3 for example). In CloudFormation, AWS actually provides the backend for saving your state.</p><p>Managing your infrastructure changes is easy with both tools. On Terraform you use the terraform plan and terraform apply commands to get an execution plan to review all changes that will be made to the current state and then apply this plan. Some blogs out there do report on some issues though (for example some latency between regions which can cause the procedure to fail).</p><p>CloudFormation supports the use of change sets, so you can <a href="http://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-change-set.html">create a change set</a>, review it and <a href="http://docs.aws.amazon.com/cli/latest/reference/cloudformation/execute-change-set.html">execute it</a> (using the aws <a href="https://aws.amazon.com/cli/">cli</a> tool). This method has its issues, which we will address in a later post, but basically you can manage your infrastructure pretty conveniently with both tools.</p><h4>Documentation &amp; Support</h4><p>As mentioned, CF documentation is great. Every feature is documented and explained, there are examples for everything, and even if you don’t have enterprise support, your issue is probably already somewhere out there in a forum. As far as Troposphere is concerned, though the documentation itself is a bit lacking, everything is pretty much out there in the Python code. If you want to know what features are supported for something, for example a V2 load balancer, just take a look at the code:</p><pre><strong>class </strong>LoadBalancer(AWSObject):<br>    resource_type = &quot;AWS::ElasticLoadBalancingV2::LoadBalancer&quot;<br><br>    props = {<br>        &#39;LoadBalancerAttributes&#39;: ([LoadBalancerAttributes], False),<br>        &#39;Name&#39;: (elb_name, False),<br>        &#39;Scheme&#39;: (basestring, False),<br>        &#39;SecurityGroups&#39;: (list, False),<br>        &#39;Subnets&#39;: (list, True),<br>        &#39;Tags&#39;: (list, False),<br>    }</pre><p>Terraform’s documentation is not as good as CF, you’ll have a harder time trying to find answers to issues you’re dealing with since its use is not that widespread.</p><h4>Summary</h4><p>Both frameworks have their limitations and caveats, which you should be fully aware of before choosing any side. While Terraform is a great promise, it still felt too early to commit our entire production to it. With time, we get to hear more and more companies speak about their experience with it, and its hiccups. One company we’ve heard about has written a Python wrapper for Terraform. Sounds familiar…<br>As it grows and accumulates more experience, documentation and abilities, and as we start moving more toward immutable infrastructure, it would definitely feel like something we might experiment with in the future. Right now, given that we use AWS as our cloud provider, and the way our infrastructure is built and maintained, it made more sense to go with the more mature, well-documented and supported solution. Not to say it doesn’t have its annoying moments, and we’ll definitely talk about those in the posts ahead…<br>We’ll also point out that we currently still haven’t reached our goal of making our infrastructure immutable. We use CF basically as a configuration management tool, not an orchestration management tool.</p><p>On the next part of this series of posts we’ll dive into how we’ve implemented Troposphere and CloudFormation into our integration and deployment pipeline to manage our infrastructure in the same way we manage our modules and instances.</p><p><a href="https://engineering.innovid.com/the-road-to-infrastructure-as-code-part-2-f02943af47d9">The Road To Infrastructure as Code: Part 2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d65c336ad92" width="1" height="1" alt=""><hr><p><a href="https://medium.com/innovid/the-road-to-infrastructure-as-code-part-1-8d65c336ad92">The Road To Infrastructure as Code: Part 1</a> was originally published in <a href="https://medium.com/innovid">Innovid</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>