3 ms·
> I was struggling with that day was to define six cloud storage buckets in Terraform...The kind of thing you’d do with a two-line nested loop in any general-pu
by paulddraper 3y ago
> I was struggling with that day was to define six cloud storage buckets in Terraform...The kind of thing you’d do with a two-line nested loop in any general-purpose language
I understand this is just an example, but FYI the modern solution is to use CDKTF rather than HCL for Terraform.
That allows you to choose your favorite general purpose lang: Python, TypeScript, Go, Java, C#.
- OJFord 3y agoI use Terraform because of HCL, the absolute best thing about it is the declarative config; if someone insists on using their favourite general purpose language: 1) they're wrong; 2) there's plenty of other options for that and I'm not interested in fighting in Terraform's corner knowing they won't use it for the most fundamental reason it's good.
- paulddraper 3y agoSo, your reply to Ruud is "you're holding it wrong" or "it actually fine you just think it isn't"?
- OJFord 3y agoNo, principally because although he writes: > Aside from Nix, Python, and HCL, which I’ve already discussed extensively, He doesn't seem to have much more to say about the latter than that. 'My reply', bluntly, is something like 'maybe it has shortcomings, you haven't addressed them; its most fundamental key advantage is not addressed at all, about it or any other language, and is not a feature of your new one'.
- rirze 3y agoYou do know all that CDKTF does is compile programming language code to JSON (1:1 with Terraform's HCL)? CDKTF is not accessing the Terraform state directly, it's allowing you to express your configuration that you would normally write in Terraform in a programatic way.
- deleted 3y ago[deleted]
- aliasxneo 3y ago> but FYI the modern solution is to use CDKTF rather than HCL for Terraform. That's an odd take. Are you saying that because it's newer? I would push something like Crossplane as more "modern" in that it solves the critical issue of Terraform not having any sort of reconciliation loop.
- paulddraper 3y agoBecause it is a (recent) solution to the problem ("how to easily loop, etc in Terraform"). There are Terraform alternatives...Cloudformation, Pulumi, Crossplane...but that's a separate matter.
- aliasxneo 3y agoGotcha. I guess I see it more as an alternative rather than a modern evolution. I don't particularly like the direction of these SDKs, but I see an increasing demand for them.
- e12e 3y agoHCL has its quirks - bit I'm not entirely sure they are without merit in this case - HCL describes resources - and it's important that when your iteration count goes down, resources are deleted. Some discussion in sections 6, 7 and 8 (linked): https://blog.boltops.com/2020/10/08/terraform-hcl-for-in-and-removing-duplication/ https://blog.boltops.com/2020/10/08/terraform-hcl-for-in-and...
- paulddraper 3y ago> it's important that when your iteration count goes down, resources are deleted Correct, but that has nothing to do with HCL and everything to do with stored state.
- e12e 3y agoWell, ultimately it comes down to "current"(stored) state vs "desired" state, as mentioned in part 6: https://blog.boltops.com/2020/10/06/terraform-hcl-nested-loops/ https://blog.boltops.com/2020/10/06/terraform-hcl-nested-loo... Quote: Consideration: Updates with Removal There’s a subtle but important consideration with the current code. It happens when the code gets updated, particularly when previously added elements are removed. For example, let’s say we first use the code above and run a terraform apply. That creates security groups with rules. Then we delete the rules from the code. Running terraform apply again will not remove the rules. This is because when there’s an empty List, the for_each loop never iterates. If you wish for the security group rules to maintain its current state set outside of Terraform, you may want this behavior. However, this is probably unexpected and undesirable behavior. If you want to have Terraform remove all the security group rules, then ingress needs to be assigned directly with a List. We’ll cover how to do that shortly.
- ljaothasdfs 3y agoYou are likely already aware of this, but for other readers, you actually have to use Pulumi if you want native language feature support. I agree CDK for TF can be better than HCL, but it is still more like a template preprocessing utility for Terraform and thus still carries the limitations of Terraform.