Skip to content

Commit

Permalink
Template automation (#11)
Browse files Browse the repository at this point in the history
* Add initial setup for pytest and GitHubClient tests

- Created pytest configuration file `pytest.ini` for test discovery and options.
- Added `requirements.txt` for project dependencies including testing libraries.
- Introduced `test_payload.json` for storing test data related to EKS settings.
- Established a test package with `__init__.py` in the `tests` directory.
- Implemented fixtures in `conftest.py` for mocking GitHub API responses.
- Developed unit tests for `GitHubClient` methods in `test_github_client.py`.
- Created integration tests for `GitHubClient` in `test_github_client_integration.py`.
- Added environment cleanup fixture to ensure a clean state for tests.
- Implemented unit tests for application logic in `test_app.py`, including SSM parameter retrieval and GitHub operations.

* Refactor GitHub token handling to use GITHUB_TOKEN_SECRET_NAME

* Add team-based admin access feature to GitHubClient and integration tests

---------

Co-authored-by: Dave Arnold <dave@roknsound.com>
  • Loading branch information
2 people authored and GitHub committed Apr 25, 2025
1 parent 3a0f957 commit 813e00f
Show file tree
Hide file tree
Showing 26 changed files with 556 additions and 241 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ jobs:
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: eks_automation/requirements.txt
cache-dependency-path: template_automation/requirements.txt

- name: Install dependencies
run: |
cd eks_automation
cd template_automation
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run integration tests
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GITHUB_TOKEN_SECRET_NAME: /dev/secret/ssh/dont/tell
GITHUB_API: "https://api.github.com" # Can be overridden with vars if needed
GITHUB_ORG: ${{ github.repository_owner }}
SECRET_NAME: /dev/secret/ssh/dont/tell
GITHUB_ORG_NAME: ${{ github.repository_owner }}
run: |
cd eks_automation
cd template_automation
python -m pytest tests/ -v -m integration
27 changes: 10 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# EKS Automation Lambda
# Template Automation Lambda

## Description

This repository contains source code and supporting files for a serverless Lambda container application.
The application uses an AWS Lambda function to process JSON input and write it to a cloned repository.
The changes are then committed and pushed to your GitHub Enterprise Server, creating a new repository
for the EKS CI/CD pipeline.
with custom configurations from your template.

## Architecture

Expand All @@ -27,13 +27,13 @@ for the EKS CI/CD pipeline.

1. Clone this repository:
```sh
git clone <your-github-enterprise-url>/eks-automation-lambda.git
cd eks-automation-lambda
git clone <your-github-enterprise-url>/template-automation-lambda.git
cd template-automation-lambda
```

2. Install Python dependencies:
```sh
cd eks_automation
cd template_automation
pip install -r requirements.txt
```

Expand Down Expand Up @@ -76,24 +76,17 @@ The Lambda function accepts JSON input in the following format:
```json
{
"project_name": "string",
"eks_settings": {
"template_settings": {
"attrs": {
"account_name": "my-account",
"aws_region": "us-east-1",
"cluster_mailing_list": "someone@example.com",
"cluster_name": "my-eks-cluster",
"eks_instance_disk_size": 100,
"eks_ng_desired_size": 2,
"eks_ng_max_size": 10,
"eks_ng_min_size": 2,
"team_contact": "someone@example.com",
"project_name": "my-project",
"environment": "development",
"environment_abbr": "dev",
"organization": "my-org:my-division:my-team",
"finops_project_name": "my_project_baseline",
"finops_project_number": "fp00000001",
"finops_project_role": "my_project_baseline_app",
"vpc_domain_name": "dev.example.com",
"vpc_name": "vpc-dev"
"project_id": "proj_001",
"domain_name": "dev.example.com"
},
"tags": {
"slim:schedule": "8:00-17:00"
Expand Down
Empty file removed eks_automation/__init__.py
Empty file.
20 changes: 0 additions & 20 deletions infrastructure/github-actions-trust-policy.json

This file was deleted.

99 changes: 0 additions & 99 deletions infrastructure/main.tf

This file was deleted.

14 changes: 0 additions & 14 deletions infrastructure/outputs.tf

This file was deleted.

12 changes: 0 additions & 12 deletions infrastructure/providers.tf

This file was deleted.

15 changes: 0 additions & 15 deletions infrastructure/variables.tf

This file was deleted.

43 changes: 23 additions & 20 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
provider "aws" {
region = "us-east-1"
region = var.aws_region
}

data "aws_caller_identity" "current" {}

resource "aws_ecrpublic_repository" "eks-automation-lambda" {
repository_name = "eks-automation-lambda"
resource "aws_ecrpublic_repository" "ecr_repo" {
repository_name = var.repository_name

catalog_data {
about_text = "EKS Automation Lambda Image"
architectures = ["x86_64"]
description = "Lambda container image for EKS automation"
operating_systems = ["AmazonLinux2"]
usage_text = "Creates an EKS Automation Lambda container image"
about_text = var.catalog_data.about_text
architectures = var.catalog_data.architectures
description = var.catalog_data.description
operating_systems = var.catalog_data.operating_systems
usage_text = var.catalog_data.usage_text
}

tags = {
env = "production"
}
tags = var.tags
}

locals {
repository_uri = aws_ecrpublic_repository.eks-automation-lambda.repository_uri
repository_id = aws_ecrpublic_repository.eks-automation-lambda.id
repository_uri = aws_ecrpublic_repository.ecr_repo.repository_uri
repository_id = aws_ecrpublic_repository.ecr_repo.id
aws_account_id = data.aws_caller_identity.current.account_id
region = "us-east-1"
arn = aws_ecrpublic_repository.eks-automation-lambda.arn
region = var.aws_region
arn = aws_ecrpublic_repository.ecr_repo.arn
}

output "repository_uri" {
value = local.repository_uri
description = "The URI of the ECR repository"
value = local.repository_uri
}

output "repository_id" {
value = local.repository_id
description = "The ID of the ECR repository"
value = local.repository_id
}

output "aws_account_id" {
value = local.aws_account_id
description = "The ID of the AWS account"
value = local.aws_account_id
}

output "region" {
value = local.region
description = "The AWS region where resources are created"
value = local.region
}

output "arn" {
value = local.arn
description = "The ARN of the ECR repository"
value = local.arn
}
17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from setuptools import setup, find_packages

setup(
name="template-automation",
version="0.1.0",
packages=find_packages(),
install_requires=[
"boto3",
"requests"
],
extras_require={
"test": [
"pytest",
"pytest-mock"
]
}
)
17 changes: 17 additions & 0 deletions template-automation-lambda.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"folders": [
{
"path": "."
},
{
"path": "../terraform-aws-template-automation"
},
{
"path": "../providers/terraform-provider-aws/website/docs/d"
},
{
"path": "../providers/terraform-provider-aws/website/docs/r"
}
],
"settings": {}
}
1 change: 1 addition & 0 deletions template_automation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Package initialization
Loading

0 comments on commit 813e00f

Please sign in to comment.