Skip to content

Commit

Permalink
update tool README not to need to prepare a ssh key
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshi committed Jun 12, 2019
1 parent 6ec6036 commit 8165fe7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
35 changes: 15 additions & 20 deletions tool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,26 @@ node -v

* Terraform

You can run this application on [Alibaba cloud ECS](https://www.alibabacloud.com/help/doc-detail/25367.htm). If you want to run it on ECS, you don't have to install npm or node, but you have to install Terraform on your local machine, which is powerful tool to construct cloud infrastructure. You can install Terraform from [here](https://www.terraform.io/).
You can run this application on [Alibaba Cloud ECS](https://www.alibabacloud.com/help/doc-detail/25367.htm). If you want to run it on ECS, you don't have to install npm or node, but you have to install Terraform on your local machine, which is powerful tool to construct cloud infrastructure. You can install Terraform from [here](https://www.terraform.io/).

You can check your environment with the following command in a terminal:

```bash
terraform -version
```

Before creating the application, you need to prepare account credentials of Alibaba cloud.
Before creating the application, you need to prepare account credentials of Alibaba Cloud.

0. Create an Alibaba cloud account
1. Create an Alibaba Cloud account

You need an Alibaba cloud account. If you don't have any account, please follow
You need an Alibaba Cloud account. If you don't have any account, please follow
[this document to create one](https://www.alibabacloud.com/help/doc-detail/50482.htm).

1. Create an access key
2. Create an access key

You need an accessKeyId and an accessKeySecret to create your Alibaba cloud products by Terraform. Please follow
You need an accessKeyId and an accessKeySecret to create your Alibaba Cloud products by Terraform. Please follow
[this document to obtain an access key id and secret](https://www.alibabacloud.com/help/faq-detail/63482.htm).

2. Create a SSH key

You need a SSH key pair to access to your ECS instance by Terraform. Please follow
[this document to obtain an SSH key pair](https://www.alibabacloud.com/help/doc-detail/51793.htm). Please note the default target region of this sample is China(Qingdao).


## Usage

Expand Down Expand Up @@ -119,19 +114,19 @@ Before creating the application, you need to prepare account credentials of Alib
2. Edit the file to set your information
```sh
# Access key id of Alibaba Cloud account
# The access key id of the Alibaba Cloud account
access_key = "xxxxxxxxxxxxxxxx"
# Access key secret of Alibaba Cloud account
# The access key secret of the Alibaba Cloud account
secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# SSH key name of Alibaba Cloud ECS
ssh_key_name = "xxxxxxx"
# Local path to SSH key of Alibaba Cloud ECS
ssh_key_local_path = "/<path>/<to>/<ssh-key>/xxxxxxx.pem"
# The ssh key name of the Alibaba Cloud ECS
ssh_key_name = "ssh-increment-meta"
# The file path of the ssh key which will be saved on local
ssh_key_local_path = "./ssh-increment-meta-tf.pem"
# Region in Alibaba Cloud
region = "cn-qingdao"
# Prefix for name of ECS
# Prefix for the name of the ECS
prefix = "tf-sample-"
# Suffix for name of ECS
# Suffix for the name of the ECS
suffix = "-incremant-meta"
```
Expand All @@ -151,7 +146,7 @@ Before creating the application, you need to prepare account credentials of Alib
terraform apply
```
You can check the created product on Alibaba cloud from the following web console url. If you changed region settings in step 2, please change region accordingly.
You can check the created product on Alibaba Cloud from the following web console url. If you changed region settings in step 2, please change region accordingly.
* ECS
Expand Down
3 changes: 2 additions & 1 deletion tool/infrastructure/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.terraform*
terraform.tfstate*
terraform.tfvars
terraform.tfvars
*.pem
15 changes: 12 additions & 3 deletions tool/infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ resource "alicloud_security_group_rule" "sgr22" {
cidr_ip = "0.0.0.0/0"
}

# SSH key pair
resource "alicloud_key_pair" "keypair_ecs1" {
key_name = "${var.ssh_key_name}"
key_file = "${var.ssh_key_local_path}"
}
# ECS
data "alicloud_images" "centos" {
name_regex = "^centos_7.*vhd$"
Expand All @@ -76,7 +81,8 @@ resource "alicloud_instance" "ecs1" {
image_id = "${data.alicloud_images.centos.images.0.id}"
instance_type = "${data.alicloud_instance_types.2c4g.instance_types.0.id}"
instance_name = "${var.prefix}ecs1${var.suffix}"
key_name = "${var.ssh_key_name}"

key_name = "${alicloud_key_pair.keypair_ecs1.key_name}"
}
# EIP (ecs1)
resource "alicloud_eip" "eip_ecs1" {
Expand All @@ -92,7 +98,7 @@ resource "alicloud_eip_association" "eip_ecs1_asso" {
connection {
type = "ssh"
user = "root"
private_key = "${file(var.ssh_key_local_path)}"
private_key = "${file(alicloud_key_pair.keypair_ecs1.key_file)}"
host = "${alicloud_eip.eip_ecs1.ip_address}"
timeout = "1m"
}
Expand All @@ -105,7 +111,7 @@ resource "alicloud_eip_association" "eip_ecs1_asso" {
connection {
type = "ssh"
user = "root"
private_key = "${file(var.ssh_key_local_path)}"
private_key = "${file(alicloud_key_pair.keypair_ecs1.key_file)}"
host = "${alicloud_eip.eip_ecs1.ip_address}"
timeout = "1m"
}
Expand All @@ -126,3 +132,6 @@ output "[debug] ecs1 image_id" {
output "[debug] eip_ecs1 ip_address" {
value = "${alicloud_eip.eip_ecs1.ip_address}"
}
output "[output] ecs1 keypair_ecs1 key_name" {
value = "${alicloud_key_pair.keypair_ecs1.key_name}"
}

0 comments on commit 8165fe7

Please sign in to comment.