//Указываем путь к провайдеру. Для провайдеров вроде AWS и MS AZure это не требуется
terraform {
required_providers {
sbercloud = {
source = "sbercloud-terraform/sbercloud"
version = "1.0.0"
}
}
}
//Настраиваем провайдера
provider "sbercloud" {
region = "ru-moscow-1" //указываем регион. Пока что он один
access_key = "TJGZBKSQCYPKQNY" //тут нужно указать ваш ключ
secret_key = "az8N8mWUumYK19wjT8LQ0RZaidhCNNcvTgI" //тут нужно указать ваш пароль
}
//Создаем ресурс VPC. "sbercloud_vpc" - это название ресурса, "test_vpc" - имя объекта в конфиге Terraform, чтобы можно было ссылаться на этот ресурс
resource "sbercloud_vpc" "test_vpc" {
name = "test_vpc" //имя VPC, которое будет создано, может отличаться от имени объекта
cidr = "172.30.0.0/23" // сама сеть
}
cd Documents/Terraform/Sbercloud/
terraform init
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.
terraform plan
% terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# sbercloud_vpc.test_vpc will be created
+ resource "sbercloud_vpc" "test_vpc" {
+ cidr = "172.30.0.0/23"
+ enterprise_project_id = (known after apply)
+ id = (known after apply)
+ name = "test_vpc"
+ region = (known after apply)
+ routes = (known after apply)
+ shared = (known after apply)
+ status = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
terraform apply
% terraform apply
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# sbercloud_vpc.test_vpc will be created
+ resource "sbercloud_vpc" "test_vpc" {
+ cidr = "172.30.0.0/23"
+ enterprise_project_id = (known after apply)
+ id = (known after apply)
+ name = "test_vpc"
+ region = (known after apply)
+ routes = (known after apply)
+ shared = (known after apply)
+ status = (known after apply)
}
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:
Enter a value: yes
sbercloud_vpc.test_vpc: Creating...
sbercloud_vpc.test_vpc: Creation complete after 6s [id=9cbebc28-1286-42e0-91c2-669ec6ce320b]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
terraform destroy
terraform destroy
sbercloud_vpc.test_vpc: Refreshing state... [id=9cbebc28-1286-42e0-91c2-669ec6ce320b]
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy
Terraform will perform the following actions:
# sbercloud_vpc.test_vpc will be destroyed
- resource "sbercloud_vpc" "test_vpc" {
- cidr = "172.30.0.0/23" -> null
- enterprise_project_id = "0" -> null
- id = "9cbebc28-1286-42e0-91c2-669ec6ce320b" -> null
- name = "test_vpc" -> null
- region = "ru-moscow-1" -> null
- routes = [] -> null
- shared = false -> null
- status = "OK" -> null
- tags = {} -> null
}
Plan: 0 to add, 0 to change, 1 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:
Enter a value: yes
sbercloud_vpc.test_vpc: Destroying... [id=9cbebc28-1286-42e0-91c2-669ec6ce320b]
sbercloud_vpc.test_vpc: Destruction complete after 10s
Destroy complete! Resources: 1 destroyed.
terraform {
required_providers {
sbercloud = {
source = "sbercloud-terraform/sbercloud"
version = "1.0.0"
}
}
}
provider "sbercloud" {
region = "ru-moscow-1"
project_name = "ru-moscow-1_network"
access_key = “my-access-key“
secret_key = “my-access-key“
}
resource "sbercloud_vpc" "vpc_ex1" {
name = "tf_vpc_1"
cidr = "192.168.0.0/24"
}
resource "sbercloud_vpc_subnet" "subnet_ex1" {
name = "tf_subnet_1"
cidr = "192.168.0.0/25"
gateway_ip = "192.168.0.1"
vpc_id = "fca04b3a-13e1-41f2-a08c-455"
}
data "sbercloud_images_image" "image_ex1" {
name = "Ubuntu 18.04 server 64bit"
most_recent = true
}
data "sbercloud_compute_flavors" "vmtype" {
availability_zone = "ru-moscow-1a"
performance_type = "normal"
cpu_core_count = 4
memory_size = 8
}
resource "sbercloud_compute_instance" "instance_ex1" {
name = "tf_instance"
image_id = data.sbercloud_images_image.image_ex1.id
flavor_id = data.sbercloud_compute_flavors.vmtype.ids[0]
security_groups = ["default"]
availability_zone = "ru-moscow-1a"
system_disk_type = "SAS"
system_disk_size = 20
network {
uuid = sbercloud_vpc_subnet.subnet_ex1.id
}
}