Skip to content

Commit 094663a

Browse files
MrWolongxiaozhu36
authored andcommitted
Improves the module examples/complete
1 parent ebc0efb commit 094663a

File tree

15 files changed

+500
-98
lines changed

15 files changed

+500
-98
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# used for testing
2-
*.tfvars
3-
41
# Compiled files
52
*.tfstate
63
*.tfstate.backup
4+
*.terraform.*
75

86
# Module directory
97
.terraform/
@@ -21,4 +19,6 @@
2119
# others
2220
*.bak
2321
*.bk
24-
22+
**/.terraform/*
23+
.terraform.lock.hcl
24+
.terraform.tfstate.lock.info

README-CN.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
terraform-alicloud-ecs-instance
22
=====================================================================
33

4-
54
本 Module 用于在阿里云的 VPC 下创建一个[云服务器ECS实例(ECS Instance)](https://www.alibabacloud.com/help/zh/doc-detail/25374.htm).
65

76
本 Module 支持创建以下资源:
@@ -61,7 +60,7 @@ module "ecs_cluster" {
6160
* [x86计算内存型实例创建示例](https://github.com/terraform-alicloud-modules/terraform-alicloud-ecs-instance/tree/master/examples/x86-architecture/memory-optimized)
6261

6362
## 注意事项
64-
本Module从版本v2.8.0开始已经移除掉如下的 provider 的显示设置
63+
本Module从版本v2.8.0开始已经移除掉如下的 provider 的显式设置
6564

6665
```hcl
6766
provider "alicloud" {
@@ -87,7 +86,7 @@ module "ecs_cluster" {
8786
}
8887
```
8988

90-
如果你想对正在使用中的Module升级到 2.8.0 或者更高的版本,那么你可以在模板中显示定义一个相同Region的provider
89+
如果你想对正在使用中的Module升级到 2.8.0 或者更高的版本,那么你可以在模板中显式定义一个相同Region的provider
9190
```hcl
9291
provider "alicloud" {
9392
region = "cn-beijing"
@@ -100,7 +99,7 @@ module "ecs_cluster" {
10099
// ...
101100
}
102101
```
103-
或者,如果你是多Region部署,你可以利用 `alias` 定义多个 provider,并在Module中显示指定这个provider
102+
或者,如果你是多Region部署,你可以利用 `alias` 定义多个 provider,并在Module中显式指定这个provider
104103

105104
```hcl
106105
provider "alicloud" {
@@ -127,7 +126,7 @@ module "ecs_cluster" {
127126

128127
| Name | Version |
129128
|------|---------|
130-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
129+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
131130
| <a name="requirement_alicloud"></a> [alicloud](#requirement\_alicloud) | >= 1.56.0 |
132131

133132
提交问题
@@ -148,6 +147,4 @@ Apache 2 Licensed. See LICENSE for full details.
148147
---------
149148
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
150149
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
151-
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
152-
153-
150+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Alicloud ECS Instance Terraform Module In VPC
22
terraform-alicloud-ecs-instance
33

4-
54
English | [简体中文](https://github.com/terraform-alicloud-modules/terraform-alicloud-ecs-instance/blob/master/README-CN.md)
65

76
Terraform module which creates ECS instance(s) on Alibaba Cloud.
@@ -131,7 +130,7 @@ More details see [How to use provider in the module](https://www.terraform.io/do
131130

132131
| Name | Version |
133132
|------|---------|
134-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.12.0 |
133+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
135134
| <a name="requirement_alicloud"></a> [alicloud](#requirement\_alicloud) | >= 1.56.0 |
136135

137136
Submit Issues
@@ -152,6 +151,4 @@ Reference
152151
---------
153152
* [Terraform-Provider-Alicloud Github](https://github.com/terraform-providers/terraform-provider-alicloud)
154153
* [Terraform-Provider-Alicloud Release](https://releases.hashicorp.com/terraform-provider-alicloud/)
155-
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)
156-
157-
154+
* [Terraform-Provider-Alicloud Docs](https://www.terraform.io/docs/providers/alicloud/index.html)

examples/complete/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Complete
2+
3+
Configuration in this directory creates ECS instance(s).
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
This example provides the tf variables file in the folder `tfvars`. If you want to create or update this example,
18+
you can run this example as the following commands:
19+
```bash
20+
$ terraform plan -var-file=tfvars/01-update.tfvars
21+
$ terraform apply -var-file=tfvars/01-update.tfvars
22+
```
23+
24+
Also, you can add more variables files in the folder `tfvars`.
25+
26+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
27+
## Requirements
28+
29+
| Name | Version |
30+
|------|---------|
31+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
32+
| <a name="requirement_alicloud"></a> [alicloud](#requirement\_alicloud) | >= 1.56.0 |

examples/complete/main.tf

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
data "alicloud_zones" "default" {
2+
}
3+
4+
data "alicloud_resource_manager_resource_groups" "default" {
5+
}
6+
7+
data "alicloud_images" "default" {
8+
name_regex = "^centos_6"
9+
owners = "system"
10+
}
11+
12+
data "alicloud_instance_types" "default" {
13+
availability_zone = data.alicloud_zones.default.zones.0.id
14+
}
15+
16+
data "alicloud_ecs_auto_snapshot_policies" "default" {
17+
}
18+
19+
resource "alicloud_ecs_disk" "default" {
20+
zone_id = data.alicloud_zones.default.zones.0.id
21+
size = var.system_disk_size
22+
}
23+
24+
resource "alicloud_ecs_snapshot" "default" {
25+
disk_id = alicloud_ecs_disk_attachment.default.disk_id
26+
category = "standard"
27+
force = var.force_delete
28+
}
29+
30+
resource "alicloud_ecs_disk_attachment" "default" {
31+
disk_id = alicloud_ecs_disk.default.id
32+
instance_id = module.ecs_instance.this_instance_id[0]
33+
}
34+
35+
resource "alicloud_ecs_key_pair" "default" {
36+
key_pair_name = "key_pair_name_2022"
37+
}
38+
39+
resource "alicloud_ram_role" "default" {
40+
name = "tf-ram-name-2022"
41+
document = var.document
42+
}
43+
44+
resource "alicloud_kms_key" "kms" {
45+
key_usage = "ENCRYPT/DECRYPT"
46+
pending_window_in_days = var.pending_window_in_days
47+
status = "Enabled"
48+
}
49+
50+
resource "alicloud_kms_ciphertext" "kms" {
51+
plaintext = "test"
52+
key_id = alicloud_kms_key.kms.id
53+
encryption_context = {
54+
test = "test"
55+
}
56+
}
57+
58+
module "security_group" {
59+
source = "alibaba/security-group/alicloud"
60+
vpc_id = module.vpc.this_vpc_id
61+
}
62+
63+
module "vpc" {
64+
source = "alibaba/vpc/alicloud"
65+
create = true
66+
vpc_cidr = "172.16.0.0/12"
67+
vswitch_cidrs = ["172.16.0.0/21"]
68+
availability_zones = [data.alicloud_zones.default.zones.0.id]
69+
}
70+
71+
module "ecs_instance" {
72+
source = "../.."
73+
74+
number_of_instances = 1
75+
76+
instance_type = data.alicloud_instance_types.default.instance_types.0.id
77+
image_id = data.alicloud_images.default.images.0.id
78+
vswitch_ids = [module.vpc.this_vswitch_ids[0]]
79+
security_group_ids = [module.security_group.this_security_group_id]
80+
description = var.description
81+
}
82+
83+
module "example" {
84+
source = "../.."
85+
86+
number_of_instances = 1
87+
88+
image_id = data.alicloud_images.default.images.0.id
89+
image_ids = data.alicloud_images.default.ids
90+
instance_type = data.alicloud_instance_types.default.instance_types.0.id
91+
security_group_ids = [module.security_group.this_security_group_id]
92+
vswitch_id = module.vpc.this_vswitch_ids[0]
93+
vswitch_ids = module.vpc.this_vswitch_ids
94+
private_ip = var.private_ip
95+
private_ips = var.private_ips
96+
name = var.name
97+
use_num_suffix = true
98+
host_name = var.host_name
99+
resource_group_id = data.alicloud_resource_manager_resource_groups.default.groups.0.id
100+
description = var.description
101+
internet_charge_type = var.internet_charge_type
102+
password = var.password
103+
kms_encrypted_password = var.kms_encrypted_password
104+
kms_encryption_context = alicloud_kms_ciphertext.kms.encryption_context
105+
system_disk_category = "cloud_efficiency"
106+
system_disk_size = var.system_disk_size
107+
system_disk_auto_snapshot_policy_id = data.alicloud_ecs_auto_snapshot_policies.default.policies.0.id
108+
data_disks = [
109+
{
110+
name = "data_disks_name"
111+
size = "20"
112+
category = "cloud_ssd"
113+
encrypted = false
114+
snapshot_id = alicloud_ecs_snapshot.default.id
115+
delete_with_instance = true
116+
description = "tf-description"
117+
auto_snapshot_policy_id = data.alicloud_ecs_auto_snapshot_policies.default.policies.0.id
118+
}
119+
]
120+
associate_public_ip_address = true
121+
internet_max_bandwidth_out = var.internet_max_bandwidth_out
122+
instance_charge_type = var.instance_charge_type
123+
subscription = var.subscription
124+
dry_run = var.dry_run
125+
user_data = var.user_data
126+
role_name = alicloud_ram_role.default.id
127+
key_name = alicloud_ecs_key_pair.default.id
128+
deletion_protection = var.deletion_protection
129+
force_delete = var.force_delete
130+
security_enhancement_strategy = "Active"
131+
credit_specification = null
132+
spot_strategy = "NoSpot"
133+
spot_price_limit = 0
134+
tags = var.tags
135+
volume_tags = var.volume_tags
136+
137+
}

examples/complete/outputs.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Output the IDs of the ECS instances created
2+
output "this_instance_id" {
3+
value = module.example.this_instance_id
4+
}
5+
6+
output "this_instance_name" {
7+
value = module.example.this_instance_name
8+
}
9+
10+
output "this_instance_type" {
11+
value = module.example.this_instance_type
12+
}
13+
14+
output "this_image_id" {
15+
value = module.example.this_image_id
16+
}
17+
18+
output "this_instance_tags" {
19+
value = module.example.this_instance_tags
20+
}
21+
22+
output "this_private_ip" {
23+
value = module.example.this_private_ip
24+
}
25+
26+
output "this_public_ip" {
27+
value = module.example.this_public_ip
28+
}
29+
30+
output "this_availability_zone" {
31+
value = module.example.this_availability_zone
32+
}
33+
34+
# VSwitch ID
35+
output "this_vswitch_id" {
36+
value = module.example.this_vswitch_id
37+
}
38+
39+
# Security Group outputs
40+
output "this_security_group_ids" {
41+
value = module.example.this_security_group_ids
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#alicloud_kms_key
2+
pending_window_in_days = 7
3+
4+
#alicloud_ram_role
5+
document = <<EOF
6+
{
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": [
13+
"ecs.aliyuncs.com"
14+
]
15+
}
16+
}
17+
],
18+
"Version": "1"
19+
}
20+
EOF
21+
22+
# Ecs instance variables
23+
private_ip = "172.16.0.12"
24+
private_ips = ["172.16.0.12"]
25+
name = "update-tf-testacc-name"
26+
host_name = "update-tf-testacc-host-name"
27+
description = "update-tf-testacc-description"
28+
internet_charge_type = "PayByBandwidth"
29+
password = "YourPassword123!update"
30+
kms_encrypted_password = "YourPassword123!update"
31+
system_disk_size = 50
32+
internet_max_bandwidth_out = 20
33+
subscription = {
34+
period = 1
35+
period_unit = "Week"
36+
renewal_status = "Normal"
37+
auto_renew_period = 1
38+
include_data_disks = false
39+
}
40+
dry_run = true
41+
user_data = "update-tf-user-data"
42+
deletion_protection = false
43+
force_delete = true
44+
tags = {
45+
Name = "updateECS"
46+
}
47+
volume_tags = {
48+
Name = "update-tf-testacc-ecs"
49+
}

0 commit comments

Comments
 (0)