{"id":4400,"date":"2021-04-25T17:40:51","date_gmt":"2021-04-25T15:40:51","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=4400"},"modified":"2021-06-28T16:49:59","modified_gmt":"2021-06-28T14:49:59","slug":"cloudformation-7-drift-detection","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2021\/04\/25\/cloudformation-7-drift-detection\/","title":{"rendered":"CloudFormation &#8211; 7 &#8211;  Drift Detection"},"content":{"rendered":"<p><!--more--><\/p>\n<p><span style=\"color: #3366ff;\">Drift Detection<\/span><\/p>\n<p><span class=\"well--text--2H_p0 well--transition-active--35hDP\">Drift is the detection of the fact that a cloud formation template, what has been created, has actually drifted from its configuration because maybe there was some manual intervention.<br \/>\n<\/span><\/p>\n<p>Consider such a yaml template:<\/p>\n<pre class=\"lang:default decode:true \">Parameters:\r\n  VPCId:\r\n    Description: VPC to create the security group into\r\n    Type: AWS::EC2::VPC::Id\r\n  \r\nResources:\r\n  SSHSecurityGroup:\r\n    Type: \"AWS::EC2::SecurityGroup\"\r\n    Properties:\r\n      GroupDescription: Test Drift SSH Security Group\r\n      SecurityGroupIngress:\r\n        - CidrIp: \"10.0.0.0\/25\"\r\n          FromPort: 22\r\n          ToPort: 22\r\n          IpProtocol: tcp\r\n      VpcId: !Ref VPCId\r\n\r\n  HTTPSecurityGroup:\r\n    Type: \"AWS::EC2::SecurityGroup\"\r\n    Properties:\r\n      GroupDescription: Test Drift HTTP Security Group\r\n      SecurityGroupIngress:\r\n        - CidrIp: \"0.0.0.0\/0\"\r\n          FromPort: 80\r\n          ToPort: 80\r\n          IpProtocol: tcp\r\n      VpcId: !Ref VPCId\r\n<\/pre>\n<p>Let&#8217;s create a stack:<\/p>\n<p><code> <img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4406 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation57.jpg\" alt=\"\" width=\"682\" height=\"717\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation57.jpg 682w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation57-285x300.jpg 285w\" sizes=\"(max-width: 682px) 100vw, 682px\" \/><\/code><\/p>\n<p><code>Next-&gt;<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4405 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation58.jpg\" alt=\"\" width=\"693\" height=\"479\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation58.jpg 693w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation58-300x207.jpg 300w\" sizes=\"(max-width: 693px) 100vw, 693px\" \/><\/p>\n<p><code>Next -&gt; Create stack<\/code><\/p>\n<p>CloudFormation has created two security groups:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4407 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation59.jpg\" alt=\"\" width=\"804\" height=\"609\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation59.jpg 804w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation59-300x227.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation59-768x582.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p><span class=\"well--text--2H_p0 well--transition-active--35hDP\">So if I go to security groups I have this :<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4408\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation60.jpg\" alt=\"\" width=\"924\" height=\"340\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation60.jpg 924w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation60-300x110.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation60-768x283.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>Now let&#8217;s initiate drift detection<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4412 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation61.jpg\" alt=\"\" width=\"844\" height=\"607\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation61.jpg 844w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation61-300x216.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation61-768x552.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p><code>Stack actions -&gt; View drift results<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4414 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation62.jpg\" alt=\"\" width=\"809\" height=\"677\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation62.jpg 809w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation62-300x251.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation62-768x643.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>Now, let&#8217;s modify one of the our security groups:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4415 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63.jpg\" alt=\"\" width=\"782\" height=\"783\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63.jpg 782w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63-300x300.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63-150x150.jpg 150w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63-768x769.jpg 768w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation63-100x100.jpg 100w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>When we refresh drifts page we see that the drift has been detected:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4418\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation65-1.jpg\" alt=\"\" width=\"801\" height=\"675\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation65-1.jpg 801w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation65-1-300x253.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation65-1-768x647.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>We can click to the<code> View drift details<\/code> to see the details<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4421 aligncenter\" src=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation66.jpg\" alt=\"\" width=\"775\" height=\"753\" srcset=\"http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation66.jpg 775w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation66-300x291.jpg 300w, http:\/\/miro.borodziuk.eu\/wp-content\/uploads\/CloudFormation66-768x746.jpg 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4400"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=4400"}],"version-history":[{"count":10,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4400\/revisions"}],"predecessor-version":[{"id":4422,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/4400\/revisions\/4422"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=4400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=4400"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=4400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}