Skip to content

Commit f901077

Browse files
committed
docs(coc/example): adjust examples under coc
1 parent a7326ce commit f901077

File tree

10 files changed

+596
-53
lines changed

10 files changed

+596
-53
lines changed

examples/coc/script/README.md

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1-
# Create COC script
1+
# Create a COC script
22

3-
In this example, we will create a COC script.
3+
This example provides best practice code for using Terraform to create a COC script in HuaweiCloud.
4+
5+
## Prerequisites
6+
7+
* A HuaweiCloud account
8+
* Terraform installed
9+
* HuaweiCloud access key and secret key (AK/SK)
10+
11+
## Required Variables
12+
13+
The following variables need to be configured:
14+
15+
### Authentication Variables
16+
17+
* `region_name` - The region where the COC script is located
18+
* `access_key` - The access key of the IAM user
19+
* `secret_key` - The secret key of the IAM user
20+
21+
### Resource Variables
22+
23+
#### Required Variables
24+
25+
* `coc_script_name` - The name of the script
26+
* `coc_script_description` - The description of the script
27+
* `coc_script_risk_level` - The risk level of the script
28+
* `coc_script_version` - The version of the script
29+
* `coc_script_type` - The type of the script
30+
* `coc_script_content` - The content of the script
31+
* `coc_script_parameters` - The parameter list of the script
32+
+ `name` - The name of the parameter
33+
+ `value` - The value of the parameter
34+
+ `description` - The description of the parameter
35+
+ `sensitive` - Whether the parameter is sensitive
36+
37+
## Usage
38+
39+
* Copy this example script to your `main.tf`.
40+
41+
* Create a `terraform.tfvars` file and fill in the required variables:
42+
43+
```hcl
44+
coc_script_name = "your_coc_script_name"
45+
coc_script_description = "your_coc_script_description"
46+
coc_script_risk_level = "your_coc_script_risk_level"
47+
coc_script_version = "your_coc_script_version"
48+
coc_script_type = "your_coc_script_type"
49+
coc_script_content = "your_coc_script_content"
50+
coc_script_parameters = "your_coc_script_parameters"
51+
```
52+
53+
* Initialize Terraform:
54+
55+
```bash
56+
$ terraform init
57+
```
58+
59+
* Review the Terraform plan:
60+
61+
```bash
62+
$ terraform plan
63+
```
64+
65+
* Apply the configuration:
66+
67+
```bash
68+
$ terraform apply
69+
```
70+
71+
* To clean up the resources:
72+
73+
```bash
74+
$ terraform destroy
75+
```
76+
77+
## Note
78+
79+
* Make sure to keep your credentials secure and never commit them to version control
80+
* All resources will be created in the specified region
81+
82+
## Requirements
83+
84+
| Name | Version |
85+
|---|---|
86+
| terraform | >= 0.12.0 |
87+
| huaweicloud | >= 1.58.0 |

examples/coc/script/main.tf

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
resource "huaweicloud_coc_script" "test" {
22
name = var.script_name
3-
description = "coc script description"
4-
risk_level = "LOW"
5-
version = "1.0.0"
6-
type = "SHELL"
3+
description = var.script_description
4+
risk_level = var.script_risk_level
5+
version = var.script_version
6+
type = var.script_type
7+
content = var.script_content
78

8-
content = <<EOF
9-
#! /bin/bash
10-
echo "hello world!"
11-
EOF
9+
dynamic "parameters" {
10+
for_each = var.script_parameters
1211

13-
parameters {
14-
name = "name"
15-
value = "world"
16-
description = "the first parameter"
17-
}
18-
parameters {
19-
name = "company"
20-
value = "Huawei"
21-
description = "the second parameter"
22-
sensitive = true
12+
content {
13+
name = parameters.value.name
14+
value = parameters.value.value
15+
description = parameters.value.description
16+
sensitive = parameters.value.sensitive
17+
}
2318
}
2419
}

examples/coc/script/providers.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
huaweicloud = {
4+
source = "huaweicloud/huaweicloud"
5+
version = ">=1.58.0"
6+
}
7+
}
8+
}
9+
10+
provider "huaweicloud" {
11+
region = var.region_name
12+
access_key = var.access_key
13+
secret_key = var.secret_key
14+
}

examples/coc/script/terraform.tfvars

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
script_name = "tf_coc_script"
2+
script_description = "Created by terraform script"
3+
script_risk_level = "LOW"
4+
script_version = "1.0.0"
5+
script_type = "SHELL"
6+
script_content = <<EOF
7+
#! /bin/bash
8+
echo "hello world!"
9+
EOF
10+
script_parameters = [
11+
{
12+
name = "name"
13+
value = "world"
14+
description = "the first parameter"
15+
},
16+
{
17+
name = "company"
18+
value = "Huawei"
19+
description = "the second parameter"
20+
sensitive = true
21+
}
22+
]

examples/coc/script/variables.tf

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
1+
# Variable definitions for authentication
2+
variable "region_name" {
3+
description = "The region where the COC script is located"
4+
type = string
5+
}
6+
7+
variable "access_key" {
8+
description = "The access key of the IAM user"
9+
type = string
10+
}
11+
12+
variable "secret_key" {
13+
description = "The secret key of the IAM user"
14+
type = string
15+
}
16+
17+
# Variable definitions for resources/data sources
118
variable "script_name" {
2-
description = "The name of the COC script"
3-
default = "tf_coc_script_name"
19+
description = "The name of the script"
20+
type = string
21+
}
22+
23+
variable "script_description" {
24+
description = "The description of the script"
25+
type = string
26+
}
27+
28+
variable "script_risk_level" {
29+
description = "The risk level of the script"
30+
type = string
31+
}
32+
33+
variable "script_version" {
34+
description = "The version of the script"
35+
type = string
36+
}
37+
38+
variable "script_type" {
39+
description = "The type of the script"
40+
type = string
41+
}
42+
43+
variable "script_content" {
44+
description = "The content of the script"
45+
type = string
46+
}
47+
48+
variable "script_parameters" {
49+
description = "The parameter list of the script"
50+
type = list(object({
51+
name = string
52+
value = string
53+
description = string
54+
sensitive = optional(bool)
55+
}))
56+
57+
nullable = false
458
}
59+

examples/coc/script_execute/README.md

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,119 @@
1-
# Execute COC script
1+
# Create a COC script and execute it
22

3-
In this example, we will execute a COC script.
3+
This example provides best practice code for using Terraform to create a COC script and execute it in HuaweiCloud.
4+
5+
## Prerequisites
6+
7+
* A HuaweiCloud account
8+
* Terraform installed
9+
* HuaweiCloud access key and secret key (AK/SK)
10+
11+
## Required Variables
12+
13+
The following variables need to be configured:
14+
15+
### Authentication Variables
16+
17+
* `region_name` - The region where the COC script is located
18+
* `access_key` - The access key of the IAM user
19+
* `secret_key` - The secret key of the IAM user
20+
21+
### Resource Variables
22+
23+
#### Required Variables
24+
25+
* `vpc_name` - The name of the VPC
26+
* `subnet_name` - The name of the subnet
27+
* `security_group_name` - The name of the security group
28+
* `instance_name` - The name of the ECS instance
29+
* `instance_user_data` - The user data for installing UniAgent on the ECS instance
30+
* `script_name` - The name of the script
31+
* `script_description` - The description of the script
32+
* `script_risk_level` - The risk level of the script
33+
* `script_version` - The version of the script
34+
* `script_type` - The type of the script
35+
* `script_content` - The content of the script
36+
* `script_parameters` - The parameter list of the script.
37+
+ `name` - The name of the parameter
38+
+ `value` - The value of the parameter
39+
+ `description` - The description of the parameter
40+
+ `sensitive` - Whether the parameter is sensitive
41+
* `script_execute_timeout` - The maximum time to execute the script in seconds
42+
* `script_execute_execute_user` - The user to execute the script
43+
* `script_execute_parameters` - The parameter list of the script execution.
44+
+ `name` - The name of the parameter
45+
+ `value` - The value of the parameter
46+
47+
#### Optional Variables
48+
49+
* `availability_zone` - The availability zone to which the ECS instance and network belong (default: "")
50+
* `instance_flavor_id` - The flavor ID of the ECS instance (default: "")
51+
* `instance_flavor_performance_type` - The performance type of the ECS instance flavor (default: "normal")
52+
* `instance_flavor_cpu_core_count` - The number of the ECS instance flavor CPU cores (default: 4)
53+
* `instance_flavor_memory_size` - The memory size of the ECS instance flavor (default: 8)
54+
* `instance_image_id` - The image ID of the ECS instance (default: "")
55+
* `instance_image_os_type` - The OS type of the ECS instance flavor (default: "Ubuntu")
56+
* `instance_image_visibility` - The visibility of the ECS instance flavor (default: "public")
57+
* `vpc_cidr` - The CIDR block of the VPC (default: "192.168.0.0/16")
58+
* `subnet_cidr` - The CIDR block of the subnet (default: "")
59+
* `subnet_gateway_ip` - The gateway IP of the subnet (default: "")
60+
61+
## Usage
62+
63+
* Copy this example script to your `main.tf`.
64+
65+
* Create a `terraform.tfvars` file and fill in the required variables:
66+
67+
```hcl
68+
vpc_name = "your_vpc_name"
69+
subnet_name = "your_subnet_name"
70+
security_group_name = "your_security_group_name"
71+
instance_name = "your_instance_name"
72+
instance_user_data = "your_user_data"
73+
script_name = "your_script_name"
74+
script_description = "your_script_description"
75+
script_risk_level = "your_script_risk_level"
76+
script_version = "your_script_version"
77+
script_type = "your_script_type"
78+
script_content = "your_script_content"
79+
script_parameters = "your_script_parameters"
80+
script_execute_timeout = "your_script_execute_timeout"
81+
script_execute_execute_user = "your_script_execute_execute_user"
82+
script_execute_parameters = "your_script_execute_parameters"
83+
```
84+
85+
* Initialize Terraform:
86+
87+
```bash
88+
$ terraform init
89+
```
90+
91+
* Review the Terraform plan:
92+
93+
```bash
94+
$ terraform plan
95+
```
96+
97+
* Apply the configuration:
98+
99+
```bash
100+
$ terraform apply
101+
```
102+
103+
* To clean up the resources:
104+
105+
```bash
106+
$ terraform destroy
107+
```
108+
109+
## Note
110+
111+
* Make sure to keep your credentials secure and never commit them to version control
112+
* All resources will be created in the specified region
113+
114+
## Requirements
115+
116+
| Name | Version |
117+
|------|---------|
118+
| terraform | >= 0.12.0 |
119+
| huaweicloud | >= 1.58.0 |

0 commit comments

Comments
 (0)