rjeczalik / terraform-aws-scylla

Terraform module for creating Scylla clusters on AWS
http://cloud.scylladb.com
21 stars 10 forks source link

null resource scylla_schema triggers even no changes in instance #9

Closed debojitkakoti closed 5 years ago

debojitkakoti commented 5 years ago

resource "null_resource" "scylla_schema" {} is being triggered without any changes to the instance id! It should trigger only when there is any changes in the first node,

triggers { id = "${element(aws_instance.scylla.*.id, 0)}" }

rjeczalik commented 5 years ago

Thanks @debojitkakoti! I agree, in general second run of terraform apply on already executed plan should be a nop, I did not test the module in terms of idempotency yet, so there could be a room for improvement.

debojitkakoti commented 5 years ago

@rjeczalik Yeah, I have create 2 nodes cluster first then increased it to 3, so it is again triggering "scylla-schema" null_resouce and attempting to create the users! But the cassandra user is being deleted before, so it is running on loop!!

Let me know if the following solution will help? Introduce count variable and set to 0 and if count is more than 5 break from the first while loop? In the second while loop anyway the user will exist so schema changes will not be applied!

Let me know your suggestions, anyway it seems like terraform bug!!

rjeczalik commented 5 years ago

@debojitkakoti Actually you just raised a bigger goal that I had in my mind for this module.

In case of Scylla cluster it's not that simple to just increase node count from 2 to 3 - terraform is not application-aware, it will blindly try to create the resources. It does not understand how to decomission a node or how to add a new one - how to reconfigure seeds or do rolling restart of nodes.

Terraform is good for the initial bootstrapping of the cluster, however modification to an existing cluster is temporarily out-of-scope for this module. My personal goal is to try to make it as flexible as possible (e.g. allow for reusing existing resources), but it won't take over the maintenance of your cluster.

If you'd be interested on how to make all that work magically without supervision hit me on e-mail.

debojitkakoti commented 5 years ago

@rjeczalik Thanks, I think, I have found a solution to this problem,

Instead of using instance id as the trigger, If I use cluster id then null_resource will run only once when cluster is being setup, after that if you increase the instance count it will not run, because cluster id is not being changed. Here is the code block.

resource "null_resource" "scylla_schema" {
    // Triggers only when cluster id is changed, for the first time it ll execute 
    triggers {
        id = "${random_uuid.cluster_id.result}"
    }