Skip to content

Latest commit

 

History

History
65 lines (44 loc) · 2.27 KB

File metadata and controls

65 lines (44 loc) · 2.27 KB

Terraform Python example

In this tutorial you will discover an example of Instance automation using Python and Terraform:

  • Automatically shut down / start instances

Requirements

Context

In this tutorial, we will simulate a project with a production environment that will be running all the time and a development environment that will be turn off on week-ends to save costs.

Project Structure

  1. This folder stores your configuration as explained in the terraform documentation.

  2. This folder contains 5 files to configure your infrastructure: a. 'main.tf': will contain the main set of configurations for your project. Here, it will be our instance. b. 'provider.tf': Terraform relies on plugins called “providers” to interact with remote systems. c. 'variables.tf': will contain the variable definitions for your project. Since all Terraform values must be defined, any variables that are not given a default value will become required arguments. d. 'terraform.tfvars': allows you to set the actual value of the variables.

  3. Create the following folder: a. 'function': to store your function code. b. 'files': (generated in main.tf when creating function's zip file) to temporarily store your zip function code.

Deploy your infrastructure

Now that everything is set up, deploy everything using Terraform

  1. Add your Scaleway credentials to your environment variables
export SCW_ACCESS_KEY="<your-secret-key>"
export SCW_SECRET_KEY="<your-access-key>"
  1. Initialize Terraform:
terraform init
  1. Let terraform verify your configuration:
terraform plan
  1. Deploy your infrastructure:
terraform apply
  1. In order to remove your infrastructure resources, you can use:
terraform destroy