Skip to content
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 Terraform For Windows Test #391

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ jobs:
aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/binary/${{ github.sha }} . --recursive

- uses: montudor/action-zip@v1
if: steps.cached_win_zip.outputs.cache-hit != 'true'
SaxyPandaBear marked this conversation as resolved.
Show resolved Hide resolved
with:
args: unzip -qq windows/amd64/amazon-cloudwatch-agent.zip -d windows-agent

- name: Create msi dep folder and copy deps
if: steps.cached_win_zip.outputs.cache-hit != 'true'
run: |
export version=$(cat CWAGENT_VERSION)
echo cw agent version $version
Expand Down Expand Up @@ -297,12 +299,69 @@ jobs:
-var="arc=${{ matrix.arrays.arc }}"
-var="binary_name=${{ matrix.arrays.binaryName }}"
-var="local_stack_host_name=${{ needs.StartLocalStack.outputs.local_stack_host_name }}"

- name: Terraform destroy
if: ${{ always() && steps.ec2-linux-integration-test.outputs.cache-hit != 'true' }}
run: >
terraform destroy --auto-approve
-var="ami=${{ matrix.arrays.ami }}"

EC2WinIntegrationTest:
needs: [BuildMSI]
name: 'EC2WinIntegrationTest'
runs-on: ubuntu-latest
defaults:
run:
working-directory: integration/terraform/ec2/win
strategy:
fail-fast: false
matrix:
arrays: [
{ os: "win-2022", ami: "cloudwatch-agent-integration-test-win-2022*"}
SaxyPandaBear marked this conversation as resolved.
Show resolved Hide resolved
]
steps:
- uses: actions/checkout@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Cache if success
id: ec2-win-integration-test
uses: actions/cache@v2
with:
path: |
RELEASE_NOTES
key: ec2-win-integration-test-${{ github.sha }}-${{ matrix.arrays.os }}

- name: Echo OS
run: echo run on ec2 instance os ${{ matrix.arrays.os }}

- name: Verify Terraform version
run: terraform --version

- name: Terraform init
run: terraform init

- name: Terraform apply
if: steps.ec2-win-integration-test.outputs.cache-hit != 'true'
run: >
echo run terraform and execute test code &&
terraform apply --auto-approve
-var="ssh_key=${PRIVATE_KEY}"
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
-var="github_sha=${GITHUB_SHA}"
-var="ami=${{ matrix.arrays.ami }}"

- name: Terraform destroy
if: ${{ always() && steps.ec2-win-integration-test.outputs.cache-hit != 'true' }}
run: >
terraform destroy --auto-approve
-var="ami=${{ matrix.arrays.ami }}"

StopLocalStack:
name: 'StopLocalStack'
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ CWAGENT_VERSION
*.iml
.terraform.*
terraform.*
.terraform/*
**/.terraform/*
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
coverage.txt
2 changes: 1 addition & 1 deletion integration/terraform/ec2/linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_instance" "integration-test" {
provisioner "remote-exec" {
inline = [
"cloud-init status --wait",
"echo clone, build, and install agent",
"echo clone and install agent",
"git clone ${var.github_repo}",
"cd amazon-cloudwatch-agent",
"git reset --hard ${var.github_sha}",
Expand Down
37 changes: 37 additions & 0 deletions integration/terraform/ec2/win/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
resource "aws_instance" "integration-test" {
ami = data.aws_ami.latest.id
instance_type = var.ec2_instance_type
key_name = var.key_name
iam_instance_profile = var.iam_instance_profile
vpc_security_group_ids = var.vpc_security_group_ids
get_password_data = true
provisioner "remote-exec" {
# @TODO when @ZhenyuTan-amz adds windows tests add "make integration-test"
inline = [
"echo clone and install agent",
"git clone ${var.github_repo}",
"cd amazon-cloudwatch-agent",
"git reset --hard ${var.github_sha}",
"aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/packaging/${var.github_sha}/amazon-cloudwatch-agent.msi .",
"msiexec /i amazon-cloudwatch-agent.msi",
]
connection {
type = "ssh"
user = "Administrator"
private_key = var.ssh_key
password = rsadecrypt(self.password_data, var.ssh_key)
host = self.public_dns
target_platform = "windows"
}
}
}

data "aws_ami" "latest" {
most_recent = true
owners = ["self"]

filter {
name = "name"
values = [var.ami]
}
}
3 changes: 3 additions & 0 deletions integration/terraform/ec2/win/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = var.region
}
44 changes: 44 additions & 0 deletions integration/terraform/ec2/win/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
variable "ec2_instance_type" {
type = string
default = "t3a.xlarge"
}

variable "key_name" {
type = string
default = "cwagent-integ-test-key"
}

variable "iam_instance_profile" {
type = string
default = "CloudWatchAgentServerRole"
}

variable "vpc_security_group_ids" {
type = list(string)
default = ["sg-013585129c1f92bf0"]
}

variable "region" {
type = string
default = "us-west-2"
}

variable "ami" {
type = string
default = ""
}

variable "ssh_key" {
type = string
default = ""
}

variable "github_sha" {
type = string
default = ""
}

variable "github_repo" {
type = string
default = ""
}