Skip to content

Commit

Permalink
feat(spec-tests): introduce aws spec tests (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
obs-gh-colinhutchinson authored Sep 18, 2023
1 parent d1faaf5 commit ca54dda
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 9 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/spec-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run AWS Spec tests

on:
workflow_dispatch:
schedule:
- cron: "0 13 * * 1" # Every Monday

permissions:
contents: write
id-token: write
packages: write

jobs:
run-aws-test-kitchen:
uses: observeinc/aws-test-kitchen/.github/workflows/ci.yml@main
with:
test_type: cloudformation
code_sha: ${{ github.sha }}
secrets:
OBSERVE_CUSTOMER: ${{ secrets.OBSERVE_CUSTOMER }}
OBSERVE_TOKEN: ${{ secrets.OBSERVE_TOKEN }}
OBSERVE_DOMAIN: ${{ secrets.OBSERVE_DOMAIN }}
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
7 changes: 0 additions & 7 deletions infrastructure/backend.tf

This file was deleted.

2 changes: 1 addition & 1 deletion infrastructure/main.tf → infrastructure/release/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ resource "aws_iam_role_policy" "github_actions_s3_write_inline" {
}

resource "github_actions_variable" "aws_release_role" {
repository = local.repository
repository = "${local.repository}"

variable_name = "AWS_ROLE_ARN"
value = aws_iam_role.github_actions_release.arn
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
13 changes: 13 additions & 0 deletions infrastructure/release/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
github = {
source = "integrations/github"
version = ">= 5"
}

aws = {
source = "hashicorp/aws"
version = ">= 5"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ terraform destroy
- Creates an IAM role with permissions that allow GitHub Actions to release CloudFormation templates to the specified S3 bucket.
- Configures GitHub Actions variables in the repository with the ARN of the IAM role so that it can be used in the release workflow.
- Configures GitHub Actions variables in the repository with the ARN of the IAM role so that it can be used.
### S3 Bucket Management
Expand Down
7 changes: 7 additions & 0 deletions infrastructure/testing/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
backend "s3" {
bucket = "observe-github-tf-state"
region = "us-west-2"
key = "github.com/observeinc/cloudformation-aws-collection"
}
}
61 changes: 61 additions & 0 deletions infrastructure/testing/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
terraform {
required_version = "~> 1.5"
}

locals {
organization = "observeinc"
repository = "cloudformation-aws-collection"
}

data "aws_iam_openid_connect_provider" "github_actions" {
url = "https://token.actions.githubusercontent.com"
}

locals {
oidc_claim_prefix = trimprefix(data.aws_iam_openid_connect_provider.github_actions.url, "https://")
}

data "aws_iam_policy_document" "github_actions_assume_role" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]

principals {
type = "Federated"
identifiers = [data.aws_iam_openid_connect_provider.github_actions.arn]
}

condition {
test = "StringLike"
variable = "${local.oidc_claim_prefix}:sub"
values = ["repo:${local.organization}/${local.repository}:*"]
}

condition {
test = "StringEquals"
variable = "${local.oidc_claim_prefix}:aud"
values = ["sts.amazonaws.com"]
}
}
}

resource "aws_iam_role" "github_actions_ci" {
name = "${local.repository}-gha-ci"

assume_role_policy = data.aws_iam_policy_document.github_actions_assume_role.json

tags = {
Principal = "GitHub Actions"
Repository = "${local.organization}/${local.repository}"
}
}

resource "aws_iam_role_policy_attachment" "admin_policy_attachment" {
role = aws_iam_role.github_actions_ci.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}

resource "github_actions_secret" "aws_ci_role" {
repository = local.repository
secret_name = "AWS_ROLE_ARN"
plaintext_value = aws_iam_role.github_actions_ci.arn
}
Empty file.
3 changes: 3 additions & 0 deletions infrastructure/testing/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "github" {
owner = local.organization
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
terraform {
required_version = ">= 1.1.0"

required_providers {
github = {
source = "integrations/github"
Expand Down

0 comments on commit ca54dda

Please sign in to comment.