Skip to content

Commit 8071d1d

Browse files
lsy1968shanye997
authored andcommitted
Enable software key management
1 parent c50c001 commit 8071d1d

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于在阿里云上购买并启用KMS软件密钥管理实例。
5+
详情可查看[通过Terraform购买并启用软件密钥管理实例](http://help.aliyun.com/document_detail/2572877.htm)
6+
<!-- DOCS_DESCRIPTION_CN -->
7+
8+
<!-- DOCS_DESCRIPTION_EN -->
9+
This example is used to purchase and enable an instance of the software key management type on Alibaba Cloud.
10+
More details in [Purchase and enable an instance of the software key management type](http://help.aliyun.com/document_detail/2572877.htm).
11+
<!-- DOCS_DESCRIPTION_EN -->
12+
13+
<!-- BEGIN_TF_DOCS -->
14+
## Providers
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
19+
| <a name="provider_local"></a> [local](#provider\_local) | n/a |
20+
21+
## Modules
22+
23+
No modules.
24+
25+
## Resources
26+
27+
| Name | Type |
28+
|------|------|
29+
| [alicloud_kms_instance.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/kms_instance) | resource |
30+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
31+
| [alicloud_vswitch.vsw](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
32+
| [alicloud_vswitch.vsw1](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
33+
| [local_file.ca_certificate_chain_pem](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
34+
| [alicloud_zones.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/zones) | data source |
35+
36+
## Inputs
37+
38+
| Name | Description | Type | Default | Required |
39+
|------|-------------|------|---------|:--------:|
40+
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | n/a | `string` | `"tff-kms-vpc-172-16"` | no |
41+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | n/a | `string` | `"ecs.n1.tiny"` | no |
42+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"cn-shanghai"` | no |
43+
<!-- END_TF_DOCS -->
44+
## Documentation
45+
<!-- docs-link -->
46+
47+
The template is based on Aliyun document: [Enable software key management](http://help.aliyun.com/document_detail/2572877.htm)
48+
49+
<!-- docs-link -->
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
variable "region" {
2+
default = "cn-shanghai"
3+
}
4+
5+
provider "alicloud" {
6+
region = var.region
7+
}
8+
variable "instance_name" {
9+
default = "tff-kms-vpc-172-16"
10+
}
11+
12+
variable "instance_type" {
13+
default = "ecs.n1.tiny"
14+
}
15+
# 使用数据源来获取可用的可用区信息。资源只能在指定的可用区内创建。
16+
data "alicloud_zones" "default" {
17+
available_disk_category = "cloud_efficiency"
18+
available_resource_creation = "VSwitch"
19+
available_instance_type = var.instance_type
20+
}
21+
# 创建VPC
22+
resource "alicloud_vpc" "vpc" {
23+
vpc_name = var.instance_name
24+
cidr_block = "172.16.0.0/12"
25+
}
26+
# 创建一个Vswitch CIDR 块为 172.16.0.0/12
27+
resource "alicloud_vswitch" "vsw" {
28+
vpc_id = alicloud_vpc.vpc.id
29+
cidr_block = "172.16.0.0/21"
30+
zone_id = data.alicloud_zones.default.zones.0.id
31+
vswitch_name = "terraform-example-1"
32+
}
33+
# 创建另一个Vswitch CIDR 块为 172.16.128.0/17
34+
resource "alicloud_vswitch" "vsw1" {
35+
vpc_id = alicloud_vpc.vpc.id
36+
cidr_block = "172.16.128.0/17"
37+
zone_id = data.alicloud_zones.default.zones.0.id
38+
vswitch_name = "terraform-example-2"
39+
}
40+
# 创建KMS软件密钥管理实例,并使用网络参数启动
41+
resource "alicloud_kms_instance" "default" {
42+
# 软件密钥管理实例
43+
product_version = "3"
44+
vpc_id = alicloud_vpc.vpc.id
45+
# 规定 KMS 实例所在的可用区,使用前面获取的可用区 ID
46+
zone_ids = [
47+
data.alicloud_zones.default.zones.0.id,
48+
data.alicloud_zones.default.zones.1.id
49+
]
50+
# 交换机id
51+
vswitch_ids = [
52+
alicloud_vswitch.vsw.id, alicloud_vswitch.vsw1.id
53+
]
54+
# 计算性能、密钥数量、凭据数量、访问管理数量
55+
vpc_num = "1"
56+
key_num = "1000"
57+
secret_num = "100"
58+
spec = "1000"
59+
# 为KMS实例关联其他VPC
60+
# 如果VPC与KMS实例的VPC属于不同阿里云账号,您需要先共享交换机。
61+
#bind_vpcs {
62+
#vpc_id = "vpc-j6cy0l32yz9ttxfy6****"
63+
#vswitch_id = "vsw-j6cv7rd1nz8x13ram****"
64+
#region_id = "cn-shanghai"
65+
#vpc_owner_id = "119285303511****"
66+
#}
67+
#bind_vpcs {
68+
#vpc_id = "vpc-j6cy0l32yz9ttd7g3****"
69+
#vswitch_id = "vsw-3h4yrd1nz8x13ram****"
70+
#region_id = "cn-shanghai"
71+
#vpc_owner_id = "119285303511****"
72+
#}
73+
}
74+
75+
# 保存KMS实例CA证书到本地文件
76+
resource "local_file" "ca_certificate_chain_pem" {
77+
content = alicloud_kms_instance.default.ca_certificate_chain_pem
78+
filename = "ca.pem"
79+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
alicloud = {
4+
source = "aliyun/alicloud"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)