Skip to content

Commit ec31e3c

Browse files
committed
examples/complete: improve the examples
1 parent 96e749a commit ec31e3c

File tree

7 files changed

+50
-62
lines changed

7 files changed

+50
-62
lines changed

examples/complete/main.tf

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ data "alicloud_zones" "default" {
22
}
33

44
data "alicloud_instance_types" "this" {
5-
cpu_core_count = 2
6-
memory_size = 4
7-
availability_zone = data.alicloud_zones.default.zones.0.id
5+
cpu_core_count = 2
6+
memory_size = 8
7+
instance_type_family = "ecs.g6"
8+
availability_zone = data.alicloud_zones.default.zones[0].id
89
}
910

1011
data "alicloud_images" "ubuntu" {
@@ -13,36 +14,41 @@ data "alicloud_images" "ubuntu" {
1314

1415
# Create a new vpc used to create ecs instance
1516
module "vpc" {
16-
source = "alibaba/vpc/alicloud"
17+
source = "alibaba/vpc/alicloud"
18+
version = "~> 1.11"
19+
1720
create = true
1821
vpc_cidr = "172.16.0.0/16"
1922
vswitch_cidrs = ["172.16.0.0/21"]
20-
availability_zones = [data.alicloud_zones.default.zones.0.id]
23+
availability_zones = [data.alicloud_zones.default.zones[0].id]
2124
}
2225

2326
# Create a new security group used to create ecs instance
2427
module "sg" {
25-
source = "alibaba/security-group/alicloud"
28+
source = "alibaba/security-group/alicloud"
29+
version = "~> 2.4"
30+
2631
vpc_id = module.vpc.this_vpc_id
2732
ingress_cidr_blocks = ["0.0.0.0/0"]
2833
ingress_rules = ["all-all"]
2934
}
3035

3136
# Create log service by sls module
3237
module "sls" {
33-
source = "terraform-alicloud-modules/sls/alicloud"
38+
source = "terraform-alicloud-modules/sls/alicloud"
39+
version = "~> 1.2"
3440
}
3541

36-
//ecs-instance
42+
#ecs-instance
3743
module "ecs" {
3844
source = "../.."
3945

40-
//ecs-instance
46+
#ecs-instance
4147
create_instance = true
4248

4349
number_of_instance = 1
44-
image_id = data.alicloud_images.ubuntu.ids.0
45-
instance_type = data.alicloud_instance_types.this.ids.0
50+
image_id = data.alicloud_images.ubuntu.ids[0]
51+
instance_type = data.alicloud_instance_types.this.ids[0]
4652
use_num_suffix = true
4753
security_groups = [module.sg.this_security_group_id]
4854
vswitch_id = module.vpc.this_vswitch_ids[0]
@@ -51,28 +57,28 @@ module "ecs" {
5157
internet_max_bandwidth_out = var.internet_max_bandwidth_out
5258
tags = var.tags
5359

54-
//sls-logtail
60+
#sls-logtail
5561
create_log_service = false
5662

5763
}
5864

59-
//sls-logtail
65+
#sls-logtail
6066
module "logtail" {
6167
source = "../.."
6268

63-
//ecs-instance
69+
#ecs-instance
6470
create_instance = false
6571

66-
//sls-logtail
72+
#sls-logtail
6773
create_log_service = true
6874

69-
//alicloud_log_machine_group
75+
#alicloud_log_machine_group
7076
existing_instance_private_ips = ["172.16.2.2", "172.16.2.3"]
7177
log_machine_group_name = "tf-log-machine-group-name"
7278
project_name = module.sls.this_log_project_name
7379
log_machine_topic = var.log_machine_topic
7480

75-
//alicloud_logtail_config
81+
#alicloud_logtail_config
7682
config_input_detail = var.config_input_detail
7783
config_input_type = var.config_input_type
7884
logstore_name = module.sls.this_log_store_name

examples/complete/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// instances variables
1+
# instances variables
22
variable "instance_password" {
33
description = "Password to an instance is a string of 8 to 30 characters. It must contain uppercase/lowercase letters and numerals, but cannot contain special symbols. When it is changed, the instance will reboot to make the change take effect."
44
type = string
@@ -19,14 +19,14 @@ variable "tags" {
1919
}
2020
}
2121

22-
// log machine group variables
22+
# log machine group variables
2323
variable "log_machine_topic" {
2424
description = "The topic of a machine group."
2525
type = string
2626
default = "tf-log-machine-topic"
2727
}
2828

29-
// logtail config variables
29+
# logtail config variables
3030
variable "config_input_detail" {
3131
description = "The logtail configure the required JSON files, this parameter is required if you will use this module to create logtail config. ([Refer to details](https://www.alibabacloud.com/help/doc-detail/29058.htm))"
3232
type = string

examples/complete/versions.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
terraform {
2+
required_version = ">= 0.13"
3+
}

locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
user_data = <<EOF
33
#!/bin/sh
4-
wget http://logtail-release-${data.alicloud_regions.this.ids.0}.oss-${data.alicloud_regions.this.ids.0}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install ${data.alicloud_regions.this.ids.0}
4+
wget http://logtail-release-${data.alicloud_regions.this.ids[0]}.oss-${data.alicloud_regions.this.ids[0]}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install ${data.alicloud_regions.this.ids[0]}
55
touch /etc/ilogtail/users/${data.alicloud_account.this.id}
66
EOF
77
random_string = replace(random_uuid.this.result, "-", "")

main.tf

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Create the ECS instances to install logtail
1+
# Create the ECS instances to install logtail
22
module "instances" {
3-
source = "alibaba/ecs-instance/alicloud"
3+
source = "alibaba/ecs-instance/alicloud"
4+
version = "2.12.0"
45

56
number_of_instances = var.create_instance ? var.number_of_instance : 0
67
image_id = var.image_id
@@ -21,6 +22,7 @@ resource "alicloud_log_machine_group" "this" {
2122
name = var.log_machine_group_name == "" ? local.log_machine_group_name : var.log_machine_group_name
2223
project = var.project_name
2324
topic = var.log_machine_topic
25+
identify_type = var.log_machine_identify_type
2426
}
2527

2628
resource "alicloud_logtail_config" "this" {
@@ -37,6 +39,6 @@ resource "alicloud_logtail_config" "this" {
3739
resource "alicloud_logtail_attachment" "this" {
3840
count = var.create_log_service ? 1 : 0
3941
project = var.project_name
40-
logtail_config_name = concat(alicloud_logtail_config.this.*.name, [""])[0]
41-
machine_group_name = concat(alicloud_log_machine_group.this.*.name, [""])[0]
42-
}
42+
logtail_config_name = concat(alicloud_logtail_config.this[*].name, [""])[0]
43+
machine_group_name = concat(alicloud_log_machine_group.this[*].name, [""])[0]
44+
}

outputs.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,50 @@ output "this_instance_name" {
1010

1111
output "this_log_project_name" {
1212
description = "The name of the log project"
13-
value = concat(alicloud_logtail_config.this.*.project, [""])[0]
13+
value = concat(alicloud_logtail_config.this[*].project, [""])[0]
1414
}
1515

1616
output "this_log_store_name" {
1717
description = "The name of the log store"
18-
value = concat(alicloud_logtail_config.this.*.logstore, [""])[0]
18+
value = concat(alicloud_logtail_config.this[*].logstore, [""])[0]
1919
}
2020

2121
output "this_log_machine_group_name" {
2222
description = "The name of the log machine group"
23-
value = concat(alicloud_log_machine_group.this.*.name, [""])[0]
23+
value = concat(alicloud_log_machine_group.this[*].name, [""])[0]
2424
}
2525

2626
output "this_log_machine_group_identify_type" {
2727
description = "The identify type of the log machine group"
28-
value = concat(alicloud_log_machine_group.this.*.identify_type, [""])[0]
28+
value = concat(alicloud_log_machine_group.this[*].identify_type, [""])[0]
2929
}
3030

3131
output "this_log_machine_group_topic" {
3232
description = "The topic of the log machine group"
33-
value = concat(alicloud_log_machine_group.this.*.topic, [""])[0]
33+
value = concat(alicloud_log_machine_group.this[*].topic, [""])[0]
3434
}
3535

3636
output "this_log_machine_group_identify_list" {
3737
description = "The identify list of the log machine group"
38-
value = concat(alicloud_log_machine_group.this.*.identify_list, [[]])[0]
38+
value = concat(alicloud_log_machine_group.this[*].identify_list, [[]])[0]
3939
}
4040

4141
output "this_logtail_config_name" {
4242
description = "The name of the logtail config"
43-
value = concat(alicloud_logtail_config.this.*.name, [""])[0]
43+
value = concat(alicloud_logtail_config.this[*].name, [""])[0]
4444
}
4545

4646
output "this_logtail_config_input_type" {
4747
description = "The input type of the logtail config"
48-
value = concat(alicloud_logtail_config.this.*.input_type, [""])[0]
48+
value = concat(alicloud_logtail_config.this[*].input_type, [""])[0]
4949
}
5050

5151
output "this_logtail_config_log_sample" {
5252
description = "The log sample of the logtail config"
53-
value = concat(alicloud_logtail_config.this.*.log_sample, [""])[0]
53+
value = concat(alicloud_logtail_config.this[*].log_sample, [""])[0]
5454
}
5555

5656
output "this_logtail_config_input_detail" {
5757
description = "The input detail of the logtail config"
58-
value = concat(alicloud_logtail_config.this.*.input_detail, [""])[0]
58+
value = concat(alicloud_logtail_config.this[*].input_detail, [""])[0]
5959
}

variables.tf

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
1-
variable "region" {
2-
description = "(Deprecated from version 1.1.0) The region used to launch this module resources."
3-
type = string
4-
default = ""
5-
}
6-
7-
variable "profile" {
8-
description = "(Deprecated from version 1.1.0) The profile name as set in the shared credentials file. If not set, it will be sourced from the ALICLOUD_PROFILE environment variable."
9-
type = string
10-
default = ""
11-
}
12-
13-
variable "shared_credentials_file" {
14-
description = "(Deprecated from version 1.1.0) This is the path to the shared credentials file. If this is not set and a profile is specified, $HOME/.aliyun/config.json will be used."
15-
type = string
16-
default = ""
17-
}
18-
19-
variable "skip_region_validation" {
20-
description = "(Deprecated from version 1.1.0) Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet)."
21-
type = bool
22-
default = false
23-
}
241

25-
// instances variables
2+
# instances variables
263
variable "create_instance" {
274
description = "Whether to create ECS instances"
285
type = bool
@@ -89,7 +66,7 @@ variable "tags" {
8966
default = {}
9067
}
9168

92-
// log machine group variables
69+
# log machine group variables
9370
variable "create_log_service" {
9471
description = "Whether to create log resources. If true, a new machine group and logtail config will be created and associate them."
9572
type = bool
@@ -120,7 +97,7 @@ variable "log_machine_topic" {
12097
default = ""
12198
}
12299

123-
// logtail config variables
100+
# logtail config variables
124101
variable "config_input_detail" {
125102
description = "The logtail configure the required JSON files, this parameter is required if you will use this module to create logtail config. ([Refer to details](https://www.alibabacloud.com/help/doc-detail/29058.htm))"
126103
type = string

0 commit comments

Comments
 (0)