@@ -15,6 +15,19 @@ provider "aws" {
1515 region = var. region
1616}
1717
18+ # get ami object
19+ locals {
20+ selected_ami = var. amis [var . testing_ami ]
21+ ami_family = var. ami_family [local . selected_ami [" family" ]]
22+ ami_id = data. aws_ami . selected . id
23+ instance_type = local. ami_family [" instance_type" ]
24+ otconfig_destination = local. ami_family [" otconfig_destination" ]
25+ login_user = local. ami_family [" login_user" ]
26+ connection_type = local. ami_family [" connection_type" ]
27+ user_data = local. ami_family [" user_data" ]
28+ download_command = format (local. ami_family [" download_command_pattern" ], " https://${ var . package_s3_bucket } .s3.amazonaws.com/${ local . selected_ami [" family" ]} /${ local . selected_ami [" arch" ]} /${ var . aoc_version } /${ local . ami_family [" install_package" ]} " )
29+ }
30+
1831# # get the ssh private key
1932data "aws_s3_bucket_object" "ssh_private_key" {
2033 bucket = var. sshkey_s3_bucket
@@ -33,39 +46,43 @@ data "template_file" "otconfig" {
3346 }
3447}
3548
36- # launch ec2 instance to install aoc [todo, support more amis, only amazonlinux2 is supported now]
49+ # launch ec2 instance to install aoc [todo, support more amis, only amazonlinux2 ubuntu, windows2019 is supported now]
3750resource "aws_instance" "aoc" {
38- ami = data . aws_ami . selected . id
39- instance_type = " t2.micro "
51+ ami = local . ami_id
52+ instance_type = local . instance_type
4053 subnet_id = tolist (module. basic_components . aoc_public_subnet_ids )[0 ]
4154 vpc_security_group_ids = [module . basic_components . aoc_security_group_id ]
4255 associate_public_ip_address = true
4356 iam_instance_profile = module. common . aoc_iam_role_name
4457 key_name = module. common . ssh_key_name
58+ get_password_data = local. connection_type == " winrm" ? true : null
59+ user_data = local. user_data
4560
4661 provisioner "file" {
4762 content = data. template_file . otconfig . rendered
48- destination = " /tmp/ot-default.yml "
63+ destination = local . otconfig_destination
4964
5065 connection {
51- type = " ssh"
52- user = " ec2-user"
53- private_key = data. aws_s3_bucket_object . ssh_private_key . body
66+ type = local. connection_type
67+ user = local. login_user
68+ private_key = local. connection_type == " ssh" ? data. aws_s3_bucket_object . ssh_private_key . body : null
69+ password = local. connection_type == " winrm" ? rsadecrypt (aws_instance. aoc . password_data , data. aws_s3_bucket_object . ssh_private_key . body ) : null
5470 host = aws_instance. aoc . public_ip
5571 }
5672 }
5773
5874 provisioner "remote-exec" {
5975 inline = [
60- " wget https:// ${ var . package_s3_bucket } .s3.amazonaws.com/amazon_linux/amd64/ ${ var . aoc_version } /aws-observability-collector.rpm " ,
61- " sudo rpm -Uvh aws-observability-collector.rpm " ,
62- " sudo /opt/aws/aws-observability-collector/bin/aws-observability-collector-ctl -c /tmp/ot-default.yml -a start "
76+ local . download_command ,
77+ local . ami_family [ " install_command " ] ,
78+ local . ami_family [ " start_command " ]
6379 ]
6480
6581 connection {
66- type = " ssh"
67- user = " ec2-user"
68- private_key = data. aws_s3_bucket_object . ssh_private_key . body
82+ type = local. connection_type
83+ user = local. login_user
84+ private_key = local. connection_type == " ssh" ? data. aws_s3_bucket_object . ssh_private_key . body : null
85+ password = local. connection_type == " winrm" ? rsadecrypt (aws_instance. aoc . password_data , data. aws_s3_bucket_object . ssh_private_key . body ) : null
6986 host = aws_instance. aoc . public_ip
7087 }
7188 }
@@ -74,8 +91,6 @@ resource "aws_instance" "aoc" {
7491
7592# # launch a ec2 instance to install data emitter
7693resource "aws_instance" "emitter" {
77- # don't do emitter instance if the sample app is not callable
78- count = var. sample_app_callable ? 1 : 0
7994 ami = data. aws_ami . suse . id
8095 instance_type = " t2.micro"
8196 subnet_id = tolist (module. basic_components . aoc_public_subnet_ids )[0 ]
@@ -98,16 +113,14 @@ data "template_file" "docker_compose" {
98113 }
99114}
100115resource "null_resource" "sample-app-validator" {
101- count = var. sample_app_callable ? 1 : 0
102-
103116 provisioner "file" {
104117 content = data. template_file . docker_compose . rendered
105118 destination = " /tmp/docker-compose.yml"
106119 connection {
107120 type = " ssh"
108121 user = " ec2-user"
109122 private_key = data. aws_s3_bucket_object . ssh_private_key . body
110- host = aws_instance. emitter [ 0 ] . public_ip
123+ host = aws_instance. emitter . public_ip
111124 }
112125 }
113126 provisioner "remote-exec" {
@@ -122,21 +135,12 @@ resource "null_resource" "sample-app-validator" {
122135 type = " ssh"
123136 user = " ec2-user"
124137 private_key = data. aws_s3_bucket_object . ssh_private_key . body
125- host = aws_instance. emitter [ 0 ] . public_ip
138+ host = aws_instance. emitter . public_ip
126139 }
127140 }
128141
129142 provisioner "local-exec" {
130- command = " ${ module . common . validator_path } --args='-c ${ var . validation_config } -t ${ module . common . testing_id } --region ${ var . region } --metric-namespace ${ module . common . otel_service_namespace } /${ module . common . otel_service_name } --endpoint http://${ aws_instance . emitter [0 ]. public_ip } '"
131- working_dir = " ../../"
132- }
133- }
134-
135- # only run it when aoc collects metrics without any sample apps
136- resource "null_resource" "validator" {
137- count = ! var. sample_app_callable ? 1 : 0
138- provisioner "local-exec" {
139- command = " ${ module . common . validator_path } --args='-c ${ var . validation_config } -t ${ module . common . testing_id } --region ${ var . region } --metric-namespace ${ module . common . otel_service_namespace } /${ module . common . otel_service_name } '"
143+ command = " ${ module . common . validator_path } --args='-c ${ var . validation_config } -t ${ module . common . testing_id } --region ${ var . region } --metric-namespace ${ module . common . otel_service_namespace } /${ module . common . otel_service_name } --endpoint http://${ aws_instance . emitter . public_ip } '"
140144 working_dir = " ../../"
141145 }
142146}
0 commit comments