Skip to content

Commit 2018343

Browse files
authored
Polish the Terraform script and Ansible playbook (#26)
- Allow using both remote SkyWalking binary package or locally built package. - Add AWS `access_key` and `secret_key` to Terraform variables so users do not need to configure the AWS credentials locally for this repo instead of globally.
1 parent 137ec16 commit 2018343

4 files changed

Lines changed: 67 additions & 45 deletions

File tree

ansible/roles/skywalking/tasks/main.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@
2323
group: skywalking
2424
mode: "0755"
2525

26-
- name: Download Apache SkyWalking tar file
26+
- name: Download Apache SkyWalking tarball
27+
when: skywalking_tarball is match('^https?://.*')
2728
get_url:
28-
url: "https://dlcdn.apache.org/skywalking/{{ skywalking_version }}/apache-skywalking-apm-{{ skywalking_version }}.tar.gz"
29-
dest: "/usr/local/skywalking/apache-skywalking-apm-{{ skywalking_version }}.tar.gz"
29+
url: "{{ skywalking_tarball }}"
30+
timeout: 120
31+
dest: /usr/local/skywalking/apache-skywalking-apm.tar.gz
32+
33+
- name: Upload Local Apache SkyWalking tarball
34+
when: skywalking_tarball is not match('^https?://.*')
35+
ansible.builtin.copy:
36+
src: "{{ skywalking_tarball }}"
37+
dest: /usr/local/skywalking/apache-skywalking-apm.tar.gz
38+
owner: skywalking
39+
group: skywalking
40+
mode: '0755'
3041

3142
- name: Extract tar file
3243
unarchive:
33-
src: "/usr/local/skywalking/apache-skywalking-apm-{{ skywalking_version }}.tar.gz"
44+
src: /usr/local/skywalking/apache-skywalking-apm.tar.gz
3445
dest: "/usr/local/skywalking"
3546
remote_src: yes
3647
extra_opts: [--strip-components=1]
3748

38-
- name: Set ownership for extracted files
39-
ansible.builtin.file:
40-
path: /usr/local/skywalking
41-
owner: skywalking
42-
group: skywalking
43-
recurse: yes
44-
4549
- name: Check hostgroup size
4650
set_fact:
4751
group_size: "{{ groups['skywalking_oap'] | length }}"

ansible/roles/skywalking/vars/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
# limitations under the License.
1515

1616
---
17-
skywalking_version: "9.5.0"
17+
# skywalking_tarball can be a remote URL or a local path, if it's a remote URL
18+
# the remote file will be downloaded to the remote host and then extracted,
19+
# if it's a local path, the local file will be copied to the remote host and
20+
# then extracted.
21+
skywalking_tarball: "https://dist.apache.org/repos/dist/release/skywalking/9.5.0/apache-skywalking-apm-9.5.0.tar.gz"
1822
sw_ui_server_port: "8080"
1923
sw_oap_server_port: "12800"
2024
sw_zipkin_address: "9412"

aws/ec2.tf

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
# limitations under the License.
1515

1616
provider "aws" {
17-
region = var.region
17+
region = var.region
18+
access_key = var.access_key
19+
secret_key = var.secret_key
1820
}
1921

2022
resource "aws_instance" "skywalking-oap" {
21-
count = var.oap_instance_count
22-
ami = data.aws_ami.amazon-linux.id
23+
count = var.oap_instance_count
24+
ami = data.aws_ami.amazon-linux.id
2325
instance_type = var.instance_type
2426
tags = merge(
2527
{
26-
Name = "skywalking-oap"
28+
Name = "skywalking-oap"
2729
Description = "Installing and configuring SkyWalking OAPService on AWS"
2830
},
2931
var.extra_tags
@@ -37,12 +39,12 @@ resource "aws_instance" "skywalking-oap" {
3739
}
3840

3941
resource "aws_instance" "skywalking-ui" {
40-
count = var.ui_instance_count
41-
ami = data.aws_ami.amazon-linux.id
42+
count = var.ui_instance_count
43+
ami = data.aws_ami.amazon-linux.id
4244
instance_type = var.instance_type
4345
tags = merge(
4446
{
45-
Name = "skywalking-ui"
47+
Name = "skywalking-ui"
4648
Description = "Installing and configuring SkyWalking UI on AWS"
4749
},
4850
var.extra_tags
@@ -55,38 +57,38 @@ resource "aws_instance" "skywalking-ui" {
5557
}
5658

5759
resource "aws_security_group" "ssh-access" {
58-
name = "ssh-access"
60+
name = "ssh-access"
5961
description = "Allow SSH access from the Internet"
6062
ingress = [
6163
{
62-
from_port = 22
63-
to_port = 22
64-
protocol = "tcp"
65-
cidr_blocks = ["0.0.0.0/0"]
66-
description = "SSH access rule"
64+
from_port = 22
65+
to_port = 22
66+
protocol = "tcp"
67+
cidr_blocks = ["0.0.0.0/0"]
68+
description = "SSH access rule"
6769
ipv6_cidr_blocks = []
68-
prefix_list_ids = []
69-
security_groups = []
70-
self = false
70+
prefix_list_ids = []
71+
security_groups = []
72+
self = false
7173
}
7274
]
7375
tags = var.extra_tags
7476
}
7577

7678
resource "aws_security_group" "public-egress-access" {
77-
name = "public-egress-access"
79+
name = "public-egress-access"
7880
description = "Allow access to the Internet"
7981
egress = [
8082
{
81-
from_port = 0
82-
to_port = 0
83-
protocol = -1
84-
cidr_blocks = ["0.0.0.0/0"]
85-
description = "Allow access to the Internet"
83+
from_port = 0
84+
to_port = 0
85+
protocol = -1
86+
cidr_blocks = ["0.0.0.0/0"]
87+
description = "Allow access to the Internet"
8688
ipv6_cidr_blocks = []
87-
prefix_list_ids = []
88-
security_groups = []
89-
self = false
89+
prefix_list_ids = []
90+
security_groups = []
91+
self = false
9092
}
9193
]
9294
tags = var.extra_tags
@@ -96,10 +98,10 @@ resource "aws_security_group" "ui-to-oap-communication" {
9698
name = "ui-to-oap-communication"
9799
description = "Allow communication from SkyWalking UI to SkyWalking OAP"
98100
ingress {
99-
from_port = 0
100-
to_port = 12800
101-
protocol = "tcp"
102-
cidr_blocks = ["0.0.0.0/0"]
101+
from_port = 0
102+
to_port = 12800
103+
protocol = "tcp"
104+
cidr_blocks = ["0.0.0.0/0"]
103105
security_groups = [aws_security_group.public-egress-access.id]
104106
}
105107
tags = var.extra_tags
@@ -110,9 +112,9 @@ resource "local_file" "oap_instance_ips" {
110112
content = join("\n", flatten([
111113
["[skywalking_oap]"],
112114
aws_instance.skywalking-oap.*.public_ip,
113-
[""] # Adds an empty string for the trailing newline
115+
[""] # Adds an empty string for the trailing newline
114116
]))
115-
filename = "${path.module}/../ansible/inventory/oap-server"
117+
filename = "${path.module}/../ansible/inventory/oap-server"
116118
file_permission = "0600"
117119
}
118120

@@ -121,8 +123,8 @@ resource "local_file" "ui_instance_ips" {
121123
content = join("\n", flatten([
122124
["[skywalking_ui]"],
123125
aws_instance.skywalking-ui.*.public_ip,
124-
[""] # Adds an empty string for the trailing newline
126+
[""] # Adds an empty string for the trailing newline
125127
]))
126-
filename = "${path.module}/../ansible/inventory/ui-server"
128+
filename = "${path.module}/../ansible/inventory/ui-server"
127129
file_permission = "0600"
128130
}

aws/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ variable "region" {
2929
default = "us-east-1"
3030
}
3131

32+
variable "access_key" {
33+
type = string
34+
description = "Access key of the AWS account"
35+
default = ""
36+
}
37+
38+
variable "secret_key" {
39+
type = string
40+
description = "Secret key of the AWS account"
41+
default = ""
42+
}
43+
3244
variable "instance_type" {
3345
type = string
3446
description = "CPU, memory, storage and networking capacity"

0 commit comments

Comments
 (0)