thedevopscat blog

Thoughts, observations and learnings of the devopscat...

Terraform Conditional Expressions

2022-12-23 3 min read Terraform

As you are no doubt aware, Terraform is a declarative laungage, it reads like a shopping list rather than code with a bunch of conditional statements. I like to think of it as matter of fact, there simply isn’t if, elseif (etc) type statements at play here and this is a (generally) a good thing. “Do or do not…” as somebody wise once said… (I know my audience!).

Continue reading

Securing Access from a Public IP

2022-12-22 4 min read Terraform

In this blog post I’ll share some tips on how you can securely use your cloud resources from a public IP, such as your home connection. I’ll be using Azure but the principles will apply to other vendor clouds.

The specific use case we’ll consider is MSDN subscription access, hence the desire to avoid the cost of running a dedicated Azure Firewall, whilst not leaving ourselves vulnerable.

Continue reading

Terraform Count Index

2022-12-22 2 min read Terraform

As a quick summary, a count index can be used (but probably shouldn’t, for_each is more flexible) to create multiple resource instances of the same type from one block of code, for example lets say you want a spin up multiple vm’s behind a load balancer for some fault tolerance.

The benefit here is you would have one block of code which would be automatically processed multiple times, as specified by your count variable/local, (it can also be set 1 or even zero, but more on this another time…).

Continue reading

Elements Terraform Function

2022-12-22 3 min read Terraform

Lets start by taking a brief look at the element function, then explore why this simple function is so useful.

We won’t labour the point here as that’s what the hashicorp help page is for, although sometimes the examples could be better.

The element function looks like this:

element(list, index)

You’ll note it uses an index … like our count index in the previous post so we will expand upon the previous example to demonstrate a real would use case.

Continue reading