diff --git a/.github/workflows/integrationTest.yml b/.github/workflows/integrationTest.yml index a7e09244ae..929683bec2 100644 --- a/.github/workflows/integrationTest.yml +++ b/.github/workflows/integrationTest.yml @@ -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' 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 @@ -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*"} + ] + 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 diff --git a/.gitignore b/.gitignore index c2f29d5139..163bc41901 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ CWAGENT_VERSION *.iml .terraform.* terraform.* -.terraform/* +**/.terraform/* coverage.txt \ No newline at end of file diff --git a/integration/terraform/ec2/linux/main.tf b/integration/terraform/ec2/linux/main.tf index 5473b5be3f..5a5d922878 100644 --- a/integration/terraform/ec2/linux/main.tf +++ b/integration/terraform/ec2/linux/main.tf @@ -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}", diff --git a/integration/terraform/ec2/win/main.tf b/integration/terraform/ec2/win/main.tf new file mode 100644 index 0000000000..60bac19b64 --- /dev/null +++ b/integration/terraform/ec2/win/main.tf @@ -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] + } +} \ No newline at end of file diff --git a/integration/terraform/ec2/win/providers.tf b/integration/terraform/ec2/win/providers.tf new file mode 100644 index 0000000000..19769a7fb3 --- /dev/null +++ b/integration/terraform/ec2/win/providers.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = var.region +} \ No newline at end of file diff --git a/integration/terraform/ec2/win/variables.tf b/integration/terraform/ec2/win/variables.tf new file mode 100644 index 0000000000..a1e156405c --- /dev/null +++ b/integration/terraform/ec2/win/variables.tf @@ -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 = "" +} \ No newline at end of file