<?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 Michael Saparov on Medium]]></title>
        <description><![CDATA[Stories by Michael Saparov on Medium]]></description>
        <link>https://medium.com/@mihma?source=rss-ea95edb25531------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*W19WF9UU3JRyRCYW0i8Yrg.jpeg</url>
            <title>Stories by Michael Saparov on Medium</title>
            <link>https://medium.com/@mihma?source=rss-ea95edb25531------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:58:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mihma/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[Azure Function deployment. DevOps story.]]></title>
            <link>https://mihma.medium.com/azure-function-deployment-devops-story-19d32ffad7a6?source=rss-ea95edb25531------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d32ffad7a6</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Michael Saparov]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 15:14:38 GMT</pubDate>
            <atom:updated>2021-02-23T09:54:19.793Z</atom:updated>
            <content:encoded><![CDATA[<p>One of my recent projects involved the provisioning, deploying and monitoring Azure Function and I’d like to share the experience I gained whilst doing all that.</p><p>First let me briefly describe what the Function is and why we need it at all. Take this flow for example: we have an application which posts messages to the Azure storage queue. Our goal is to read those messages, transform them and create blobs accessible to the consumer of our service. One day it can be over 100 messages, another day it can be nil. Azure Function works perfectly for such case as it will only be triggered and run when the message is queued and we won’t waste compute power and therefore money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnPV1Qzo8ZgR6gEET0DUmg.png" /></figure><p>What we have: main application posting to storage queue and application insights for the monitoring and alerting. We also have a Key Vault for each of our environments.</p><p>Our function will have Managed Identity assigned to allow access to blob storage. In fact the plan was to use MI to read from the queue as well but it appeared that the queue trigger only supports connection string. Another feature request, Microsoft! The same MI is used to access Key Vault in order to get the secrets. For that we’re creating access policy in the Terraform code below.</p><p>Let’s deploy the blob storage account and function which will be integrated with VNet. That means the traffic will not leave VNet and all inbound traffic is blocked. We will only allow access to our consumers whitelisting their public ip addresses on the storage firewall. I will only touch on those particular resources and will not cover app service plan, etc. Mind that we will need Premium app service plan to have that VNet integration.</p><pre>resource &quot;azurerm_virtual_network&quot; &quot;vnet&quot; {<br>  name                = &quot;vnet-function&quot;<br>  address_space       = [&quot;10.0.0.0/16&quot;]<br>  resource_group_name = &quot;rg-function&quot;<br>  location            = &quot;southuk&quot;<br>}</pre><pre>resource &quot;azurerm_subnet&quot; &quot;subnet&quot; {<br>  name                 = &quot;snet-function&quot;<br>  resource_group_name  = &quot;rg-function&quot;<br>  virtual_network_name = azurerm_virtual_network.vnet.name<br>  address_prefixes     = [&quot;10.0.1.0/24&quot;]<br>  service_endpoints    = [<br>    &quot;Microsoft.Storage&quot;,<br>    &quot;Microsoft.Web&quot;<br>  ]</pre><pre>delegation {<br>  name = &quot;azure-function-delegation&quot;</pre><pre>service_delegation {<br>    name    = &quot;Microsoft.Web/serverFarms&quot;<br>    actions = [&quot;Microsoft.Network/virtualNetworks/subnets/action&quot;]<br>    }<br>  }<br>}</pre><pre>#Creating app service plan and storage for the function app here. #We&#39;re not going to cover this.</pre><pre>resource &quot;azurerm_function_app&quot; &quot;function&quot; {<br>  name                       = &quot;function-${random_id.suffix.hex}&quot;<br>  location                   = &quot;southuk&quot;<br>  resource_group_name        = &quot;rg-function&quot;<br>  app_service_plan_id        = azurerm_app_service_plan.plan.id<br>  storage_account_name       = azurerm_storage_account.storage.name<br>  storage_account_access_key = azurerm_storage_account.storage.primary_access_key<br>  https_only                 = true<br>  version                    = &quot;~3&quot;</pre><pre>lifecycle {<br>    ignore_changes = [app_settings]<br>  }<br>  <br>  identity {<br>    type = &quot;SystemAssigned&quot;<br>  }</pre><pre>site_config {<br>    scm_type                  = &quot;VSTSRM&quot;<br>    ftps_state                = &quot;Disabled&quot;<br>    min_tls_version           = &quot;1.2&quot;<br>    pre_warmed_instance_count = 0</pre><pre>ip_restriction {<br>      name                      = &quot;Allow VNet&quot;<br>      virtual_network_subnet_id = azurerm_subnet.subnet.id<br>    }<br>  }<br>}</pre><pre>resource &quot;azurerm_app_service_virtual_network_swift_connection&quot; &quot;vnet_integration&quot; {<br>  app_service_id = azurerm_function_app.function.id<br>  subnet_id      = azurerm_subnet.subnet.id<br>}</pre><pre>resource &quot;azurerm_key_vault_access_policy&quot; &quot;function_kv_policy&quot; {<br>  key_vault_id = var.key_vault_id<br>  tenant_id    = azurerm_function_app.function.identity.0.tenant_id<br>  object_id  = azurerm_function_app.function.identity.0.principal_id</pre><pre>secret_permissions = [<br>    &quot;get&quot;,<br>  ]<br>}</pre><p>Once we have the infrastructure ready we will leverage Azure DevOps pipelines to deploy the function code into Azure. First we will create a template which we will be able to reuse whilst doing staging deployments from dev all the way to production. Templates help in keeping our pipelines dry and avoid copy-pasting. What we need for our function to work is to declare application settings including the queue connection string, application insights key and other parameters which I will touch on below. For that we are using the ADO task doing just that. Also note how earlier we asked Terraform to ignore those settings so they are not going to be removed the next time Terraform runs!</p><pre>lifecycle {<br>    ignore_changes = [app_settings]<br>  }</pre><p>The whole deployment template looks like this:</p><pre>jobs:<br>  - deployment: DeployAzureFunction<br>    displayName: Deploy Azure Function<br>    environment: ${{ parameters.environment }}<br>    strategy:<br>      runOnce:<br>        deploy:<br>          steps:<br>          - download: none<br>          - task: DownloadBuildArtifacts@0<br>            inputs:<br>              buildType: &#39;current&#39;<br>              downloadType: &#39;single&#39;<br>              artifactName: &#39;FunctionName_$(Build.BuildNumber)&#39;<br>              downloadPath: &#39;$(System.ArtifactsDirectory)&#39;<br>          - task: AzureAppServiceSettings@1<br>            inputs:<br>              azureSubscription: ${{ parameters.azureSubscription }}<br>              appName: ${{ parameters.appName }}<br>              resourceGroupName: ${{ parameters.resourceGroupName }}<br>              appSettings: |<br>                [<br>                  {<br>                    &quot;name&quot;: &quot;WEBSITE_VNET_ROUTE_ALL&quot;, <br>                    &quot;value&quot;: &quot;1&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  },<br>                  {<br>                    &quot;name&quot;: &quot;WEBSITE_RUN_FROM_PACKAGE&quot;, <br>                    &quot;value&quot;: &quot;1&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  },<br>                  {<br>                    &quot;name&quot;: &quot;FUNCTIONS_WORKER_RUNTIME&quot;, <br>                    &quot;value&quot;: &quot;dotnet&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  },<br>                  {<br>                    &quot;name&quot;: &quot;SourceQueueConnection&quot;, <br>                    &quot;value&quot;: &quot;${{ parameters.SourceQueueConnection }}&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  },<br>                  {<br>                    &quot;name&quot;: &quot;SourceQueueName&quot;, <br>                    &quot;value&quot;: &quot;${{ parameters.SourceQueueName }}&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  },<br>                  {<br>                    &quot;name&quot;: &quot;BlobStorageConnectionUri&quot;, <br>                    &quot;value&quot;: &quot;${{ parameters.BlobStorageConnectionUri }}&quot;,<br>                    &quot;slotSetting&quot;: false <br>                  }<br>                ]<br>          - task: AzureFunctionApp@1<br>            displayName: &#39;Azure Function Deployment&#39;<br>            inputs:<br>              azureSubscription: ${{ parameters.azureSubscription }}<br>              appType: functionApp<br>              appName: ${{ parameters.appName }}<br>              package: &#39;$(System.ArtifactsDirectory)/**/*.zip&#39;</pre><p>By default, our app routes only RFC1918 traffic into our VNet. In order to route all of the outbound traffic into our VNet, we’re applying the app setting <em>WEBSITE_VNET_ROUTE_ALL</em>.</p><p>Now to the main pipeline. I’ll skip the build step as it’s quite standard for dotnet application and jump straight to how we use the template we’ve created earlier. All secrets and resource names are not real :)</p><pre>- stage: DeployDEV<br>  displayName: Deploy to Dev environment<br>  dependsOn: Build<br>  condition: succeeded()<br>  jobs:<br>  # Application Insights Instrumentation Key setting<br>  - job: SetAppInsightsKey<br>    displayName: Set Applicaiton Insights Key<br>    steps:<br>    - task: AzureKeyVault@1<br>      inputs:<br>        azureSubscription: ${{ variables.nonProdSubscription }}<br>        KeyVaultName: &#39;kv-function-dev-001&#39;<br>        SecretsFilter: &#39;dev-appinsights-instrumentation-key&#39;<br>        RunAsPreJob: false<br>    - task: AzureAppServiceSettings@1<br>      inputs:<br>        azureSubscription: ${{ variables.nonProdSubscription }}<br>        appName: &#39;function-xxxxxx&#39;<br>        resourceGroupName: &#39;rg-function-dev&#39;<br>        appSettings: |<br>          [<br>            {<br>              &quot;name&quot;: &quot;APPINSIGHTS_INSTRUMENTATIONKEY&quot;, <br>              &quot;value&quot;: &quot;$(dev-appinsights-instrumentation-key)&quot;,<br>              &quot;slotSetting&quot;: false <br>            }<br>          ]<br>  # Function deploy<br>  - template: templates/azure-function-deploy.yml<br>    parameters: <br>      environment: &#39;non-prod-dev&#39;<br>      azureSubscription: ${{ variables.nonProdSubscription }}<br>      resourceGroupName: &#39;rg-function-dev&#39;<br>      appName: &#39;function-xxxxxx&#39;<br>      SourceQueueConnection: &#39;<a href="http://twitter.com/Microsoft">@Microsoft</a>.KeyVault(SecretUri=<a href="https://kv-htbapply-dev-001.vault.azure.net/secrets/htbapply-dev-001-storage-connection-string-1/a3ad6c83a73b44b5a7d471a2122d0fd8)&#39;">https://kv-function-dev-001.vault.azure.net/secrets/dev-storage-connection-string-1/a3ad6c83a73b44b5b8d471a2122d0fd8)&#39;</a><br>      SourceQueueName: &#39;myqueue&#39;<br>      BlobStorageConnectionUri: &#39;<a href="https://stpdhtbapplydev001.blob.core.windows.net/ctr-htbapply-dev-plus-dane-integration-01&#39;">https://storfunctionxxxxxx.blob.core.windows.net/function-results&#39;</a></pre><p>We pass the environment, service connection and all other parameters but I would like to concentrate on those that we consider sensitive and that’s queue connection string and application insights instrumentation key. The former will be presented inside the function as a Key Vault reference and we are passing that as specially formatted string which has that same secret reference. Keep in mind it should also include the version of the secret. We also have a queue name and generic blob connection string. No secrets here but you can definitely make them referencing Key Vault as well.</p><p>It would also be logical to do the same for the app insights key but for some reason it just doesn’t work. The Function doesn’t pick up the connection to Application Insights if we reference it as a secret. It might be a bug which Microsoft will fix at some point but for now we have a separate job reading from the Key Vault and creating the application setting called <em>APPINSIGHTS_INSTRUMENTATIONKEY</em>. We could have included that task into our template but unfortunately ADO doesn’t support nested variables and how the task works it creates a variable available for the next task so it’s not possible to parameterise that.</p><p>A couple of honourable mentions:</p><ul><li><em>scm_type = “VSTSRM”</em> in Terraform code is there to work around Terraform bug where it would overwrite the function resource after we had deployed our code. More on that here: <a href="https://github.com/terraform-providers/terraform-provider-azurerm/issues/8171#issuecomment-707165404">https://github.com/terraform-providers/terraform-provider-azurerm/issues/8171#issuecomment-707165404</a></li><li>Credscan and code analysis added as prerequisite for the build and deploy. We use Microsoft Security Code Analysis ADO extension for that: <a href="https://secdevtools.azurewebsites.net/">https://secdevtools.azurewebsites.net/</a></li><li>Application is visually presented as graph via app insights and you can see there’s a request to get MSI token in order to access Azure resources using managed identity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*oqmIG_dhGiukMwdgMdPw1A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d32ffad7a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Home Assistant + IFTTT + Google assistant + Node Red]]></title>
            <link>https://mihma.medium.com/home-assistant-ifttt-google-assistant-node-red-e5b6d96c18c6?source=rss-ea95edb25531------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5b6d96c18c6</guid>
            <category><![CDATA[ifttt]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[node-red]]></category>
            <category><![CDATA[octopus]]></category>
            <category><![CDATA[home-automation]]></category>
            <dc:creator><![CDATA[Michael Saparov]]></dc:creator>
            <pubDate>Fri, 15 May 2020 10:16:33 GMT</pubDate>
            <atom:updated>2020-05-15T13:46:36.162Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to get cheapest energy intervals using Home Assistant and IFTTT</h3><p>This post sums up my current knowledge of home automation and Home Assistant. Still a lot to learn but I’d like to share this one.</p><p>Story: I switched to Octopus Agile tariff where the electricity prices vary every 30 minutes and wanted to know when to run my appliances, e.g. dishwasher or washing machine to get the most out of it.</p><p>Solution: To get the cheapest time slots I used AppDaemon 4 add-on with octoblock Python app running inside it <a href="https://github.com/badguy99/octoblock">https://github.com/badguy99/octoblock</a></p><p>Make sure you add the timezone to the add-on configuration so you get the correct time out of it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*4KgHSLsjY34wdabcYhQEqQ.png" /></figure><p>After that I added the sensors to the Lovelace UI. Used the custom secondary info card as well <a href="https://github.com/custom-cards/secondaryinfo-entity-row">https://github.com/custom-cards/secondaryinfo-entity-row</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTgtI_uCCQ5zfmUTUveirA.png" /></figure><p>Easy, right?</p><p>Problem: When I want to start a dishwasher I need to open an iPhone app which was just too complicated, I think we all agree on this. I also have a Google Assistant set up. If only I could ask it when to run my dishwasher…</p><p>Solution: Using IFTTT I created an applet where IF is Google Assistant phrase <em>“What is the best time to run a dishwasher”</em> and THEN is a Webhook with JSON formatted content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*l9jAb1MYEXhUi3_SgnrwrQ.png" /></figure><p>I use Nabu Casa cloud to get the webhook url for my Home Assistant instance. $5 per month for out of the box remote UI and easy Google Assistant integration. Also supports the HA developers hence worth every cent.</p><p>What should this webhook trigger? I use Node Red add-on for all my home automations. Using <strong>events: all</strong><em> </em>node I search all incoming events for <em>ifttt_webhook_received</em> event type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*v-PAzUQTvv0jwLoBrWrgcA.png" /></figure><p>Then using the <strong>switch</strong> node I route the flow depending on the message received. In this case it is <em>octopus_4h</em> set up earlier in IFTTT</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*CW3YfDXiK_NOwH8m8mvrWw.png" /></figure><p>Then using <strong>current state</strong> node I get the relevant sensor’s state and pass that on to <strong>function</strong> node where it calculates how many hours left until the cheapest time slot. Substring method is used to remove ‘<em>BST’</em> from the end of the octoblock output which was ‘<em>YYYY-MM-DDTHH:MM:SS BST</em> ‘</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fLKfHx8EmoVWXv2ssy5gAA.png" /></figure><p>Then finished it off with a <strong>call service </strong>node which passed the message to the speaker via the <em>google_translate_say</em> service. The whole flow looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*slIEnj9wHd881vplB_V_dA.png" /></figure><p>Now I can ask the assistant and straight away know how many hours of a delay to put when starting the dishwasher.</p><p><a href="https://youtu.be/nquq0G7MgLM">https://youtu.be/nquq0G7MgLM</a></p><p>I tend to do that before going to bed as the prices at night are at their minimum. So in the morning I take the dish out knowing it was washed at the cheapest time using greener energy.</p><p>This is just another example of how powerful and versatile Home Assistant platform is.</p><p>If you’re considering switching to Octopus you will get £50 if you use my referral link: <a href="https://share.octopus.energy/rainy-jewel-32">https://share.octopus.energy/rainy-jewel-32</a></p><p>I was able to cut my monthly bill from £30 to £15 just by using less energy during the peak time between 16:00 and 19:00.</p><p>Thanks for reading.</p><p>Mike.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5b6d96c18c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>