NavigationContentFooter
Jump toSuggest an edit

Deploying Your First Infrastructure on Scaleway using Terraform

Reviewed on 16 October 2023Published on 06 April 2018
  • compute
  • Terraform
  • Scaleway-infrastructures
  • cloud
  • Elastic-Metal
  • Instance
  • HashiCorp-Terraform

HashiCorp Terraform is an open-source software tool to deploy IaaC: Infrastructure as Code. It means that you can automate infrastructure resources such as Network, Instances, Elastic Metal servers and more. It allows you to use declarative configuration files to manage the full lifecycle — create new resources, manage existing ones, and delete those no longer needed. The configuration language used by Terraform is called Hashicorp Configuration Language (HCL).

Before you start

To complete the actions presented below, you must have:

  • A Scaleway account logged into the console
  • Owner status or IAM permissions allowing you to perform actions in the intended Organization
  • An SSH key
  • A valid API key

Installing Terraform

The first step is to install Terraform on a server or on your computer to deploy and manage your resources. Terraform is installed on a user environment (which can either be your local computer or a remote server used to manage your infrastructures) to push configuration files to your cloud environment. We suggest adding your configuration files to a versioning system, like GitHub or Bitbucket to manage the versioning of your configurations.

Installation on macOS

Terraform can be easily installed on computers running macOS X using the Homebrew package manager. Run the following command in a terminal window to install the application:

brew install terraform

Installation on Windows

The installation of Terraform on Windows can be done in a single command-line using the Chocolatey package manager. Run the following command in a terminal window to install Terraform on computers running Microsoft Windows:

choco install terraform

Installation on Linux

The installation of Terraform on Linux can be done in a few simple steps.

  1. Download the HashiCorp GPG key on your machine.
    wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
  2. Add the Terraform repositories to the the apt sources.
    echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
  3. Update the apt packet cache and install Terraform using apt.
    apt update && apt install terraform
  4. Test the installation by running the terraform version command.
    terraform version
    Terraform v1.6.5
    on linux_amd64

Creating a first Instance using Terraform

To create a first Instance using Terraform, a declarative configuration file is required. This file contains all information of machine characteristics required to deploy. It has to be written in the Hashicorp Configuration Language (HCL). The deployment of Scaleway resources is done using the Scaleway Provider for Terraform. For more information about HCL, refer to the official documentation.

  1. Create a project folder (for example scaleway-terraform) and navigate into the newly created directory:

    mkdir scaleway-terraform && cd scaleway-terraform
  2. Create a new text file called scaleway.tf in your favorite text editor, for example nano:

    nano scaleway.tf
  3. Add the following content to the file to deploy a Development DEV1-L Instance running the Ubuntu Focal Fossa (20.04 LTS) base image in the fr-par-1 zone. Replace <SCW_ACCESS_KEY> and <SCW_SECRET_KEY> with your own API key information and <SCW_DEFAULT_PROJECT_ID> with your own Project ID:

    terraform {
    required_providers {
    scaleway = {
    source = "scaleway/scaleway"
    }
    }
    required_version = ">= 0.13"
    }
    provider "scaleway" {
    access_key = "<SCW_ACCESS_KEY>"
    secret_key = "<SCW_SECRET_KEY>"
    project_id = "<SCW_DEFAULT_PROJECT_ID>"
    zone = "fr-par-1"
    region = "fr-par"
    }
    resource "scaleway_instance_ip" "public_ip" {}
    resource "scaleway_instance_volume" "data" {
    size_in_gb = 30
    type = "l_ssd"
    }
    resource "scaleway_instance_server" "my-instance" {
    type = "DEV1-L"
    image = "ubuntu_focal"
    tags = [ "terraform instance", "my-instance" ]
    ip_id = scaleway_instance_ip.public_ip.id
    additional_volume_ids = [ scaleway_instance_volume.data.id ]
    root_volume {
    # The local storage of a DEV1-L Instance is 80 GB, subtract 30 GB from the additional l_ssd volume, then the root volume needs to be 50 GB.
    size_in_gb = 50
    }
    }

    Save the file and exit the text editor.

    Note

    Though it is the simplest way for a beginner, we do not generally recommend hard-coding your API key credentials into the configuration file. See the Authentication section of official Scaleway Terraform documentation to find out about other ways to manage your credentials.

  4. Run terraform init to load the newly created configuration file into Terraform:

    terraform init
    Initializing the backend...
    Initializing provider plugins...
    - Finding latest version of scaleway/scaleway...
    - Installing scaleway/scaleway v2.0.0...
    - Installed scaleway/scaleway v2.0.0 (signed by a HashiCorp partner, key ID F5BF26CADF6F9614)
    Partner and community providers are signed by their developers.
    If you'd like to know more about provider signing, you can read about it here:
    https://www.terraform.io/docs/cli/plugins/signing.html
    Terraform has created a lock file .terraform.lock.hcl to record the provider
    selections it made above. Include this file in your version control repository
    so that Terraform can guarantee to make the same selections by default when
    you run "terraform init" in the future.
    Terraform has been successfully initialized!
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  5. Plan the execution of the tasks to be done by terraform using the command terraform plan:

    terraform plan
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
    + create
    Terraform will perform the following actions:
    # scaleway_instance_ip.public_ip will be created
    + resource "scaleway_instance_ip" "public_ip" {
    + address = (known after apply)
    + id = (known after apply)
    + organization_id = (known after apply)
    + project_id = (known after apply)
    + reverse = (known after apply)
    + server_id = (known after apply)
    + zone = (known after apply)
    }
    # scaleway_instance_server.my-instance will be created
    + resource "scaleway_instance_server" "my-instance" {
    + additional_volume_ids = (known after apply)
    + boot_type = "local"
    + bootscript_id = (known after apply)
    + enable_dynamic_ip = false
    + enable_ipv6 = false
    + id = (known after apply)
    + image = "ubuntu_focal"
    + ip_id = (known after apply)
    + ipv6_address = (known after apply)
    + ipv6_gateway = (known after apply)
    + ipv6_prefix_length = (known after apply)
    + name = (known after apply)
    + organization_id = (known after apply)
    + placement_group_policy_respected = (known after apply)
    + private_ip = (known after apply)
    + project_id = (known after apply)
    + public_ip = (known after apply)
    + security_group_id = (known after apply)
    + state = "started"
    + tags = [
    + "terraform instance",
    + "my-instance",
    ]
    + type = "DEV1-L"
    + zone = (known after apply)
    + root_volume {
    + delete_on_termination = true
    + size_in_gb = 50
    + volume_id = (known after apply)
    }
    }
    # scaleway_instance_volume.data will be created
    + resource "scaleway_instance_volume" "data" {
    + id = (known after apply)
    + name = (known after apply)
    + organization_id = (known after apply)
    + project_id = (known after apply)
    + server_id = (known after apply)
    + size_in_gb = 30
    + type = "l_ssd"
    + zone = (known after apply)
    }
    Note: You didn't specify an "-out" parameter to save this plan, so Terraform
    cannot guarantee that exactly these actions will be performed if
    "terraform apply" is subsequently run.
  6. Apply the new configuration and create the Instance using Terraform by running terraform apply, if the output obtained is the same as the one above. Confirm the execution of the plan by typing yes when prompted:

    terraform apply
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
    + create
    Terraform will perform the following actions:
    # scaleway_instance_ip.public_ip will be created
    + resource "scaleway_instance_ip" "public_ip" {
    + address = (known after apply)
    + id = (known after apply)
    + organization_id = (known after apply)
    + project_id = (known after apply)
    + reverse = (known after apply)
    + server_id = (known after apply)
    + zone = (known after apply)
    }
    # scaleway_instance_server.my-instance will be created
    + resource "scaleway_instance_server" "my-instance" {
    + additional_volume_ids = (known after apply)
    + boot_type = "local"
    + bootscript_id = (known after apply)
    + enable_dynamic_ip = false
    + enable_ipv6 = false
    + id = (known after apply)
    + image = "ubuntu_focal"
    + ip_id = (known after apply)
    + ipv6_address = (known after apply)
    + ipv6_gateway = (known after apply)
    + ipv6_prefix_length = (known after apply)
    + name = (known after apply)
    + organization_id = (known after apply)
    + placement_group_policy_respected = (known after apply)
    + private_ip = (known after apply)
    + project_id = (known after apply)
    + public_ip = (known after apply)
    + security_group_id = (known after apply)
    + state = "started"
    + tags = [
    + "terraform instance",
    + "my-instance",
    ]
    + type = "DEV1-L"
    + zone = (known after apply)
    + root_volume {
    + delete_on_termination = true
    + size_in_gb = 50
    + volume_id = (known after apply)
    }
    }
    # scaleway_instance_volume.data will be created
    + resource "scaleway_instance_volume" "data" {
    + id = (known after apply)
    + name = (known after apply)
    + organization_id = (known after apply)
    + project_id = (known after apply)
    + server_id = (known after apply)
    + size_in_gb = 30
    + type = "l_ssd"
    + zone = (known after apply)
    }
    Plan: 3 to add, 0 to change, 0 to destroy.
    Do you want to perform these actions?
    Terraform will perform the actions described above.
    Only 'yes' will be accepted to approve.
    Enter a value: yes
    scaleway_instance_ip.public_ip: Creating...
    scaleway_instance_volume.data: Creating...
    scaleway_instance_volume.data: Creation complete after 0s [id=fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a]
    scaleway_instance_ip.public_ip: Creation complete after 0s [id=fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f]
    scaleway_instance_server.my-instance: Creating...
    scaleway_instance_server.my-instance: Still creating... [10s elapsed]
    scaleway_instance_server.my-instance: Still creating... [20s elapsed]
    scaleway_instance_server.my-instance: Still creating... [30s elapsed]
    scaleway_instance_server.my-instance: Still creating... [40s elapsed]
    scaleway_instance_server.my-instance: Still creating... [50s elapsed]
    scaleway_instance_server.my-instance: Still creating... [1m0s elapsed]
    scaleway_instance_server.my-instance: Still creating... [1m10s elapsed]
    scaleway_instance_server.my-instance: Creation complete after 1m12s [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
    Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
  7. Go to the Instances section in your Scaleway console. You can see that the Instance has been created:

Modifying an Instance using Terraform

We now have a first Instance up and running. Next, we will modify it by restricting access using security groups. We are going to DROP all traffic to the Instance by default: only traffic to ports 80 (HTTP), 443 (HTTPS) and 22 (SSH) will be allowed. To do this, we have to add some more lines to our existing configuration file scaleway.tf.

Important

All changes made to the local configuration file are not effective in production before the new configuration is applied using the terraform apply command.

  1. Open the configuration file scaleway.tf in a text editor and edit it as follows. To modify our Instance, we add a scaleway_instance_security_group resource, and the security_group_id identifier to our existing scaleway_instance_server resource.
    terraform {
    required_providers {
    scaleway = {
    source = "scaleway/scaleway"
    }
    }
    required_version = ">= 0.13"
    }
    provider "scaleway" {
    access_key = "<SCW_ACCESS_KEY>"
    secret_key = "<SCW_SECRET_KEY>"
    project_id = "<SCW_DEFAULT_PROJECT_ID>"
    zone = "fr-par-1"
    region = "fr-par"
    }
    resource "scaleway_instance_ip" "public_ip" {}
    resource "scaleway_instance_volume" "data" {
    size_in_gb = 30
    type = "l_ssd"
    }
    resource "scaleway_instance_security_group" "my-security-group" {
    inbound_default_policy = "drop"
    outbound_default_policy = "accept"
    inbound_rule {
    action = "accept"
    port = "22"
    }
    inbound_rule {
    action = "accept"
    port = "80"
    }
    inbound_rule {
    action = "accept"
    port = "443"
    }
    }
    resource "scaleway_instance_server" "my-instance" {
    type = "DEV1-L"
    image = "ubuntu_focal"
    tags = [ "terraform instance", "my-instance" ]
    ip_id = scaleway_instance_ip.public_ip.id
    additional_volume_ids = [ scaleway_instance_volume.data.id ]
    root_volume {
    # The local storage of a DEV1-L Instance is 80 GB, subtract 30 GB from the additional l_ssd volume, then the root volume needs to be 50 GB.
    size_in_gb = 50
    }
    security_group_id = scaleway_instance_security_group.my-security-group.id
    }
    Save the file and exit the text editor.
  2. Run terraform apply again to see how Terraform applies the new configuration to the existing instance:
    terraform apply
    scaleway_instance_ip.public_ip: Refreshing state... [id=fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f]
    scaleway_instance_volume.data: Refreshing state... [id=fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a]
    scaleway_instance_server.my-instance: Refreshing state... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
    Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
    + create
    ~ update in-place
    Terraform will perform the following actions:
    # scaleway_instance_security_group.my-security-group will be created
    + resource "scaleway_instance_security_group" "my-security-group" {
    + enable_default_security = true
    + external_rules = false
    + id = (known after apply)
    + inbound_default_policy = "drop"
    + name = (known after apply)
    + organization_id = (known after apply)
    + outbound_default_policy = "accept"
    + project_id = (known after apply)
    + stateful = true
    + zone = (known after apply)
    + inbound_rule {
    + action = "accept"
    + port = 22
    + protocol = "TCP"
    }
    + inbound_rule {
    + action = "accept"
    + port = 80
    + protocol = "TCP"
    }
    + inbound_rule {
    + action = "accept"
    + port = 443
    + protocol = "TCP"
    }
    }
    # scaleway_instance_server.my-instance will be updated in-place
    ~ resource "scaleway_instance_server" "my-instance" {
    id = "fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e"
    name = "tf-srv-amazing-heisenberg"
    ~ security_group_id = "fr-par-1/17ae2620-b190-4126-bb7f-ad2edec693d7" -> (known after apply)
    tags = [
    "terraform instance",
    "my-instance",
    ]
    # (15 unchanged attributes hidden)
    # (1 unchanged block hidden)
    }
    Plan: 1 to add, 1 to change, 0 to destroy.
    Do you want to perform these actions?
    Terraform will perform the actions described above.
    Only 'yes' will be accepted to approve.
    Enter a value: yes
    scaleway_instance_security_group.my-security-group: Creating...
    scaleway_instance_security_group.my-security-group: Creation complete after 4s [id=fr-par-1/50368bc5-cbd0-4956-975c-8fd45a055171]
    scaleway_instance_server.my-instance: Modifying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
    scaleway_instance_server.my-instance: Modifications complete after 2s [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
    Apply complete! Resources: 1 added, 1 changed, 0 destroyed.
  3. Terraform has created the security group and modified the configuration of the existing Instance by adding it to the newly created group. You can see the group from the Scaleway console and check the rules that have been created:

Adding resources to an infrastructure

Terraform allows us to add additional resources to infrastructures and is capable of managing both Instances and Elastic Metal servers. Let us add an Elastic Metal server to our Terraform project using the Elastic Metal module of the Scaleway provider.

  • Open the file scaleway.tf in a text editor and add the "scaleway_account_ssh_key" data source and the scaleway_baremetal_server resource as follows:
Note

Remember to replace the SSH key ID field with the ID for your own SSH key, available in the credentials tab of your Project Dashboard

terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
}
}
required_version = ">= 0.13"
}
provider "scaleway" {
access_key = "<SCW_ACCESS_KEY>"
secret_key = "<SCW_SECRET_KEY>"
project_id = "<SCW_DEFAULT_PROJECT_ID>"
zone = "fr-par-1"
region = "fr-par"
}
resource "scaleway_instance_ip" "public_ip" {}
resource "scaleway_instance_volume" "data" {
size_in_gb = 30
type = "l_ssd"
}
resource "scaleway_instance_security_group" "my-security-group" {
inbound_default_policy = "drop"
outbound_default_policy = "accept"
inbound_rule {
action = "accept"
port = "22"
}
inbound_rule {
action = "accept"
port = "80"
}
inbound_rule {
action = "accept"
port = "443"
}
}
resource "scaleway_instance_server" "my-instance" {
type = "DEV1-L"
image = "ubuntu_focal"
tags = [ "terraform instance", "my-instance" ]
ip_id = scaleway_instance_ip.public_ip.id
additional_volume_ids = [ scaleway_instance_volume.data.id ]
root_volume {
# The local storage of a DEV1-L Instance is 80 GB, subtract 30 GB from the additional l_ssd volume, then the root volume needs to be 50 GB.
size_in_gb = 50
}
}
data "scaleway_account_ssh_key" "main" {
ssh_key_id = "<SSH-KEY-ID>"
}
resource "scaleway_baremetal_server" "base" {
zone = "fr-par-2"
offer = "GP-BM1-S"
os = "d17d6872-0412-45d9-a198-af82c34d3c5c"
ssh_key_ids = [data.scaleway_account_ssh_key.main.ssh_key_id]
}

Apply the new configuration using terraform apply. Terraform will add an Elastic Metal server to the existing infrastructure

# scaleway_baremetal_server.base will be created
+ resource "scaleway_baremetal_server" "base" {
+ domain = (known after apply)
+ id = (known after apply)
+ ips = (known after apply)
+ name = (known after apply)
+ offer = "GP-BM1-S"
+ offer_id = (known after apply)
+ organization_id = (known after apply)
+ os = "d17d6872-0412-45d9-a198-af82c34d3c5c"
+ os_id = (known after apply)
+ ssh_key_ids = [
+ "<SSH-KEY-ID>",
]
+ zone = "fr-par-2"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
scaleway_baremetal_server.base: Creating...
scaleway_baremetal_server.base: Still creating... [10s elapsed]
scaleway_baremetal_server.base: Still creating... [20s elapsed]
scaleway_baremetal_server.base: Still creating... [30s elapsed]
scaleway_baremetal_server.base: Still creating... [40s elapsed]
scaleway_baremetal_server.base: Still creating... [50s elapsed]
scaleway_baremetal_server.base: Still creating... [1m0s elapsed]
scaleway_baremetal_server.base: Still creating... [1m10s elapsed]
scaleway_baremetal_server.base: Still creating... [1m20s elapsed]
scaleway_baremetal_server.base: Still creating... [1m30s elapsed]
[...]
scaleway_baremetal_server.base: Creation complete after 12m42s [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7]
Apply complete! Resources: 1 added, 0 changed, 1 destroyed.
Note

The creation of an Elastic Metal server may take up to several minutes.

Storing the Terraform state in the cloud

Optionally, you can use the S3 Backend to store your Terraform state in a Scaleway Object Storage. Configure your backend as follows:

terraform {
backend "s3" {
bucket = "terraform_state"
key = "my_state.tfstate"
region = "fr-par"
access_key = "<SCW_ACCESS_KEY>"
secret_key = "<SCW_SECRET_KEY>"
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
endpoints = {
s3 = "https://s3.fr-par.scw.cloud"
}
}
}

Deleting infrastructures using Terraform

Now you have deployed a Terraform infrastructure, modified its settings and added additional resources. If you want to destroy the infrastructure, you can clean up everything using the terraform destroy command.

Run terraform destroy in your terminal. The infrastructure created previously will be destroyed:

terraform destroy
scaleway_instance_ip.public_ip: Refreshing state... [id=fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f]
scaleway_instance_volume.data: Refreshing state... [id=fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a]
scaleway_instance_security_group.my-security-group: Refreshing state... [id=fr-par-1/50368bc5-cbd0-4956-975c-8fd45a055171]
scaleway_baremetal_server.base: Refreshing state... [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7]
scaleway_instance_server.my-instance: Refreshing state... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
Terraform used the selected providers to generate the following execution plan. Resource actions are
indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# scaleway_baremetal_server.base will be destroyed
- resource "scaleway_baremetal_server" "base" {
- domain = "f761ff74-de50-44c3-afab-3c1ef00b16b7.fr-par-2.baremetal.scw.cloud" -> null
- id = "fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7" -> null
- ips = [
- {
- address = "2001:bc8:1200:1:dac4:97ff:fe5b:7551"
- id = "3cc6979a-3776-42dd-8fdd-9ed552ed57e1"
- reverse = "f761ff74-de50-44c3-afab-3c1ef00b16b7.fr-par-2.baremetal.scw.cloud"
- version = "IPv6"
},
- {
- address = "51.159.57.46"
- id = "cc18b9aa-b748-4185-af46-c4bec865c75b"
- reverse = "f761ff74-de50-44c3-afab-3c1ef00b16b7.fr-par-2.baremetal.scw.cloud"
- version = "IPv4"
},
] -> null
- name = "tf-bm-cranky-kowalevski" -> null
- offer = "GP-BM1-M" -> null
- offer_id = "fr-par-2/964f9b38-577e-470f-a220-7d762f9e8672" -> null
- organization_id = "<ORGANIZATION-ID>" -> null
- os = "d17d6872-0412-45d9-a198-af82c34d3c5c" -> null
- os_id = "fr-par-2/d17d6872-0412-45d9-a198-af82c34d3c5c" -> null
- ssh_key_ids = [
- "<SSH-KEY-ID>",
] -> null
- tags = [] -> null
- zone = "fr-par-2" -> null
}
# scaleway_instance_ip.public_ip will be destroyed
- resource "scaleway_instance_ip" "public_ip" {
- address = "163.172.129.226" -> null
- id = "fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f" -> null
- organization_id = "<SCW_DEFAULT_ORGANIZATION_ID>" -> null
- project_id = "<SCW_DEFAULT_PROJECT_ID>" -> null
- server_id = "fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e" -> null
- zone = "fr-par-1" -> null
}
# scaleway_instance_security_group.my-security-group will be destroyed
- resource "scaleway_instance_security_group" "my-security-group" {
- enable_default_security = true -> null
- external_rules = false -> null
- id = "fr-par-1/50368bc5-cbd0-4956-975c-8fd45a055171" -> null
- inbound_default_policy = "drop" -> null
- name = "tf-sg-fervent-joliot" -> null
- organization_id = "<SCW_DEFAULT_ORGANIZATION_ID>" -> null
- outbound_default_policy = "accept" -> null
- project_id = "<SCW_DEFAULT_PROJECT_ID>" -> null
- stateful = true -> null
- zone = "fr-par-1" -> null
- inbound_rule {
- action = "accept" -> null
- port = 22 -> null
- protocol = "TCP" -> null
}
- inbound_rule {
- action = "accept" -> null
- port = 80 -> null
- protocol = "TCP" -> null
}
- inbound_rule {
- action = "accept" -> null
- port = 443 -> null
- protocol = "TCP" -> null
}
}
# scaleway_instance_server.my-instance will be destroyed
- resource "scaleway_instance_server" "my-instance" {
- additional_volume_ids = [
- "fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a",
] -> null
- boot_type = "local" -> null
- bootscript_id = "fdfe150f-a870-4ce4-b432-9f56b5b995c1" -> null
- enable_dynamic_ip = false -> null
- enable_ipv6 = false -> null
- id = "fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e" -> null
- image = "ubuntu_focal" -> null
- ip_id = "fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f" -> null
- ipv6_prefix_length = 0 -> null
- name = "tf-srv-amazing-heisenberg" -> null
- organization_id = "<SCW_DEFAULT_ORGANIZATION_ID>" -> null
- private_ip = "10.73.136.53" -> null
- project_id = "<SCW_DEFAULT_PROJECT_ID>" -> null
- public_ip = "163.172.129.226" -> null
- security_group_id = "fr-par-1/50368bc5-cbd0-4956-975c-8fd45a055171" -> null
- state = "started" -> null
- tags = [
- "terraform instance",
- "my-instance",
] -> null
- type = "DEV1-L" -> null
- zone = "fr-par-1" -> null
- root_volume {
- delete_on_termination = true -> null
- size_in_gb = 50 -> null
- volume_id = "fr-par-1/fea0bd14-de92-4ea3-aa84-3df0df4651a3" -> null
}
}
# scaleway_instance_volume.data will be destroyed
- resource "scaleway_instance_volume" "data" {
- id = "fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a" -> null
- name = "tf-vol-strange-benz" -> null
- organization_id = "<SCW_DEFAULT_ORGANIZATION_ID>" -> null
- project_id = "<SCW_DEFAULT_PROJECT_ID>" -> null
- server_id = "eb731c89-0cb7-4148-9b5f-18470143aa7e" -> null
- size_in_gb = 30 -> null
- type = "l_ssd" -> null
- zone = "fr-par-1" -> null
}
Plan: 0 to add, 0 to change, 5 to destroy.
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
scaleway_instance_server.my-instance: Destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e]
scaleway_baremetal_server.base: Destroying... [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7]
scaleway_baremetal_server.base: Still destroying... [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7, 10s elapsed]
scaleway_instance_server.my-ubuntu-instance: Still destroying... [id=fr-par-1/df778c76-36dc-43eb-b028-f000d131a75d, 10s elapsed]
scaleway_baremetal_server.base: Still destroying... [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7, 20s elapsed]
scaleway_instance_server.my-ubuntu-instance: Still destroying... [id=fr-par-1/df778c76-36dc-43eb-b028-f000d131a75d, 20s elapsed]
scaleway_baremetal_server.base: Still destroying... [id=fr-par-2/f761ff74-de50-44c3-afab-3c1ef00b16b7, 30s elapsed]
scaleway_instance_server.my-ubuntu-instance: Still destroying... [id=fr-par-1/df778c76-36dc-43eb-b028-f000d131a75d, 30s elapsed]
scaleway_baremetal_server.base: Destruction complete after 31s
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 10s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 20s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 30s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 40s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 50s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 1m0s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 1m10s elapsed]
scaleway_instance_server.my-instance: Still destroying... [id=fr-par-1/eb731c89-0cb7-4148-9b5f-18470143aa7e, 1m20s elapsed]
scaleway_instance_server.my-instance: Destruction complete after 1m25s
scaleway_instance_ip.public_ip: Destroying... [id=fr-par-1/377ba8cc-e2c0-46cf-a651-df2e1ec71a8f]
scaleway_instance_volume.data: Destroying... [id=fr-par-1/02522ca3-0ece-454a-9240-087a1248f08a]
scaleway_instance_security_group.my-security-group: Destroying... [id=fr-par-1/50368bc5-cbd0-4956-975c-8fd45a055171]
scaleway_instance_ip.public_ip: Destruction complete after 0s
scaleway_instance_security_group.my-security-group: Destruction complete after 0s
scaleway_instance_volume.data: Destruction complete after 0s
Destroy complete! Resources: 5 destroyed.

You have now managed the complete lifecycle of an infrastructure using Terraform. To discover more Terraform commands, use the terraform -h command. Common Terraform commands include for example:

  • apply: Builds or changes infrastructure
  • console: Interactive console for Terraform interpolations
  • destroy: Destroy Terraform-managed infrastructure env Workspace management
  • fmt: Rewrites configuration files to canonical format
  • get: Download and install modules for the configuration
  • graph: Create a visual graph of Terraform resources
  • import: Import existing infrastructure into Terraform
  • init: Initialize a Terraform working directory
  • output: Read an output from a state file
  • plan: Generate and show an execution plan
  • providers: Prints a tree of the providers used in the configuration
  • refresh: Update local state file against real resources
  • show: Inspect Terraform state or plan
  • taint: Manually mark a resource for recreation
  • untaint: Manually unmark a resource as tainted
  • validate Validates the Terraform files
  • version: Prints the Terraform version
  • workspace: Workspace management

To create configurations that are shareable and version-controlled, it is recommended that you organize your code with modules. Modules are used to encapsulate logic and design a layer of abstraction for Terraform code.

Most modules manage a few closely related resources from a single provider and allow you to parameterize the configurations. You can define variables to simplify the management of your infrastructures and to duplicate it in no time.

For example, create a configuration file variables.tf in your Terraform Project directory and edit it as follows:

variable "zone" {
default = "fr-par-1"
}

You have 3 options to use these variables:

  • As an environment variable: TF_VAR_zone=${var.zone} terraform apply
  • As a command-line parameter variable: terraform apply -var zone=${var.zone}
  • As a variables file: terraform apply -var-file=variables.tf

To learn more, discover how to deploy your cloud resources using Packer and Terraform and check out the full Scaleway Provider documentation for Terraform.

Docs APIScaleway consoleDedibox consoleScaleway LearningScaleway.comPricingBlogCarreer
© 2023-2024 – Scaleway