<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Google Cloud Platform on shocksolution.com</title><link>https://shocksolution.com/tags/google-cloud-platform/</link><description>Recent content in Google Cloud Platform on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 29 Apr 2022 18:57:01 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/google-cloud-platform/index.xml" rel="self" type="application/rss+xml"/><item><title>Google Cloud Build for Cloud Functions</title><link>https://shocksolution.com/posts/google-cloud-build-for-cloud-functions/</link><pubDate>Fri, 29 Apr 2022 18:57:01 +0000</pubDate><guid>https://shocksolution.com/posts/google-cloud-build-for-cloud-functions/</guid><description>&lt;p&gt;This post aims to add some missing information to Google&amp;rsquo;s docs about setting up CI/CD for Cloud Functions with Cloud Build.&lt;/p&gt;&#10;&lt;h2 id="global-vs-regional"&gt;Global vs Regional&lt;/h2&gt;&#10;&lt;p&gt;Cloud Build triggers are &lt;strong&gt;global&lt;/strong&gt;by default. You can create a regional trigger in the Cloud Console by changing the location when editing or creating a trigger.&lt;strong&gt;NOTE:&lt;/strong&gt; I can&amp;rsquo;t find any way at all to create a regional trigger with Terraform.&lt;/p&gt;&#10;&lt;p&gt;However, functions must be &lt;strong&gt;regional&lt;/strong&gt;. The &lt;a href="https://cloud.google.com/build/docs/deploying-builds/deploy-functions"&gt;Google docs&lt;/a&gt; indicate that you must specify a region in your cloud build config file. If you&amp;rsquo;re using a global trigger, the &lt;code&gt;`$LOCATION`&lt;/code&gt; &lt;a href="https://cloud.google.com/build/docs/configuring-builds/substitute-variable-values"&gt;substitution variable&lt;/a&gt; is set to &lt;code&gt;global&lt;/code&gt;, and you&amp;rsquo;ll get a permission error when trying to deploy to a regional function. There are two options that I know of, and neither is great:&lt;/p&gt;</description></item><item><title>Terraform: for_each on a list of resources</title><link>https://shocksolution.com/posts/terraform-for_each-on-a-list-of-resources/</link><pubDate>Thu, 10 Mar 2022 18:25:02 +0000</pubDate><guid>https://shocksolution.com/posts/terraform-for_each-on-a-list-of-resources/</guid><description>&lt;p&gt;Terraform provides a very simply way to use for_each to iterate over a list of resources. If you have a list of strings, use the toset() function to convert the list to a set of strings.&lt;/p&gt;&#10;&lt;h2 id="example-assign-a-unique-role-on-each-resource"&gt;Example: assign a unique role on each resource&lt;/h2&gt;&#10;&lt;p&gt;My use case is setting up a number of dev environments in Google Cloud Platform. The number may change as the size of the dev team increases, so I don&amp;rsquo;t want to hard-code the number of resources anywhere in my Terraform code. The number of environments is stored in the &lt;code&gt;num_envs&lt;/code&gt; variable. For this example, I want to create a group of resources (Google Cloud Storage buckets). Each environment has its own service account, and I want each environment&amp;rsquo;s service account to have a specific role on that environment&amp;rsquo;s bucket. I also want to leverage official Google-supported Terraform modules whenever possible.&lt;/p&gt;</description></item><item><title>Auto-Create Multiple Blocks in a Terraform Resource</title><link>https://shocksolution.com/posts/auto-create-multiple-blocks-in-a-terraform-resource/</link><pubDate>Fri, 12 Nov 2021 16:35:50 +0000</pubDate><guid>https://shocksolution.com/posts/auto-create-multiple-blocks-in-a-terraform-resource/</guid><description>&lt;p&gt;Learn how to automatically create multiple Terraform resources, and multiple blocks within one Terraform resource, using the for_each meta-argument and dynamic blocks.&lt;/p&gt;&#10;&lt;h2 id="creating-multiple-resources"&gt;Creating Multiple Resources&lt;/h2&gt;&#10;&lt;p&gt;When using Terraform in a realistic environment (e.g. not a lab or tutorial), you often need to create automatically create multiple resources based on a list or map of data. This article reviews the options for creating resources based on data.There are two general methods to choose from when creating multiple resources:&lt;/p&gt;</description></item><item><title>Define a Google Load Balancer and Cloud Storage bucket with Terraform</title><link>https://shocksolution.com/posts/define-a-google-load-balancer-and-cloud-storage-bucket-with-terraform/</link><pubDate>Thu, 30 Sep 2021 18:11:54 +0000</pubDate><guid>https://shocksolution.com/posts/define-a-google-load-balancer-and-cloud-storage-bucket-with-terraform/</guid><description>&lt;p&gt;Here&amp;rsquo;s an example of using Terraform to define resources to host static content in a Google Cloud Storage bucket, fronted by a Cloud Load Balancer with a custom URL and SSL certificate. This example uses some other advanced features, such as Google Secrets and a map variable to define the SSL certificates. It&amp;rsquo;s pulled from a larger project, so this block of code isn&amp;rsquo;t guaranteed to run as-is. At a minimum, you&amp;rsquo;ll need to define the variables and set values.&lt;/p&gt;</description></item><item><title>Node.js: Connecting to MySQL on a socket with Sequelize</title><link>https://shocksolution.com/posts/node-js-connecting-to-mysql-on-a-socket-with-sequelize/</link><pubDate>Thu, 22 Apr 2021 18:54:25 +0000</pubDate><guid>https://shocksolution.com/posts/node-js-connecting-to-mysql-on-a-socket-with-sequelize/</guid><description>&lt;p&gt;According to its official description, &amp;ldquo;&lt;a href="https://sequelize.org/master/index.html"&gt;Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server.&lt;/a&gt;&amp;rdquo; Sequelize is widely used in Node.js web applications to abstract the database layer. I recently found a &amp;ldquo;corner case&amp;rdquo; for Sequelize which is possible to accomplish, but is not well documented anywhere on the web. I need to use Sequelize to connect to a MySQL server via a UNIX socket. I&amp;rsquo;m developing some plugins for Confluence that use the &lt;a href="https://bitbucket.org/atlassian/atlassian-connect-express/src/master/"&gt;atlassian-connect-express&lt;/a&gt; toolkit, which has a datastore that wraps Sequelize. The way Atlassian has chosen to wrap Sequelize is rather unfortunate, probably because they are trying to maintain backwards compatibility with JugglingDB. Essentially, the Atlassian Connect Express only looks at the URL, and ignores any option passed to Sequelize. Therefore, you have to pass everything you need via the URL, and this is where it&amp;rsquo;s tricky. Here&amp;rsquo;s the form of the URL that you need to connect to MySQL via a UNIX socket with Sequelize:&lt;/p&gt;</description></item><item><title>Alert Policies for Log Metrics on Google Stackdriver Monitoring</title><link>https://shocksolution.com/posts/alert-policies-for-log-metrics-on-google-stackdriver-monitoring/</link><pubDate>Tue, 08 Sep 2020 16:31:08 +0000</pubDate><guid>https://shocksolution.com/posts/alert-policies-for-log-metrics-on-google-stackdriver-monitoring/</guid><description>&lt;p&gt;Google Cloud Operations, formerly known as Stackdriver Logging and Monitoring, can be very confusing to set up. It&amp;rsquo;s easy to monitor something simple, but more complex cases quickly get confusing. One of the more flexible but confusing types of alert policies in Stackdriver Monitoring is a Logs-Based Metrics policy, which gives you the ability to monitor entries in Stackdriver Logging.&lt;/p&gt;&#10;&lt;h2 id="create-a-logs-based-metric"&gt;Create a Logs-Based Metric&lt;/h2&gt;&#10;&lt;p&gt;The first step is to go to Stackdriver (Operations) Logging and create a user-defined metric. Go to the Logs Viewer and build a query to return the subset of log entries that you want to monitor (the details of query building are beyond the scope of this article). As of Sept. 2020, I highly recommend enabling the Preview Mode of the Logs Viewer interface, which is much better at guiding you through the process of building the query. If you must use the Classic interface, click the little black arrow at the right side of the filter box, near the top of the Logs Viewer screen. Select &amp;ldquo;Convert to advanced filter&amp;rdquo; from the drop-down menu, and &lt;a href="https://cloud.google.com/logging/docs/view/advanced-queries"&gt;create an advanced filter using the query language&lt;/a&gt;. Once you have created the right filter (query) that selects the log entries that you want to monitor, proceed to the next step:&lt;/p&gt;</description></item><item><title>Testing Access to Google Bigtable</title><link>https://shocksolution.com/posts/testing-access-to-google-bigtable/</link><pubDate>Fri, 05 Jun 2020 20:14:15 +0000</pubDate><guid>https://shocksolution.com/posts/testing-access-to-google-bigtable/</guid><description>&lt;p&gt;This is a minimal PHP script that&amp;rsquo;s useful for verifying connectivity and permissions to read data from a Google Bigtable instance. Unlike some of the sparse examples in Google&amp;rsquo;s PHP SDK, this script will work for any table, and you don&amp;rsquo;t need to know anything about the structure of the table. This script tests the critical elements that need to work together to enable Bigtable access:&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;Credential file&lt;/em&gt; GRPC extension for PHP&#10;&lt;em&gt;Protobuf extension for PHP&lt;/em&gt; Scopes enabled on Compute Engine instances&lt;/p&gt;</description></item><item><title>Another Reason to Enable Private IP Addresses on Google Cloud SQL</title><link>https://shocksolution.com/posts/another-reason-to-enable-private-ip-addresses-on-google-cloud-sql/</link><pubDate>Wed, 26 Jun 2019 18:16:22 +0000</pubDate><guid>https://shocksolution.com/posts/another-reason-to-enable-private-ip-addresses-on-google-cloud-sql/</guid><description>&lt;p&gt;Google Cloud SQL recently introduced the capability for an instance to have an IP address within the private address space of your VPC network. Previously, all Cloud SQL instances had IP addresses within the address space of the public Internet. Obviously, the public IP was a security and privacy concern, as well as a potential violation of some compliance and governance frameworks. Now, each instance may have a public IP, private IP, or both. There&amp;rsquo;s another potential benefit to using a private IP address: performance!&lt;/p&gt;</description></item><item><title>QNAP NAS: Backup &amp; Sync to Google Cloud Storage</title><link>https://shocksolution.com/posts/qnap-nas-backup-sync-to-google-cloud-storage/</link><pubDate>Sat, 01 Jun 2019 21:17:40 +0000</pubDate><guid>https://shocksolution.com/posts/qnap-nas-backup-sync-to-google-cloud-storage/</guid><description>&lt;p&gt;I have a QNAP NAS at home which I use for file storage. It shares several folders with the family&amp;rsquo;s Mac, Linux, and Windows computers. Many of these files are are irreplaceable, especially our digital photos, so I back them up to the cloud. &lt;a href="https://%3C%3Cwww.qnap.com/solution/hbs3/en/&amp;amp;gt%3E;"&gt;QNAP provides the Hybrid Backup and Sync application&lt;/a&gt;, which supports multiple cloud storage endpoints. QNAP also provides specific documentation for &lt;a href="https://%3C%3Cwww.qnap.com/en/how-to/tutorial/article/how-to-connect-to-google-cloud-storage-with-cloud-backup-sync/&amp;amp;gt%3E;"&gt;backing up and syncing to Google Cloud Storage&lt;/a&gt;. However, QNAP&amp;rsquo;s instructions don&amp;rsquo;t explain how to set up a Google Cloud Storage bucket destination, so here is the procedure I used to set up Google Cloud Storage to back up my QNAP NAS.&lt;/p&gt;</description></item><item><title>Disk space utilization monitoring in Google StackDriver</title><link>https://shocksolution.com/posts/disk-space-utilization-monitoring-in-google-stackdriver/</link><pubDate>Tue, 28 May 2019 18:22:43 +0000</pubDate><guid>https://shocksolution.com/posts/disk-space-utilization-monitoring-in-google-stackdriver/</guid><description>&lt;p&gt;Setting up disk space utilization alerts in Google Stackdriver is almost unbelievably tricky. It&amp;rsquo;s easy to think that you can just choose the metric &amp;ldquo;Disk Utilization&amp;rdquo; and add a condition to alert when disk utilization crosses some threshold for some length of time (such as over 55% for 1 hour).&lt;/p&gt;&#10;&lt;h2 id="file-system-type-filter"&gt;File System Type Filter&lt;/h2&gt;&#10;&lt;p&gt;Your first problem is that a Linux system has many types of file systems, even if it only has one disk. You probably want to alert when your root disk is running out of space; therefore, you need to filter out non-disk filesystems like &lt;a href="https://en.wikipedia.org/wiki/Procfs"&gt;procfs&lt;/a&gt; or tmpfs. Add a device filter to select exactly which devices you want to alert on; in my case, with only one disk per server, I match only on device rootfs.&lt;/p&gt;</description></item><item><title>Creating Kubernetes Secrets Using TLS/SSL as an Example</title><link>https://shocksolution.com/posts/creating-kubernetes-secrets-using-tls-ssl-as-an-example/</link><pubDate>Fri, 14 Dec 2018 16:15:11 +0000</pubDate><guid>https://shocksolution.com/posts/creating-kubernetes-secrets-using-tls-ssl-as-an-example/</guid><description>&lt;p&gt;Creating Kubernetes secrets isn&amp;rsquo;t intuitive the first time you do it. A common reason to use a secret is to add a SSL/TLS certificate to a cluster. Kubernetes provides two ways to add a secret: directly on the command line, and from a YAML source file. First, let&amp;rsquo;s generate a test certificate to work with and select our cluster.&lt;/p&gt;&#10;&lt;h2 id="prerequisites"&gt;Prerequisites&lt;/h2&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj &amp;#34;/CN=foo.bar.com&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;This command produces two files: tls.key and tls.cert. In production, you&amp;rsquo;d generate a key file and use it to obtain a certificate from a certificate authority.&lt;/p&gt;</description></item><item><title>Viewing logs for a cluster of instances on Google Stackdriver Logging</title><link>https://shocksolution.com/posts/viewing-logs-for-a-cluster-of-instances-on-google-stackdriver-logging/</link><pubDate>Tue, 27 Mar 2018 14:01:51 +0000</pubDate><guid>https://shocksolution.com/posts/viewing-logs-for-a-cluster-of-instances-on-google-stackdriver-logging/</guid><description>&lt;p&gt;StackDriver Logging is a great feature of Google Compute Engine (GCE). You pretty much need a centralized logging solution if you are taking maximum advantage of the features offered by GCE. For example, most production applications will run on a cluster of web servers. If you set up the cluster as a managed instance group on GCE, Google can auto-scale the size of the cluster based on traffic. The challenge is that it&amp;rsquo;s much  harder to troubleshoot errors across a cluster. The requests that caused the error could be spread across any number of servers, with randomly assigned names. If load drops and the server pool contracts, you will entirely lose any log data on a server that&amp;rsquo;s auto-deleted. StackDriver Logging is the answer to this problem. Configure all servers to send all logs to StackDriver, and you can view all of your web server logs in one interface, with the entries in chronological order. &lt;a href="https://gist.github.com/craigafinch/a2025a867eae1dfc236c6162072024a5"&gt;View StackDriver Advanced Filter as a Gist on GitHub&lt;/a&gt; The problem is that the Stackdriver docs only explain how to select an instance by the instance ID, which is a random-looking string that is not visible in the Console. Further, if you have a large cluster of disposable servers, you would have to look up the ID for every instance. If an instance was deleted when the cluster was auto-scaled, you won&amp;rsquo;t even know what to look up. Therefore, it&amp;rsquo;s much better to search for the logs based on a human-readable server name. For example, assume that your servers are Google Compute Engine instances that are named [region]-[zone]-web-[id]. Here&amp;rsquo;s a filter to match on that naming convention: [sourcecode language=&amp;ldquo;plain&amp;rdquo;] resource.type=&amp;ldquo;gce_instance&amp;rdquo; logName=&amp;ldquo;projects/my-project-name/logs/apache-error&amp;rdquo; labels.&amp;ldquo;compute.googleapis.com/resource_name&amp;rdquo;:&amp;quot;-web-&amp;quot; textPayload:&amp;ldquo;execution time&amp;rdquo; [/sourcecode]&lt;/p&gt;</description></item></channel></rss>