-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add win user data test #377
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,10 @@ var testTypeToTestConfig = map[string][]testConfig{ | |
{testDir: "../../../test/restart"}, | ||
{testDir: "../../../test/acceptance"}, | ||
{testDir: "../../../test/feature/windows/event_logs"}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to run this on all platforms. |
||
testDir: "../../../test/feature/windows/userdata", | ||
targets: map[string]map[string]struct{}{"os": {"win-2019": {}}}, | ||
}, | ||
// assume role test doesn't add much value, and it already being tested with linux | ||
//{testDir: "../../../test/assume_role"}, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<powershell> | ||
$installDirectory = "c:\temp\cw" | ||
adam-mateen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$downloadDirectory = $installDirectory | ||
$logsDirectory = $installDirectory | ||
$cwAgentInstaller = "$downloadDirectory\amazon-cloudwatch-agent.msi" | ||
$cwAgentInstallPath = "C:\\Program Files\\Amazon\\AmazonCloudWatchAgent" | ||
|
||
New-Item -ItemType "directory" -Path $installDirectory | ||
|
||
Set-Location -Path $installDirectory | ||
|
||
Write-host "Installing Powershell S3 CLI" | ||
Install-PackageProvider NuGet -Force; | ||
Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
Install-Module -Name AWS.Tools.S3 -AllowClobber | ||
|
||
Write-host "Installing Cloudwatch Agent" | ||
${copy_object} | ||
Start-Process -FilePath msiexec -Args "/i $cwAgentInstaller /l*v $logsDirectory\installCWAgentLog.log /qn" -Verb RunAs -Wait | ||
|
||
Write-host "Load config" | ||
|
||
& "$cwAgentInstallPath\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c ssm:${agent_json_config} | ||
</powershell> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ resource "aws_instance" "cwagent" { | |
vpc_security_group_ids = [module.basic_components.security_group] | ||
associate_public_ip_address = true | ||
instance_initiated_shutdown_behavior = "terminate" | ||
user_data = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? data.template_file.user_data.rendered : "" | ||
get_password_data = true | ||
|
||
metadata_options { | ||
|
@@ -72,18 +73,20 @@ resource "aws_instance" "cwagent" { | |
tags = { | ||
Name = "cwagent-integ-test-ec2-windows-${var.test_name}-${module.common.testing_id}" | ||
} | ||
depends_on = [aws_ssm_parameter.upload_ssm] | ||
} | ||
|
||
# Size of windows json is too large thus can't use standard tier | ||
resource "aws_ssm_parameter" "upload_ssm" { | ||
count = var.use_ssm == true && length(regexall("/feature/windows", var.test_dir)) > 0 ? 1 : 0 | ||
count = length(regexall("/feature/windows", var.test_dir)) > 0 ? 1 : 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can upload the value to ssm for all feature tests since it will be deleted by terraform destroy anyway. This will allow us to use ssm for userdata test. |
||
name = local.ssm_parameter_name | ||
type = "String" | ||
tier = "Advanced" | ||
value = file(module.validator.agent_config) | ||
} | ||
|
||
resource "null_resource" "integration_test_setup" { | ||
resource "null_resource" "integration_test_setup_agent" { | ||
count = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? 0 : 1 | ||
depends_on = [aws_instance.cwagent, module.validator, aws_ssm_parameter.upload_ssm] | ||
|
||
# Install software | ||
|
@@ -99,6 +102,24 @@ resource "null_resource" "integration_test_setup" { | |
inline = [ | ||
"aws s3 cp s3://${var.s3_bucket}/integration-test/packaging/${var.cwa_github_sha}/amazon-cloudwatch-agent.msi .", | ||
"start /wait msiexec /i amazon-cloudwatch-agent.msi /norestart /qb-", | ||
] | ||
} | ||
} | ||
|
||
resource "null_resource" "integration_test_setup_validator" { | ||
depends_on = [aws_instance.cwagent, module.validator, aws_ssm_parameter.upload_ssm] | ||
|
||
# Install software | ||
connection { | ||
type = "winrm" | ||
user = "Administrator" | ||
password = rsadecrypt(aws_instance.cwagent.password_data, local.private_key_content) | ||
host = aws_instance.cwagent.public_dns | ||
} | ||
|
||
# Install agent binaries | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"aws s3 cp s3://${var.s3_bucket}/integration-test/validator/${var.cwa_github_sha}/windows/${var.arc}/validator.exe .", | ||
] | ||
} | ||
|
@@ -123,7 +144,8 @@ resource "null_resource" "integration_test_reboot" { | |
} | ||
|
||
depends_on = [ | ||
null_resource.integration_test_setup, | ||
null_resource.integration_test_setup_agent, | ||
null_resource.integration_test_setup_validator, | ||
] | ||
} | ||
|
||
|
@@ -144,7 +166,8 @@ resource "null_resource" "integration_test_run" { | |
# run go test when it's not feature test | ||
count = length(regexall("/feature/windows", var.test_dir)) < 1 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup, | ||
null_resource.integration_test_setup_agent, | ||
null_resource.integration_test_setup_agent, | ||
null_resource.integration_test_wait, | ||
] | ||
|
||
|
@@ -170,9 +193,10 @@ resource "null_resource" "integration_test_run" { | |
|
||
resource "null_resource" "integration_test_run_validator" { | ||
# run validator only when test_dir is not passed e.g. the default from variable.tf | ||
count = length(regexall("/feature/windows", var.test_dir)) > 0 ? 1 : 0 | ||
count = length(regexall("/feature/windows", var.test_dir)) > 0 && length(regexall("/feature/windows/userdata", var.test_dir)) < 1 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup, | ||
null_resource.integration_test_setup_agent, | ||
null_resource.integration_test_setup_validator, | ||
null_resource.integration_test_wait, | ||
] | ||
|
||
|
@@ -213,6 +237,42 @@ resource "null_resource" "integration_test_run_validator" { | |
} | ||
} | ||
|
||
resource "null_resource" "integration_test_run_validator_userdata" { | ||
# run validator only when test_dir is not passed e.g. the default from variable.tf | ||
count = length(regexall("/feature/windows/userdata", var.test_dir)) > 0 ? 1 : 0 | ||
depends_on = [ | ||
null_resource.integration_test_setup_validator, | ||
null_resource.integration_test_wait, | ||
] | ||
|
||
connection { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using EC2 "userdata" to launch the instance and install the agent, then do we still need winrm access to the instance? In other words, after launching a Windows EC2 instance with the agent installed with user-data, what additional steps occur? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This runs the validator, it does not reinstall / restart the agent. The validator runs on the ec2 instance. |
||
type = "winrm" | ||
user = "Administrator" | ||
password = rsadecrypt(aws_instance.cwagent.password_data, local.private_key_content) | ||
host = aws_instance.cwagent.public_dns | ||
} | ||
|
||
provisioner "file" { | ||
source = module.validator.agent_config | ||
destination = module.validator.instance_agent_config | ||
} | ||
|
||
provisioner "file" { | ||
source = module.validator.validator_config | ||
destination = module.validator.instance_validator_config | ||
} | ||
|
||
//runs validator and sets up prometheus java agent | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"set AWS_REGION=${var.region}", | ||
"validator.exe --validator-config=${module.validator.instance_validator_config} --preparation-mode=true", | ||
"powershell.exe \"& \"C:ProgramFiles\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1\" -m ec2 -a status\"", | ||
"validator.exe --validator-config=${module.validator.instance_validator_config} --preparation-mode=false" | ||
] | ||
} | ||
} | ||
|
||
data "aws_ami" "latest" { | ||
most_recent = true | ||
|
||
|
@@ -221,3 +281,19 @@ data "aws_ami" "latest" { | |
values = [var.ami] | ||
} | ||
} | ||
|
||
##################################################################### | ||
# Generate template file for EC2 userdata script | ||
##################################################################### | ||
data "template_file" "user_data" { | ||
template = file("install_and_start_agent.tpl") | ||
|
||
vars = { | ||
copy_object = "Copy-S3Object -BucketName ${var.s3_bucket} -Key integration-test/packaging/${var.cwa_github_sha}/amazon-cloudwatch-agent.msi -region ${var.region} -LocalFile $cwAgentInstaller" | ||
agent_json_config = local.ssm_parameter_name | ||
} | ||
} | ||
|
||
output "userdata" { | ||
value = data.template_file.user_data.rendered | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ func main() { | |
binary.BigEndian.PutUint32(r[0:4], uint32(epochNow)) | ||
rand.Read(r[4:]) | ||
fmt.Printf("%s", hex.EncodeToString(r[:])) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This come from running make fmt |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to have to run this command in terminal when I get terraform fmt error. I should be able to run it via make.