Opsgenie Terraform control
I want to automate all the things. Pretty much anything I do can usually be done quicker and better by a machine and usually one controlled from some simple code.
In this case I have been setting up Opsgenie for the first time here. We selected Opsgenie because we needed an on-call management and alerting tool that was external to our infrastructure and while the usual kid on the block I would look to first is Pagerduty this specific client happens to already be all in with the Atlassian toolset so Opsgenie made more sense and it also happens to be cheaper for the features we want which is no small thing.
Thankfully there is a Terraform provider for Opsgenie which is well documented and does everything it appears we are going to need to do. We had an initial play with with the tool to see what we might want to do with it and see how it works so we already had a few users in there with some teams defined but thankfully the Terraform resources in this case support import. With Terraform since it manages a view of the state of which ever service it is managing if you already have created resources with another tool you can use terraform import to bring the current state of those resources into the Terraform state file. After this initial import the resources can be managed by code.
This process mostly went smoothly other than for my own user. For all the other users the ID as mentioned in the terraform opsgenie user resource appears in the web interface but for my own user it did not. Given I needed my ID to import my user I had to find someway to get this. Thankfully the Opsgenie API that Terraform is using to speak with Opsgenie supports querying a user and I was able to get my ID and import myself into the state file, I now existed in code.
At the end of this I am not sure how much of this service we really want to manage in code. The users are a clear advantage as git will provide an audit trail for adding or modifying users and the same is true of teams but it may be that the schedules will be better managed in the web interface as will the contact details for users for user self management. While automation and Infrastructure as Code is a great thing it is important to know when to apply and when sometimes it does not make sense.
Peace, love and happiness.