News for hackers. Stuff that matters.
Re:Terraform 0.15 General Availability by solatic on Wednesday April 14, 2021 @04:28PM (#26812615)
Because the state exists regardless. When you write code that interfaces with AWS, there's always something that exists on the other side of the AWS API. The question you have is, how do you programmatically keep a copy of that state on your side of the API?

The naive approach that tries to do this without state in code goes something like:

a) invoke the remote API to look for something that should exist b) if it doesn't exist, invoke the remote API to create it c) use the property of the thing to do something else

What Terraform does is cleanly separate your state (don't look stuff up you already know exists) from the API (which is handled by an open-source library, aka the provider) from your configuration (which can now be declarative). Because the state and API calls are abstracted away, the configuration itself is much more clean, easy to reason about, and easier to maintain.

Re:Terraform 0.15 General Availability by mr_C on Wednesday April 14, 2021 @04:48PM (#26812857)
Maybe an unpopular opinion but what you just described as "naive" is arguably a better solution than Terraform's overengineering.

I use Ansible to manage multiple clouds (Openstack, AWS...etc) using a mix of custom modules and public collections. I don't need a "state", I couldn't care less if resources exist or not, upgrades between versions are smooth, module/collection upgrades doesn't interfere with all the existing resources we already have... every time I run a playbook I know that everything will end up just like I want it to be. Not bad for a naive approach I guess.

Re:Terraform 0.15 General Availability by diroussel on Wednesday April 14, 2021 @05:07PM (#26813095)
If you have an ansible playbook that creates a certain resource, and you delete that code. Next time you run it, it won’t delete the resource because there is no state management.

You have to add code to as only to be sure to remove the non-longer needed resource. But how long does that code need to stay there.

Ansible is supposed to engender a decorative approach, but it’s very easy to slip into procedural code. Whereas terraform is much more declarative.

Re:Terraform 0.15 General Availability by mr_C on Wednesday April 14, 2021 @05:23PM (#26813293)
Who cares if there is a dangling dns records somewhere or an extra allocated floating ip? In practice you could just set state:absent to whatever you are trying to remove or just remove it manually, the latter is most of the time faster than dealing with state management once you have a behemoth in prod that no one wants to break.
Re:Terraform 0.15 General Availability by ncallaway on Wednesday April 14, 2021 @08:01PM (#26814660)
> Who cares if there is a dangling dns records somewhere or an extra allocated floating ip

What if instead of a dangling dns record, its 15 large EC2 instances?

Yes, you can come up with examples of trivial dangling resources, but it's just as easy for me to come up with non-trivial examples of dangling resources.

Re:Terraform 0.15 General Availability by mr_C on Thursday April 15, 2021 @04:37AM (#26817720)
I came up with trivial examples because no one forgets about non-trivial resources. In my opinion, if you decrease some instance count from 18 to 3, you'd rather waste 1 minute deleting 15 instances than dealing with all the problems a state management brings to the table.
Re:Terraform 0.15 General Availability by ncallaway on Thursday April 15, 2021 @01:53PM (#26823880)
> no one forgets about non-trivial resources

The number of articles I've read about someone who left a non-trivial number of resources running unused in AWS and were later surprised by a large bill would seem to be a counterexample to that point.

Re:Terraform 0.15 General Availability by sciurus on Wednesday April 14, 2021 @08:40PM (#26814912)
> Who cares if there is a dangling dns records somewhere

You should care. This opens you up to subdomain takeovers, which have real security implications.

https://developer.mozilla.org/en-US/docs/Web/Security/Subdom...

Re:Terraform 0.15 General Availability by erik_seaberg on Wednesday April 14, 2021 @06:32PM (#26813917)
Some cloud resources will cost money every month, forever. (I think this is an unappreciated side of the AWS business model; it’s not cost-effective to have a dev confirm that each resource can be safely decomm’d.)

There’s also a risk that your legacy environments only work because some dangling resource wasn’t cleaned up, and a new clone of the environment will fail.

Re:Terraform 0.15 General Availability by ezrast on Thursday April 15, 2021 @01:29AM (#26816471)
> In practice you could just set state:absent to whatever you are trying to remove

If you do this, or in fact anything with Ansible, be REAL careful about double-checking what your tags actually match before committing. Since it doesn't track state, anything in your cloud environment is fair game.

I was not careful once, and that was a bad week for me.

Re:Terraform 0.15 General Availability by solatic on Thursday April 15, 2021 @12:54AM (#26816317)
Part of the benefit of Terraform is the ability to set up ephemeral resources and tear everything down afterwards with "terraform destroy", which is useful for setting up one-off experiments and tests. That kind of cleanup is completely impossible with Ansible.
Re:Terraform 0.15 General Availability by mr_C on Thursday April 15, 2021 @04:41AM (#26817772)
Not true, just set state to absent and run your play again.
Re:Terraform 0.15 General Availability by m1keil on Wednesday April 14, 2021 @09:07PM (#26815077)
You pay for some of these (like dangling IP addresses not in use) and some others have a max quota (like security groups).
Re:Terraform 0.15 General Availability by matwood on Wednesday April 14, 2021 @09:44PM (#26815310)
Any dangling resources may cost money and/or open up security concerns.
Re:Terraform 0.15 General Availability by llbeansandrice on Wednesday April 14, 2021 @04:59PM (#26813006)
I haven't used Ansible so maybe I'm incorrect here but aren't tf and Ansible solving slightly different problems?

Terraform feels like infrastructure management to me. We use it to provision underlying resources: Networking, Clusters, Nodes, Alerts, etc. All of the actual code deployments are entirely separate.

Ansible is more of a configuration management right?

Re:Terraform 0.15 General Availability by timdev2 on Wednesday April 14, 2021 @07:40PM (#26814490)
Right. And you can use something like terraform-inventory[0] as a dynamic inventory source in Ansible. So TF manages all the bits and bobs floating around in AWS, and then ansible takes over to manage configuration on whatever EC2 instances are involved.

[0]: https://github.com/adammck/terraform-inventory

Re:Terraform 0.15 General Availability by throwdbaaway on Wednesday April 14, 2021 @08:02PM (#26814666)
Not really. In terms of functionalities, I consider ansible as a superset of terraform, without all the state management stuffs. Distributed systems are hard, and I will just let my cloud providers to be the single source of truth of all the states.

Here's a comment from the author of ansible when terraform was first released: https://news.ycombinator.com/item?id=8100036

> One of the things shown in the Ansible examples are how to do a cloud deploy in one hop, i.e. request resources and also configure the stack all the way to the end, from one button press, and can also be used to orchestrate the rolling updates of those machines, working with the cloud load balancers and so on, throughout their entire life cycle -- all using just the one tool.

Re:Terraform 0.15 General Availability by ggregoire on Wednesday April 14, 2021 @06:35PM (#26813945)
I've never used them but there are modules to provision stuff on AWS: https://docs.ansible.com/ansible/latest/scenario_guides/guid...

Edit: seems limited to ec2 and s3: https://docs.ansible.com/ansible/latest/collections/amazon/a...

Although you could provision other services with some custom modules using the aws-cli.

Re:Terraform 0.15 General Availability by matwood on Wednesday April 14, 2021 @09:48PM (#26815335)
Yeah. I use packer and ansible to build/configure AMIs. Terraform manages the configuration that launches said AMIs (through things like autoscaling, etc...).
Re:Terraform 0.15 General Availability by matwood on Wednesday April 14, 2021 @09:43PM (#26815302)
> upgrades between versions are smooth

I use tf and ansible regularly. I wouldn't call ansible upgrades exactly smooth, they deprecate features just like anyone else.

Re:Terraform 0.15 General Availability by apple4ever on Thursday April 15, 2021 @12:43AM (#26816270)
How do you ensure you have say 2 web servers created and connected to a load balancer? Is that part of your custom module?
Re:Terraform 0.15 General Availability by mr_C on Thursday April 15, 2021 @04:25AM (#26817622)
Using ec2_instance_info to check if the instance exists filtering by name (eg: selectattr('tags.Name', 'defined') | selectattr('tags.Name', 'equalto', server_name) ) and then standard ec2_instance module, same for lb.