25
u/locutus233 Apr 29 '20
I feel like this alot. Usually because it initially seams all cool and should work, then there is some edge case you miss or dont full understand and it blows up in your face. Autoscaling and elasticsearch cognito authentication I'm looking at you.
9
6
u/Rad_Spencer Apr 29 '20
My current feeling of this comes from trying to stand up and tear down eks clusters. Terraform builds the eks cluster, the eks cluster creates ebs volumes and loadbalancers that are not part of the state file, making tear down and cleanup a pain.
5
u/some_kind_of_rob Apr 29 '20
I’ve had nothing but pain working with EKS. ECS isn’t terribly straightforward, especially with Fargate, but it works well with Terraform.
And you get the added benefit of not having to use Kube...
4
6
3
u/xandrellas Apr 29 '20
Absolutely.
I'm transitioning ours from tf11 to tf12, instituting Terragrunt AND modularizing as much as I can.
Hitting rough levels of burnout.
1
u/Dynamic-D Apr 30 '20
I personally found your can abandon terragrunt one you upgrade to 0.12. it's not quite on par, but close enough I find removing a layer to be worth it.
1
u/xandrellas Apr 30 '20
Hey thanks for the info! So far, after intensely frustrating learning of TF/12/TG, I'm feeling fairly comfortable translating all over but the amount of iteration to separate into namespaces/modules is very burnout-inducing.
If it makes sense after I've completed this project (5 aws regions, numerous accounts) to decouple it from TG, I'm game.
2
2
u/Dynamic-D Apr 29 '20
Sometimes you gotta remind yourself: Terraform is not a CM tool. It's a deployment tool. It's cloud-config on steroids. It subverts so many expectations when you remember what this tool is for.
Yeah it blurs the line when PaaS let's you declare settings so easily. But it has no interest in going under the surface.
1
u/P3zcore Apr 30 '20
This is me anytime something should work but just doesn't. Looking at you Key Vault secret creation...
1
u/Luna_moonlit Apr 25 '23
I’ve only done super basic stuff in terraform (creating VMs + DNS records) and it always worked until I did DNS. With powerDNS running with an SQLite backend you have to do parallelism=1 otherwise it doesn’t work 🤣🤣🤣
0
Apr 29 '20
[deleted]
5
u/Bennetjs Apr 29 '20
Getting an updated ECS Task definition that way, thought it'd be easier than that...
5
u/ac_slinky Apr 29 '20
Hmm, explain your use case if you don’t mind. We are doing full blue green ECS deployments with Terraform for about 2.5 years now. Not doing them with local-exec null resources. Maybe our method could help?
2
u/michelmzs Apr 29 '20
Are you using terraform to update task definitions too? I was wondering about it, but seems strange to me using terraform for image deployment.
3
u/ac_slinky Apr 29 '20
So basically, our method would work with any automated CI/CD pipeline. We effectively do things in the following order:
New code is merged to master
Pipeline (gitlab in our case) is triggered to run a build stage (tests first I promise!)
The build stage is basically just a docker build, but with one important step, it takes the short SHA of that latest git commit and appends it to the end of the image tag before pushing it to ECR
This is only half the battle, because now you need that full image URL with the latest SHA to be set to your new task definitions image URL. As long as that's a variable that you've temporarily set locally in the pipeline process, you can run a terraform apply -var docker_image_url=<image_url> (can't think of the exact command off the top of my head) and set that image url as the variable for the taskdef image url.
This is where the AWS magic happens with your Terraform deploy. If you've terraformed the ECS service and it's linked to that task definition, when you run a plan/apply for Terraform, that new image URL equals a new task definition. Why is this magic? Well, because now ECS sees a new task definition revision tied to the service and immediately begins a blue/green rollout of the existing.
(New tasks roll in, pending, come healthy, old tasks roll out).
We also add a touch where we then run a wait command on the ecs service in the pipeline to ensure the latest tasks come up healthy before clarifying the pipeline job as a success.
Let me know if you aren't tracking that and perhaps I can explain a different way :)
1
u/michelmzs Apr 29 '20
I Got it, your terraform /deploy stage contains the service and task definitions resources, correct? Our current implementation is different, tf provides ecs service creation and the ecs-cli does the task definition update. But the deploy stage depends on tf steps did for someone one time at first.
1
Apr 29 '20
I used to deploy by generating new task definitions. Luckily there were not that many. It was a pretty neat solution.
However, I had to write a python script as local-exec/null_resource for tracking deploy progress on ECS. IMO, resources should have an option to wait for the health check to pass.
4
u/tbell83 Apr 29 '20
We are inheriting some existing infrastructure and there are
null_resources andlocal-execblocks everywhere and I am losing my damn mind.1
u/DrudgeBreitbart Apr 29 '20
I wouldn’t do it if terraform would actually work properly
0
Apr 29 '20
[deleted]
1
u/DrudgeBreitbart Apr 29 '20
Eh there’s just a lot of weird edge cases with Terraform. I’ve run into quite a few of them. Terraform is especially limited if you desire to create dynamic infrastructure. It doesn’t work as well as a normal language does in terms of logic.
0
0
u/Dynamic-D Apr 29 '20 edited Apr 29 '20
I have a few of those in use because the existing Terraform modules are so terribly inflexible it was easier to go ahead and create a config.yml from a template and local exec than it was to use the resources...
That's a sign of trouble...
0
Apr 29 '20
[deleted]
1
u/Dynamic-D Apr 29 '20
To give more clarity, there's an RKE module for using rke to deploy k8s. The way it's structured you can't use a simple count to change the node count. So it's easier to build the yaml from a template then manually kick off rke with local_exec.
0
Apr 29 '20
[deleted]
2
u/Dynamic-D Apr 29 '20
It's the resource itself, as each node had to be specifically declared in the config resource. Because you can only "count" an entire resource, they need a new resource just for defining nodes that can be linked.
Otherwise, template_file to the rescue! I can create a config yaml easily enough.
6
u/alwaysResponsible Apr 29 '20
Meme was for animal crossing but it still works over here.