Skip to content

Commit

Permalink
Add Terraform For Windows Test (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon authored Mar 24, 2022
1 parent 5991033 commit 8a25004
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 2 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,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*"}
]
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/*
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 = ""
}

0 comments on commit 8a25004

Please sign in to comment.