-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(example): Add a working example (FlexibleEngineCloud#874)
* docs: Fix typo * chore(example): Add a working example
- Loading branch information
Showing
25 changed files
with
221 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
# FULL Terraform flexibleengine Example | ||
|
||
This script will create the following resources (if enabled): | ||
* Volumes | ||
* Floating IPs | ||
* Neutron Ports | ||
* Instances | ||
|
||
* VPC | ||
* VPC Subnet | ||
* Keypair | ||
* Network | ||
* Subnet | ||
* Router | ||
* Router Interface | ||
* Loadbalancer | ||
* Templates | ||
* Instances | ||
* Security Group (Allow ICMP, 80/tcp, 22/tcp) | ||
* Volumes | ||
* EIP | ||
* Loadbalancer | ||
* Backup Policies and Backups | ||
|
||
## Usage | ||
|
||
## Resource Creation | ||
This example will, by default not create Volumes. This is to show how to enable resources via parameters. | ||
To enable Volume creation, set the **disk__size_gb** variable to a value > 10. | ||
|
||
This example will, by default not create Volumes. This is to show how to enable resources via parameters. To enable Volume creation, set the **disk__size_gb** variable to a value > 10. | ||
Add your variables to a file called **terraform.tfvars** or set them as environment variables. | ||
|
||
```shell | ||
export TF_VAR_access_key=your_access_key | ||
export TF_VAR_secret_key=your_secret_key | ||
export TF_VAR_domain_name=your_domain_name | ||
``` | ||
|
||
Then run the following commands: | ||
|
||
```shell | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
Observe the output of the apply command, it will show you the external IP address of the loadbalancer. | ||
|
||
## Destroy | ||
|
||
```shell | ||
terraform destroy | ||
``` | ||
|
||
You can encounter an error when destroying the bucket, this is because the bucket is not empty. You can delet | ||
e the objects manually in the console and run the destroy command again. | ||
|
||
## Available Variables | ||
|
||
### Required | ||
|
||
* **username** (your flexibleengine username) | ||
* **password** (your flexibleengine password) | ||
* **access_key** (your flexibleengine access_key) | ||
* **secret_key** (your flexibleengine secret_key) | ||
* **domain_name** (your flexibleengine domain name) | ||
* You must have a **ssh_pub_key** file defined, or terraform will complain, see default path below. | ||
|
||
### Optional | ||
* **project** (this will prefix all your resources, _default=terraform_) | ||
* **ssh_pub_key** (the path to the ssh public key you want to deploy, _default=~/.ssh/id_rsa.pub_) | ||
* **instance_count** (affects the number of Floating IPs, Instances, Volumes and Ports, _default=1_) | ||
* **flavor_name** (flavor of the created instances, _default=s1.medium_) | ||
* **image_name** (image used for creating instances, _default=Standard_CentOS_7_latest_) | ||
* **disk_size_gb** (size of the volumes in gigabytes, _default=None_) | ||
|
||
* **project** (this will prefix all your resources, *default=terraform*) | ||
* **ssh_pub_key** (the path to the ssh public key you want to deploy, *default=~/.ssh/id_rsa.pub*) | ||
* **instance_count** (affects the number of Floating IPs, Instances, Volumes and Ports, *default=1*) | ||
* **flavor_name** (flavor of the created instances, *default=s6.medium.2*) | ||
* **image_name** (image used for creating instances, *default=OBS Ubuntu 22.04*) | ||
* **disk_size_gb** (size of the volumes in gigabytes, *default=None*) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
resource "flexibleengine_vpc_eip_v1" "eip_1" { | ||
resource "flexibleengine_vpc_eip" "eip_1" { | ||
publicip { | ||
type = "5_bgp" | ||
} | ||
bandwidth { | ||
name = "test" | ||
size = 8 | ||
share_type = "PER" | ||
name = "test" | ||
size = 8 | ||
share_type = "PER" | ||
charge_mode = "traffic" | ||
} | ||
} | ||
|
||
resource "flexibleengine_vpc_eip_associate" "associated" { | ||
public_ip = flexibleengine_vpc_eip.eip_1.address | ||
fixed_ip = flexibleengine_lb_loadbalancer_v2.loadbalancer.vip_address | ||
network_id = flexibleengine_vpc_subnet_v1.subnet.id | ||
} | ||
|
||
resource "flexibleengine_antiddos_v1" "antiddos_1" { | ||
floating_ip_id = "${flexibleengine_vpc_eip_v1.eip_1.id}" | ||
enable_l7 = true | ||
traffic_pos_id = 1 | ||
http_request_pos_id = 2 | ||
floating_ip_id = flexibleengine_vpc_eip.eip_1.id | ||
enable_l7 = true | ||
traffic_pos_id = 1 | ||
http_request_pos_id = 2 | ||
cleaning_access_pos_id = 1 | ||
app_type_id = 0 | ||
} | ||
app_type_id = 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
resource "flexibleengine_csbs_backup_v1" "backup_v1" { | ||
backup_name = "${var.project}-backup" | ||
resource_id = "${flexibleengine_compute_instance_v2.webserver.id}" | ||
resource_type = "OS::Nova::Server" | ||
} | ||
# resource "flexibleengine_csbs_backup_v1" "backup_v1" { | ||
# count = var.instance_count | ||
# backup_name = "${var.project}-${flexibleengine_compute_instance_v2.webserver.*.name[count.index]}-backup" | ||
# resource_id = flexibleengine_compute_instance_v2.webserver.*.id[count.index] | ||
# resource_type = "OS::Nova::Server" | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
resource "flexibleengine_csbs_backup_policy_v1" "backup_policy_v1" { | ||
name = "${var.project}-policy" | ||
resource { | ||
id = "${flexibleengine_compute_instance_v2.webserver.id}" | ||
type = "OS::Nova::Server" | ||
name = "resource1" | ||
name = "${var.project}-csbs-policy" | ||
dynamic "resource" { | ||
for_each = flexibleengine_compute_instance_v2.webserver.*.id | ||
content { | ||
id = resource.value | ||
type = "OS::Nova::Server" | ||
name = flexibleengine_compute_instance_v2.webserver.*.name[resource.key] | ||
} | ||
} | ||
|
||
scheduled_operation { | ||
name = "mybackup" | ||
enabled = true | ||
description = "My backup policy" | ||
operation_type = "backup" | ||
max_backups = 2 | ||
trigger_pattern = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nRRULE:FREQ=WEEKLY;BYDAY=TH;BYHOUR=12;BYMINUTE=27\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" | ||
name = "mybackup" | ||
enabled = true | ||
description = "My backup policy" | ||
operation_type = "backup" | ||
max_backups = 2 | ||
trigger_pattern = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nRRULE:FREQ=WEEKLY;BYDAY=TH;BYHOUR=12;BYMINUTE=27\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
resource "random_string" "bucket" { | ||
length = 16 | ||
upper = false | ||
override_special = "-" | ||
} | ||
|
||
resource "flexibleengine_s3_bucket" "bucket" { | ||
bucket = "tf-test-bucket" | ||
acl = "public-read" | ||
bucket = "${var.project}-${random_string.bucket.result}-bucket" | ||
acl = "public-read" | ||
} | ||
|
||
resource "flexibleengine_smn_topic_v2" "topic_1" { | ||
name = "topic_check" | ||
display_name = "The display name of topic_1" | ||
name = "topic_check" | ||
display_name = "The display name of topic_1" | ||
} | ||
|
||
resource "flexibleengine_cts_tracker_v1" "tracker_v1" { | ||
bucket_name = "${flexibleengine_s3_bucket.bucket.bucket}" | ||
file_prefix_name = "yO8Q" | ||
is_support_smn = true | ||
topic_id = "${flexibleengine_smn_topic_v2.topic_1.id}" | ||
is_send_all_key_operation = false | ||
operations = ["delete","create","login"] | ||
need_notify_user_list = ["user1"] | ||
} | ||
bucket_name = flexibleengine_s3_bucket.bucket.bucket | ||
file_prefix_name = "yO8Q" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
resource "flexibleengine_compute_instance_v2" "webserver" { | ||
count = "${var.instance_count}" | ||
name = "${var.project}-webserver${format("%02d", count.index+1)}" | ||
image_name = "${var.image_name}" | ||
flavor_name = "${var.flavor_name}" | ||
key_pair = "${flexibleengine_compute_keypair_v2.keypair.name}" | ||
count = var.instance_count | ||
name = "${var.project}-webserver${format("%02d", count.index + 1)}" | ||
image_name = var.image_name | ||
flavor_name = var.flavor_name | ||
key_pair = flexibleengine_compute_keypair_v2.keypair.name | ||
user_data = "#cloud-config\npackage_update: true\npackages: ['nginx-light']\n" | ||
security_groups = [ | ||
"${flexibleengine_compute_secgroup_v2.secgrp_web.name}" | ||
"${flexibleengine_networking_secgroup_v2.secgrp_web.name}" | ||
] | ||
|
||
network { | ||
uuid = "${flexibleengine_networking_network_v2.network.id}" | ||
uuid = flexibleengine_vpc_subnet_v1.subnet.id | ||
} | ||
} | ||
|
||
resource "flexibleengine_compute_volume_attach_v2" "volume_attach" { | ||
count = "${var.disk_size_gb > 0 ? var.instance_count : 0}" | ||
instance_id = "${element(flexibleengine_compute_instance_v2.webserver.*.id, count.index)}" | ||
volume_id = "${element(flexibleengine_blockstorage_volume_v2.volume.*.id, count.index)}" | ||
count = var.disk_size_gb > 0 ? var.instance_count : 0 | ||
instance_id = element(flexibleengine_compute_instance_v2.webserver.*.id, count.index) | ||
volume_id = element(flexibleengine_blockstorage_volume_v2.volume.*.id, count.index) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
resource "flexibleengine_compute_keypair_v2" "keypair" { | ||
count = "${var.instance_count}" | ||
name = "${var.project}-terraform_key" | ||
public_key = "${file("${var.ssh_pub_key}")}" | ||
public_key = file("${var.ssh_pub_key}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
resource "flexibleengine_networking_network_v2" "network" { | ||
count = "${var.instance_count}" | ||
name = "${var.project}-network" | ||
admin_state_up = "true" | ||
resource "flexibleengine_vpc_v1" "vpc" { | ||
name = "${var.project}-vpc" | ||
cidr = var.vpc_cidr | ||
} | ||
|
||
resource "flexibleengine_networking_subnet_v2" "subnet" { | ||
name = "${var.project}-subnet" | ||
count = "${var.instance_count}" | ||
network_id = "${flexibleengine_networking_network_v2.network.id}" | ||
cidr = "${var.subnet_cidr}" | ||
ip_version = 4 | ||
dns_nameservers = ["8.8.8.8", "8.8.4.4"] | ||
resource "flexibleengine_vpc_subnet_v1" "subnet" { | ||
name = "${var.project}-subnet" | ||
cidr = var.subnet_cidr | ||
gateway_ip = var.gateway_ip | ||
vpc_id = flexibleengine_vpc_v1.vpc.id | ||
dns_list = ["1.1.1.1", "9.9.9.9"] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "webserver_url" { | ||
value = "http://${flexibleengine_vpc_eip.eip_1.address}/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
terraform { | ||
required_providers { | ||
flexibleengine = { | ||
source = "FlexibleEngineCloud/flexibleengine" | ||
version = "1.35.1" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
} | ||
} | ||
} | ||
|
||
|
||
provider "random" {} | ||
|
||
provider "flexibleengine" { | ||
user_name = "${var.username}" | ||
password = "${var.password}" | ||
tenant_name = "${var.tenant_name}" | ||
domain_name = "${var.domain_name}" | ||
auth_url = "${var.endpoint}" | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
tenant_name = var.tenant_name | ||
domain_name = var.domain_name | ||
region = var.region | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.