Comments (6)
Controlling the powered state is currently not supported because certain service state information becomes unavailable and/or unchangeable for powered off services. We will probably look into this at some point but making it work consistently in all cases is quite difficult.
Could you elaborate what kind of use case you have?
from terraform-provider-aiven.
In out dev environment we bring up expensive large resources (kafka, pg) along with big AWS docker swarm only temporarily. When not in use we destroy swarm in AWS and shutdown Kafka and PG at Aiven
This preserves all the data accumulated when we bring it up next time.
We now switch to Terragrunt to control individual Terraform projects responsible for these pieces of infrastructure (Kafka, PG, SQL, Swarm, InlfuxDB) to allow us bring up/down entire development environment with a single command.
Thinking more on this I realized the way "terraform destroy" works it needs to destroy the resource not just change its powerstate.
So to make it work in our use case you can add new property similar to termination_protection.
Call it "power_off_on_destroy". When this property set to "true" "terraform destroy" will perform poweroff instead of actual destroy of service.
Next "terraform apply" on same service (same properties for name, cloud, etc) will discover existing powered off service and turn it on instead of creating new one.
from terraform-provider-aiven.
Some attribute that powers off services instead of deleting them when the Terraform environment is destroyed would seem like a reasonable extension. However, if you use Terraform to also control your databases, as you should if you're using it otherwise, the databases would be deleted separately so even if the service itself is preserved the data would be gone. The issue with gone databases could be worked around by separately removing them from Terraform state (terraform state rm aiven_database.mydb
etc.) before doing terraform destroy
so the teardown part could be made to work somewhat reasonably.
Bringing the services back up with Terraform alone is something that would require somewhat too hacky behavior. Automatically importing services when they are being created does not sound like something we'd want to do. There's too high risk that the system ends up automatically doing something one didn't expect to happen. You could just do terraform import aiven_service.myservice myproject/myservice
etc. for the service related resources explicitly before running terraform apply
so that would take care of getting the earlier service back to Terraform without hacks. However, the service would then still be powered off and wouldn't really work. The power on / power off functionality is difficult to make properly in all cases as mentioned earlier. Since powering on a service manually doesn't require more than
curl -XPUT -H "Authorization: aivenv1 myapitoken" -H "Content-Type: application/json" -d '{"powered": true}' "https://api.aiven.io/v1beta/project/myproject/service/myservice"
you could do that before starting to apply the Terraform configuration. Now then if you do manual step to power on the services you might as well do manual step to power off the services without having the slightly hacky power_off_on_destroy
attribute by doing exactly the same request as above but with value false
. So your steps would be something like:
Power on:
curl ... '{"powered": true}' ...
terraform import aiven_service.mypg myproject/mypg
terraform import aiven_database.mydb myproject/mypg/mydb
terraform apply
Powef off:
terraform state rm aiven_database.mydb
terraform state rm aiven_service.mypg
curl ... '{"powered": false}' ...
terraform destroy
from terraform-provider-aiven.
Great suggestions and examples, thanks Rauli!
I'm still in early stages of converting all pieces of infrastructure under TF control.
At this time we use scripts that create folders for different components (VPC, backup, InlfuxDB, swarm) with single main.tf file. Then the script runs apply or destroy inside it.
Our desire is to get away from scripting model and express as much of our infrastructure as code.
I quickly realized I could not do this with Terraform alone so found Terragrunt solves many deficiencies.
I see that Terragrunt has before/after hooks feature to do exactly this sort of thing you suggest.
https://github.com/gruntwork-io/terragrunt#before-and-after-hooks
from terraform-provider-aiven.
I'm closing this for now as the "terraform destroy without deleting stateful services" and "terraform apply with auto import of services" features are not directly implementable in a reasonable way and workaround exists. Please let us know if you still think there are some changes that should be done to the Aiven Terraform provider itself or if there's some other input you'd require.
from terraform-provider-aiven.
Thanks. Once I start using this I'll have more input.
from terraform-provider-aiven.
Related Issues (20)
- Handle correctly missing (or deleted) `kafka_topics` HOT 4
- Importing member of the "Account Owner" team doesn't change the state. HOT 7
- Unable to update aiven_service_integration_endpoint of endpoint type `rsyslog` HOT 7
- creating a new kafka cluster with v3.11.0 fails HOT 8
- Error creating resources: unable to wait for service state change: context deadline exceeded HOT 9
- API removed for `aiven_flink_table` HOT 1
- upgrading to v3.13.0 or higher fails when having aiven_kafka_topic resources with read timeout HOT 14
- 4.0.0 pg_user_config.ip_filter_object does not set ips on aiven_pg HOT 6
- Guides in the documentation for migrating away from deprecated resources HOT 7
- aiven_kafka (Data Source) returns empty connect_uri string HOT 7
- How to get kafka registry port HOT 2
- [Kafka] ip_filter_object error when applying HOT 7
- Kafka connector plan hides all changes HOT 5
- regression with 4.1.2 version HOT 2
- Fail terraform plan when reducing partition count for aiven_kafka_topic HOT 3
- [Kafka] ip_filter_object unnecessary output HOT 4
- Error on apply changes resource after maintenance HOT 4
- Show Values for the Supported Integration Types for the aiven_service_integration_endpoint resource HOT 1
- Feature request: (Mirrormaker) External Kafka integration HOT 1
- admin_username usage causes resource recreation in 3.9.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-aiven.