Zoom Logo

TW presents: Getting started with Terraform Pipelines (by Michael Lihs) - Shared screen with speaker view
Stephie (ThoughtWorks)
40:28
Find the whole Code of Conduct from ThoughtWorks here:https://www.thoughtworks.com/code-of-conduct-germany
Katharina (ThoughtWorks)
44:30
Just ping your questions to the chat and we will gather them to make sure we don’t miss anything. :-)
Dominic
51:24
Question: Will you be doomed if state gets somehow lost? Can you recover from a state loss?
Mario Fernandez
51:48
you should store your state in a high durability place, such as S3
Ashish Mohite
51:56
not exactly but close enough
Benji
52:06
Terraform gives the possibility to import ressources.
Mario Fernandez
52:07
you can import existing infrastructure into a state
Ashish Mohite
52:08
terraform import can help
Matthias
52:38
You should backup your state file aswell :-) maybe work with snapshots bevor/after apply
Rajan Bhave
53:09
Does terraform give a graphical representation of the infra getting created like for e.g cloud formation designer provides?
Sean Mitchell
53:13
But there is no import all yet … it is per resource (at least last I checked)
Deyaa
53:15
Question: what happens if resorces were changed outside terraform?
Björn Eberhardt
53:15
Followup question: What if your state loss happens because a state apply failed and you have an intermediate state?
Wolfgang Bauer
53:23
not every resource can be imported
Benji
53:35
You should take care of import. If the provider is implemented badly it won't help you very much
Sascha Diefenthäler
53:36
Do you persist the state then?
Björn Eberhardt
54:23
When a state apply fails because AWS rejects the request?
Chris
54:45
But most of the time they just get destroyed and recreated
Mario Fernandez
55:05
the state needs to be persisted in any case. Because if you don’t two different people applying terraform code would recreate resources
Rajan Bhave
55:06
On which service does terraform run on?
Ashish Mohite
55:33
terraform usually stores backup file while apply
Matthias
55:39
Is there a possibility to snapshot tf-state in a storage-account?
Tat-Thien
55:51
How do changes to resources, which were triggered manually, affect the terraform state?
Engie Tawfik (ThoughtWorks)
55:52
All major cloud providers, you can even order Dominoes Pizza with Terraform @Rajan
Ashish Mohite
55:54
yes
Steffen Gebert
56:03
in CI
Steffen Gebert
56:05
:-)
Sean Mitchell
56:29
Important to mention it doesn’t run all the time … it’s not a service or something … it’s run in a pipeline, makes changes and exits
Tim Fletcher
57:10
Recommendation for state version is to enable it on the remote storage eg S3 supports versioning of files
Tim Fletcher
57:45
These are the supported systems that Terraform can configure: https://www.terraform.io/docs/providers/index.html
Mario Fernandez
57:47
the state in the end is a JSON File. If everything else fails, things can fixed by editing the file and reuploading it, although this is a recipe for pain
Steffen Gebert
57:52
terraform cloud is free for state storage as well
Tim Fletcher
58:00
My team works with AWS, Github and K8S providers
Tim Fletcher
58:46
Indeed there is also Terraform cloud, we can’t use that as our clients have restrictions in place about where sensitive data eg state files can be sotred
Ashish Mohite
59:31
tdd is kinda impossible with terraform
Ashish Mohite
59:45
terratest is ok to use
Ashish Mohite
59:59
but doesn't help much in tdd
Rajan Bhave
01:00:25
Terraform vs. Pulumi…. Which is gaining more traction these days?
Ashish Mohite
01:00:31
terraform
Mario Fernandez
01:00:53
terraform has a bigger offering of providers, pulumi is in very active development as well
Ashish Mohite
01:00:57
pulumi is gaining traction
Michael Fait
01:00:58
So how big was the blast radius on your projects outage?
Michael Fait
01:01:01
:)
Mario Fernandez
01:01:11
if you are starting from scratch I would encourage to check both and see which one fits your use case better
Tim Fletcher
01:01:24
It depends on how you consider TDD, my team have written tests and then written the terraform to deploy working code to make the tests go green - this is out of scope of this talk but we have run talks on infra testing before and will again
Tim Fletcher
01:02:11
My team have focused on Terraform as it’s a common language and tool set to work with Github, K8S and AWS
Ashish Mohite
01:02:19
interesting
Ashish Mohite
01:03:03
any links Tim?
Hannes B
01:05:08
What does “Go for immutable infra” mean exactly? Other than a DB
Tim Fletcher
01:05:09
No links to hand sorry
Engie Tawfik (ThoughtWorks)
01:05:28
@Tim, what does it mean to split state? Is this an outcome of infra modularity?
Taner Durkut
01:06:16
should we split state for each environment?
Steffen Gebert
01:06:25
YES
Mario Fernandez
01:06:28
immutable infra would be deploying infrastructure that is not changed until the next deployment. For instance, all the networking is based on the TF code reflecting the end state.
Hannes B
01:07:13
Thanks @Mario
Yevgen Batovskyi
01:08:05
I have a question, where do you run terraform code, in azure devops, azure container or azure shell, or local laptop?
Michael
01:08:45
Is the concept of pipelines and stages applicable with other tools than Terraforn? E.g. with Ansible?
Mario Fernandez
01:09:12
yes, though the declarative nature of terraform tends to make describing the end state a bit easier
Tim Fletcher
01:09:54
For my team we run all terraform code in pipeline only, we do not run terraform locally at all and have not creds to do so. My team make an active choice to do this.
Anthony Scatchell
01:10:17
Quick question: It looks like your terraform code for many services is all in a single “infra” repo - was there any intentional decision to do this instead of putting the terraform scripts alongside the service code inside each services repository? What drove that decision?
Tim Fletcher
01:10:21
Our CI is GoCD running in K8S containers
Ashish Mohite
01:10:47
tim do you use atlantis?
Sean Mitchell
01:11:10
We’ve just started using Atlantis … it’s nice :D
Tim Fletcher
01:11:14
Not yet, we are considering it in the future
Yevgen Batovskyi
01:11:49
Tim, thanks a lot, do you use HachiCorp Vault for secrets or some parts of GoCD for secrets?
Ashish Mohite
01:12:36
I don't like workspaces
Tim Fletcher
01:13:00
Currently we are using K8S “secrets” we will be moving to AWS secrets store “soon” and then in a while we will be standing up vault
Krystian
01:13:57
What’s the best place to version control infrastructure code, in repo with application code or in separate repo?
Tim Fletcher
01:14:03
My team is building a platform in AWS for a large Thoughtworks client. We are currently getting our MVP up and running for our first team to move to our platform
João Martins (aka Jota)
01:14:09
Plus Locks can only be removed if you have the right permissions.
Johannes Thönes
01:14:19
Did you discuss splitting state even more, e.g. one statefile per service? Why did you decide against it?
Ashish Mohite
01:14:41
monorepo vs mico repos with code?
Yevgen Batovskyi
01:15:12
and last thing, do you use tools like test terratest, kitchen-terraform, validate? or some part of GoCD can help with testing?
Tim Fletcher
01:15:19
I think version control answer is “it depends” and it also depends how tightly linked your code and infra are
Taner Durkut
01:16:43
Is there anyone who experienced with Jenkins for CI pipeline? How good is Jenkins about Terraform CI pipelining?
Tim Fletcher
01:16:44
My team currently tests with tflint and terraform validate, we have additional in pipeline tests to ensure resources are available and configured correctly.
Tim Fletcher
01:17:00
We are also looking at awsspec for testing
Steffen Gebert
01:17:20
works good
Tim Fletcher
01:17:21
I have 0 Jenkins experience I think that @Mario has much more
jeroen
01:17:37
I see a lot of azure specific configuration? I was expecting something more platform independent so you can describe the state independent of where it is applied (Azure, AWS, etc)?
Sean Mitchell
01:17:40
Have you looked at terragrunt at all? It can handle splitting and templating of environments. Well worth a look if it fits your needs
Mario Fernandez
01:17:46
any CI tool can be used to be honest, though I’ve seen many centralized jenkins instances that are exceedingly hard to use
Tigran Arabadjyan
01:17:47
why not to split states down to each independent servece?
Mario Fernandez
01:18:08
+1 to terragrunt, can be used effectively to address some terraform pain points
Tim Fletcher
01:18:36
Terragrunt is something that we are looking at next week to fix some of the pain of copy pasted variables
Sean Mitchell
01:18:44
Why not split to each service: There are tons of interdependencies you can create between services and passing variables back and fourth becomes a PITA
Ashish Mohite
01:20:08
I think terragrunt will be obsolete in some time as tf adds those teatures
Tim Fletcher
01:22:18
My team uses both terraform data calls and terraform remote_state as data sources to pass information between small pieces of terraform code
Ashish Mohite
01:22:47
we use remote state too
Steffi
01:22:52
how "cloud specific" is the resulting terraform code? I'm asking since my team might have to e.g. provision k8s and other services on multiple cloud service providers.
Ashish Mohite
01:23:15
very specific
Ashish Mohite
01:23:33
since resources change by clouds
Tim Fletcher
01:25:59
The k8s terraform will apply to most versions of k8s, but different cloud providers provide different resources as Ashish says
Tim Fletcher
01:26:42
The concepts however are always the same, resources / data objects same templating engine etc
Steffi
01:26:42
thanks
Sean Mitchell
01:27:17
If you want to create a kubernetes cluster, just take a look at the differences between the terraform resource “azurerm_kubenretes_cluster” and “google_container_cluster” … you have to handle ALL those differences yourself
Ashish Mohite
01:30:02
did you. setup pipeline for terraform right away or after your infra reached a certain state
Ashish Mohite
01:30:06
?
Tim Fletcher
01:30:22
My team went straight to pipeline never ran it locally
Dmytro Vlasenko
01:30:24
State described well here. Also the graph tool https://thorsten-hans.com/terraform-state-demystified
Tim Fletcher
01:31:15
But we where starting with a Greenfield setup and we had the opportunity to make a clear choice of pipelines only
Tim Fletcher
01:32:46
We have sometimes needed to do interactive terraform but only a few times in the last 6 months. We do this from the CI/CDs
Tim Fletcher
01:33:01
agents*
Ashish Mohite
01:33:13
gotcha
Tim Fletcher
01:33:55
We actually tag all our infra with the unique pipeline ID as well so we can trace AWS -> pipeline -> code
Andreas Härpfer
01:34:51
Where/how do you publish the various terraform packages? Is it just pushing a docker image to a registry every time?
Tim Fletcher
01:35:50
You can run a terraform registry or just use git but we are not at this stage yet
Johannes Thönes
01:35:57
How do you build the pipeline itself? Also with terraform?
Engie Tawfik (ThoughtWorks)
01:36:28
Can we elaborate more on why “the download terraform package” is needed in every stage?
Tim Fletcher
01:36:39
We actually use yaml to define them in git and then have good sutopull them
Matthias
01:36:39
In Gitlab CI/CD you can use “artifacts” to store the package…
Engie Tawfik (ThoughtWorks)
01:37:06
Thanks @Matthias
Tim Fletcher
01:37:07
There is a GoCD terraform provider but it’s a little trickier to automate for us
Steffen Gebert
01:37:10
What if the "test" stage in prod fails?
Steffen Gebert
01:37:38
We've actually created AWS CodePipelines with Terraform, which then later runs Terraform.. works
Tim Fletcher
01:37:52
That’s an interesting question Steffen, and your team should decide if it’s an alert etc
Ashish Mohite
01:37:54
we build pipelines with terraform using aws codepipeline and codebuild
Anthony Scatchell
01:38:08
When automating terraform plan/apply in a pipeline (no manual approval), do you put any restrictions on? (i.e. don’t automatically apply if there are any destroy’s in the plan)
Steffen Gebert
01:38:21
@TIm that then looks like dev diverges from prod, so you probably can't sooo easily push a change through
Steffen Gebert
01:38:52
kk, thanks
Jonathan Nowak
01:39:14
Currently the Azure DevOps Terraform provider is being developed. So for the moment it is not stable and a lot of resources within Azure DevOps unfortunately can't be terraformed.
Steffen Gebert
01:39:20
Are you running the pipeline from non-master branches? If, what happens there?
Tim Fletcher
01:39:39
We always run from master
Michael Fait
01:39:49
haha … chip is implanted
Yevgen Batovskyi
01:40:03
do you run azure rm templates from teraform/terragrunt?
Stefano Salvatori
01:40:55
How do you know which version or git commit of the terraform scripts was used to build the current prod?
Tim Fletcher
01:41:20
We tag things with the pipeline ID which is made up of the git short hash + pipeline run count
Stefano Salvatori
01:41:21
Like add labels in with the git commit to the resources ?
Stefano Salvatori
01:41:38
Thanks @tim
Tim Fletcher
01:42:08
We also do some AWS tricks to have the pipeline ID embedded in the AWS role assume process that we use
Stefano Salvatori
01:42:35
thx
Matthew Cosgrove
01:43:52
For “proper” unit testing with all dependencies in memory, it’s looking compelling on prem by combining Terraform with the golang vCenter vcsim tool where you can replicate a vCenter set of resources locally. Is anyone aware of such simulation tools for any of the public clouds?
Tim Fletcher
01:44:19
There are some AWS stub tools, I’ve never looked at them
Hannes B
01:46:29
What exactly caused your complete infra outage?
Michael Fait
01:46:53
👏👏👏
Sean Mitchell
01:47:01
How are you guys managing state migrations? For example, I want to rename a module …
Steffen Gebert
01:47:08
great question!
Sean Mitchell
01:47:13
Gah … enter too early :D
Hannes B
01:48:02
Caused, not cost
Sean Mitchell
01:48:06
I want to rename a module … module.x.something to module.y.something … we’ve always had to do this “by hand” before our pipeline runs with terraform state mv … any hints on how to get this in a pipeline in a "migrations”
Ashish Mohite
01:48:07
tf state mv works well
Jonathan Nowak
01:48:13
@Hannes BBasically applying a new resource against a new (wrong) terraform state.
Anja Kammer
01:48:18
Personday, not Manday ;)
Michael Fait
01:48:24
Yeah sure … corrupted state ...
Michael Fait
01:48:28
:)
Hannes B
01:48:38
Thanks
Yevgen Batovskyi
01:48:45
so there is a way to provision resources via powershell modules/integration with UI via Azure resource templates (similar to cloudformation on AWS), when you develope infrastrcuture with teraform you are not always have chnages from Azure in modules
Hannes B
01:49:00
Do you have an opinion on terra grunt?
Engie Tawfik (ThoughtWorks)
01:49:06
@Sean Mitchell, grep and sed possibly? :D
Yevgen Batovskyi
01:49:10
and I was interested how do you integrate azure rm?
Ashish Mohite
01:49:20
I've done a complete nested module renames
Matthew Cosgrove
01:49:36
For “proper” unit testing with all dependencies in memory, it’s looking compelling on prem by combining Terraform with the golang vCenter vcsim tool where you can replicate a vCenter set of resources locally. Is anyone aware of such simulation tools for any of the public clouds?
Sean Mitchell
01:49:42
Grep and sed … no :D terraform state mv works fine, but its always outside of our pipeline. We are adding it to our PRs right now to say “Hey, before we merge this PR into environment, do these state moves”
Steffen Gebert
01:49:57
But how to "terraform state.." when you don't have access to the state / infra, because only your CI has @Ashish
Sean Mitchell
01:50:18
It also happened recently when azurerm renamed some resources from like azurerm_hub_dps to azurerm_iothub_dps … terraform wanted to erase and recreate
Ashish Mohite
01:50:32
i did it manually
Ashish Mohite
01:50:38
not in ci
Steffen Gebert
01:50:57
that then, of course, breaks the concept of only CI has access
Hannes B
01:51:24
🙏
Ashish Mohite
01:51:31
yeah
Tigran Arabadjyan
01:51:32
what about rollbacks with terraform?
Stephie (ThoughtWorks)
01:51:32
Get Michaels slides here: https://github.com/michaellihs/meetup-2020-05-07-terraform-pipelines/blob/master/presentation.pdf
Steffen Gebert
01:51:36
but I don't see a good alternative, except that you have a pipeline which allows to do such renaming
Sascha Diefenthäler
01:51:52
Big appreciation for the talk!
Michael Fait
01:51:52
👍👍👍
Alberto Enriquez de Salamanca
01:51:53
Thanks, very good structured
Christina
01:51:54
thank you very much
Krystian
01:51:57
Thank you
Sean Mitchell
01:51:57
Thanks!!! :)
Mathilda
01:52:00
Thanks
Ashish Mohite
01:52:03
thanks 😊
Dominic
01:52:04
Awesome!
Steffen Gebert
01:52:07
Thanks!
Sebastian
01:52:07
Thanks!
Taner Durkut
01:52:08
Thank you so much :)
Jan Krajewski
01:52:09
many thanks
Felix
01:52:09
Thanks :)
Jan Krajewski
01:52:11
bye
Jette Bakemeier
01:52:11
Thank you!
Laura
01:52:14
thank u :)
Franck Brignoli
01:52:15
Great talk! thanks
Ronny
01:52:16
thanks
Engie Tawfik (ThoughtWorks)
01:52:16
Thanks :)
Thomas Feucht
01:52:18
thank you!
Matthias
01:52:19
thx
Tim Fletcher
01:52:19
I would do the rename via a temp pipeline
Achim
01:52:19
Thank you!
Till
01:52:21
Thanks.
jeroen
01:52:22
Thank you
Yevgen Batovskyi
01:52:22
awesome!! thank a lot TW
Jonathan Nowak
01:52:23
Thanks :-)
Mo El Sherif
01:52:24
Thanks for a great talk
Jenna (ThoughtWorks)
01:52:29
Thanks for joining everyone! :)
Michi
01:52:40
Thank you guys!
Rafael Rezende
01:52:44
Thank you very much!! I really enjoyed the presentation!
Daniel @d_pisanu
01:52:44
cheerio!
Jerko Horvat
01:52:44
Thank you!
Till
01:52:50
Have to go grab some Pizza now :)
Andreas Härpfer
01:52:56
And also thanks to Tim for answering questions in the chat!
Anna Sukiasyan
01:53:01
3 dots -> save chat
Rafael Rezende
01:53:03
Good question, because there are good questions and answers here :-)