Code coverage for PowerShell module development
Robstr
by
2y ago
Code coverage can be a controversial topic, if you let it, but I feel that it is one of the many tools one can use to make sure that you’re on the right track. For those not aware, code coverage (or test coverage) is a measurement of how much of your source code you’re testing. The though being that the more of your code you are testing, the better. I agree, and I try to write tests for every single function that I write in a module. In this particular blog, we’re going to explore how to create code coverage metrics and automatically send the results to the service codecov.io, which in turn wi ..read more
Visit website
Publish to PowerShellGallery with GitHub Actions
Robstr
by
2y ago
My next step in automating my PowerShell module development workflow is to have my module deploy to PowerShellGallery when creating a GitHub release. Last time it was doing unit testing with pester, now we want our code to get out in the world. What I want to accomplish is pretty simple, to make my release process simple. By using GitHub Actions, we can trigger tasks by creating a new release. When creating a release, we checkout our code and run Publish-Module like we would locally on our machine. We need an API Key, which you can find when you log into PowerShellGallery, and that’s about it ..read more
Visit website
Using GitHub actions to run automatic Pester tests
Robstr
by
2y ago
I used a long time before looking into Pester to test my code. Or, worded differently, for the longest time I was not testing my code. But as soon as I started creating PowerShell modules that was more than just small time projects, I had to step up the production quality. As soon as I had written some tests, I wanted to have those tests run every time I did a pull request. This helps me catch bugs before publishing the new version of my module, and saves me from a ton of stress. This is not an explanation on how Pester works. If you want to learn how to write tests for PowerShell you can eit ..read more
Visit website
Custom variable validation, a practical example
Robstr
by
2y ago
Custom variable validation is my new go-to killer feature. Introduced as a language experiment in late 0.12, from Terraform 0.13 it is now production-ready! This enables us to write a definition of what we want our input variables to, and give send out a proper warning. At first, you might ask why bother? If the user inputs something that can’t be deployed, wouldn’t Terraform fail? Sure, but for a failure to happen we actually have to run the code, use the provider to get the error back. This takes time, or even worse it might actually try to deploy and time out, which takes even more time. Cr ..read more
Visit website
List all VNet and Subnets across multiple subscriptions
Robstr
by
2y ago
It has happened to everyone, the network sprawl. You might have on-premises networks and virtual networks, maybe even in multiple clouds, and at one point you simply have lost count of your ranges and what they are used for. Usually, these ranges come from someone that is responsible for IP-ranges (preferably an IPAM solution) but what if you have a lot of teams creating VNet in a bunch of subscriptions? Well, it can get out of hand quickly. The script If you are interested in learning how this script works, we’ll continue the blog post after the code. For those who just want to run the script ..read more
Visit website
Extract Zip files with PowerShell
Robstr
by
2y ago
For my module tftools I needed to download Terraform from Hashicorp, which came in a Zip archive. I didn’t want to rely on other tools or modules to extract the Zip files, and luckily there was a .Net class called ZipFile from the System.IO.Compression.FileSystem assembly that could be utilized. Here’s how we can download a Zip file as a temporary file and extract the content. # Define a temporary file, # the URI for the file you want to download, # and the folder you want to extract to $tempFile = [System.IO.Path]::GetTempFileName() $URI = "https://example.org/file.zip" $OutputFolder = "C ..read more
Visit website
Version 0.3.5 release of tftools, now available for MacOS
Robstr
by
2y ago
Cross platform functionality achieved! As someone who uses PowerShell on 2 of the 3 major operation systems, Linux and Windows, having my modules work on all systems is very important to me. Doing this is usually though, but when working with Terraform which is cross platform made it relatively easy. By utilizing a helper function to determine the OS and setting that platforms specific settings, and by using Azure DevOps pipelines to run Pester tests on the code, we now have a toolset that works on Linux, Windows and Mac. You can install 0.3.5 from the PowerShell Gallery by running # Install ..read more
Visit website
Create more flexible modules with Terraform 0.13 and for_each loops
Robstr
by
2y ago
Terraform 0.13 introduces a myriad of new features that drastically improves many Infrastructure-as-Code(rs) lives. It is finally possible to use the count, depends_on, and for_each features in modules. We also get custom validation rules for variables, which is really helpful when working with resources that has limitations like length. Version 0.13 really takes what you can do with Terraform to whole new levels. An example would be writing a module for setting up cluster with Azure Kubernetes Service. In AKS, you have one default node pool with the possibility to add additional pools. Tradit ..read more
Visit website
Tftools - PowerShell module for Terraform version handling
Robstr
by
2y ago
One of the great things with PowerShell is that it’s pretty easy to create your own tools. Due to the nature of Terraform, there are times where you need a specific version of Terraform. For instance, a client that I work at these days have some old code written in 0.11 while also creating new code that uses 0.12 syntax. This can easily happen if you have a big code base, as it’s almost impossible at times to update the entire thing. While there are other solutions for version handling, these were either platform specific or did not have all the functionality that I wanted. So, I wanted to mak ..read more
Visit website
PowerShell and how to work with network settings
Robstr
by
2y ago
This one seems confusing for most, as it might be the area where most Windows sysadmins rely on the GUI. If you ask (almost) any sysadmin how to change the IP on a server, they are going to answers how to get to the network adapters in the settings. Things like this seem to be to be one of the reasons why people are afraid of adapting Server Core. Figuring that it’s time to inform the people and make sure that anyone can handle networking, even if they can only access the shell. Let’s summarize how to do most network related tasks in PowerShell. Any requests? Enable and Disable NIC # List all ..read more
Visit website

Follow Robstr on Feedspot

Continue with Google
OR