Nuwantha
Nuwantha

Reputation: 23

Terraform stop command

I'm new to terraform. I wrote a terraform code to provision an instance to oracle cloud infrastructure and it works fine. Somehow the problem is there is no "stop" command in terraform cmd, they only have "destroy" command. Is there any way to stop resources instead of destroying it?

Upvotes: 0

Views: 3545

Answers (3)

bmuthuv
bmuthuv

Reputation: 326

You also have an option of setting up Functions that can manage the lifecycle actions. There is already a public solution such as the one below in case you would like to pursue further.

https://github.com/AnykeyNL/OCI-AutoScale/blob/master/AutoScaleALL.py

Upvotes: 0

bmuthuv
bmuthuv

Reputation: 326

I suggest using Terraform for Provisioning (Apply) and Termination (Destroy). Stopping/Starting the instance through OCI CLI is simple and can be done easily through a simple shell script such as this.

This is less complex and easily maintainable for simpler requirements.

Instance.sh File

oci compute instance action --action $1 --instance-id ocid1.instance.oc1.iad.an.....7d3xamffeq

Start Command: $ source Instance.sh start

Stop Command: $ source Instance.sh stop

Upvotes: 1

HumayunM
HumayunM

Reputation: 554

if you are looking for a solution, there is no such option currently. You can request for a feature here

As a temporary workaround, you could toy with user_data and update and send a shutdown request using it. i.e. terraform apply

Upvotes: 2

Related Questions