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

feat: add format check workflows for JSON/YAML and Terraform files #31

Merged
merged 1 commit into from
Jan 15, 2025
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
23 changes: 23 additions & 0 deletions .github/workflows/format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: json-yaml-validate
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

permissions:
contents: read
pull-requests: write # enable write permissions for pull request comments

jobs:
json-yaml-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: json-yaml-validate
id: json-yaml-validate
uses: GrantBirki/[email protected]
with:
comment: "true" # enable comment mode
19 changes: 19 additions & 0 deletions .github/workflows/terraform-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check file formatting

on: [push]

jobs:
check_format:
runs-on: ubuntu-latest
name: Check Terraform file are formatted correctly
steps:
- name: Checkout
uses: actions/checkout@v4

- name: terraform fmt
uses: dflook/terraform-fmt-check@v1
id: fmt-check

- name: Wrong formatting found
if: ${{ failure() && steps.fmt-check.outputs.failure-reason == 'check-failed' }}
run: echo "formatting check failed"
48 changes: 24 additions & 24 deletions aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ module "automq_byoc_vpc" {

# NAT Gateway
# if the deploy type is k8s, then enable_nat_gateway is true, single_nat_gateway is true
enable_nat_gateway = var.automq_byoc_default_deploy_type == "k8s"
single_nat_gateway = var.automq_byoc_default_deploy_type == "k8s"
enable_nat_gateway = var.automq_byoc_default_deploy_type == "k8s"
single_nat_gateway = var.automq_byoc_default_deploy_type == "k8s"

tags = {
automqVendor = "automq"
Expand Down Expand Up @@ -172,7 +172,7 @@ data "aws_vpc" "vpc_id" {
}

locals {
image_name = var.use_custom_ami ? var.automq_byoc_env_console_ami : format("AutoMQ-control-center-Prod-%s-x86_64", var.automq_byoc_env_version)
image_name = var.use_custom_ami ? var.automq_byoc_env_console_ami : format("AutoMQ-control-center-Prod-%s-x86_64", var.automq_byoc_env_version)
}

data "aws_ami" "console_ami" {
Expand Down Expand Up @@ -240,7 +240,7 @@ resource "aws_iam_role" "automq_byoc_role" {

resource "aws_iam_role" "automq_byoc_node_role" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
name = "automq-byoc-node-role-${var.automq_byoc_env_id}"
name = "automq-byoc-node-role-${var.automq_byoc_env_id}"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Expand All @@ -263,46 +263,46 @@ resource "aws_iam_role" "automq_byoc_node_role" {
}

# https://docs.aws.amazon.com/zh_cn/eks/latest/userguide/create-node-role.html
resource "aws_iam_role_policy_attachment" "nodes-AmazonEKSWorkerNodePolicy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.automq_byoc_node_role[0].name
resource "aws_iam_role_policy_attachment" "nodes-AmazonEKSWorkerNodePolicy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.automq_byoc_node_role[0].name
}

resource "aws_iam_role_policy_attachment" "nodes-AmazonEKS_CNI_Policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.automq_byoc_node_role[0].name
resource "aws_iam_role_policy_attachment" "nodes-AmazonEKS_CNI_Policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.automq_byoc_node_role[0].name
}

resource "aws_iam_role_policy_attachment" "nodes-AmazonEC2ContainerRegistryReadOnly" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.automq_byoc_node_role[0].name
resource "aws_iam_role_policy_attachment" "nodes-AmazonEC2ContainerRegistryReadOnly" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.automq_byoc_node_role[0].name
}

# https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/deploy/installation/#option-b-attach-iam-policies-to-nodes
resource "aws_iam_role_policy" "aws_load-balancer_policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
name = "aws-load-balancer-controller-service-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name
name = "aws-load-balancer-controller-service-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name

policy = file("${path.module}/tpls/aws_load_balancer_controller_service_policy.json.tpl")
}

# https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/cloudprovider/aws/README.md
resource "aws_iam_role_policy" "aws_cluster_auto_scaler_policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
name = "aws-cluster-auto-scaler-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name
name = "aws-cluster-auto-scaler-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name

policy = file("${path.module}/tpls/aws_cluster_auto_scaler_policy.json.tpl")
}

resource "aws_iam_role_policy" "automq_s3_policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
name = "automq-s3-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name
name = "automq-s3-policy-${var.automq_byoc_env_id}"
role = aws_iam_role.automq_byoc_node_role[0].name

policy = templatefile("${path.module}/tpls/automq_node_s3_policy.json.tpl", {
automq_data_bucket = local.automq_data_bucket
Expand All @@ -312,7 +312,7 @@ resource "aws_iam_role_policy" "automq_s3_policy" {


resource "aws_iam_policy" "automq_byoc_policy" {
count = var.automq_byoc_default_deploy_type == "vm" ? 1 : 0
count = var.automq_byoc_default_deploy_type == "vm" ? 1 : 0
name = "automq-byoc-service-policy-${var.automq_byoc_env_id}"
description = "Custom policy for automq_byoc service"

Expand All @@ -328,7 +328,7 @@ resource "aws_iam_policy" "automq_byoc_policy" {
}

resource "aws_iam_policy" "automq_byoc_k8s_policy" {
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
count = var.automq_byoc_default_deploy_type == "k8s" ? 1 : 0
name = "automq-byoc-service-k8s-policy-${var.automq_byoc_env_id}"
description = "Custom policy for automq_byoc service"

Expand Down
13 changes: 4 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ resource "aws_instance" "automq_byoc_console" {
key_name = var.automq_byoc_env_console_key_name

tags = {
Name = "automq-byoc-console-${var.automq_byoc_env_id}"
automqVendor = "automq"
Name = "automq-byoc-console-${var.automq_byoc_env_id}"
automqVendor = "automq"
automqEnvironmentID = var.automq_byoc_env_id
}

Expand All @@ -34,18 +34,13 @@ resource "aws_instance" "automq_byoc_console" {
})
}

data "aws_key_pair" "select" {
count = var.automq_byoc_env_console_key_name != "" ? 1 : 0
key_name = var.automq_byoc_env_console_key_name
}

resource "aws_ebs_volume" "data_volume" {
availability_zone = data.aws_subnet.public_subnet_info.availability_zone
size = 20
type = "gp3"

tags = {
automqVendor = "automq"
automqVendor = "automq"
automqEnvironmentID = var.automq_byoc_env_id
}
}
Expand All @@ -54,4 +49,4 @@ resource "aws_volume_attachment" "data_volume_attachment" {
device_name = "/dev/sdh"
volume_id = aws_ebs_volume.data_volume.id
instance_id = aws_instance.automq_byoc_console.id
}
}
18 changes: 9 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
output "automq_byoc_env_id" {
description = "This parameter is used to create resources within the environment. Additionally, all cloud resource names will incorporate this parameter as part of their names. This parameter supports only numbers, uppercase and lowercase English letters, and hyphens. It must start with a letter and is limited to a length of 32 characters."
value = var.automq_byoc_env_id
value = var.automq_byoc_env_id
}

output "automq_byoc_endpoint" {
description = "The endpoint for the AutoMQ environment console. Users can set this endpoint to the AutoMQ Terraform Provider to manage resources through Terraform. Additionally, users can access this endpoint via web browser, log in, and manage resources within the environment using the WebUI."
value = "http://${aws_eip.web_ip.public_ip}:8080"
value = "http://${aws_eip.web_ip.public_ip}:8080"
}

output "automq_byoc_initial_username" {
description = "The initial username for the AutoMQ environment console. It has the `EnvironmentAdmin` role permissions. This account is used to log in to the environment, create ServiceAccounts, and manage other resources. For detailed information about environment members, please refer to the [documentation](https://docs.automq.com/automq-cloud/manage-identities-and-access/member-accounts)."
value = "admin"
value = "admin"
}

output "automq_byoc_initial_password" {
description = "The initial password for the AutoMQ environment console. This account is used to log in to the environment, create ServiceAccounts, and manage other resources. For detailed information about environment members, please refer to the [documentation](https://docs.automq.com/automq-cloud/manage-identities-and-access/member-accounts)."
value = aws_instance.automq_byoc_console.id
value = aws_instance.automq_byoc_console.id
}

output "automq_byoc_vpc_id" {
description = "The VPC ID for the AutoMQ environment deployment."
value = local.automq_byoc_vpc_id
value = local.automq_byoc_vpc_id
}

output "automq_byoc_instance_id" {
description = "The EC2 instance id for AutoMQ Console."
value = aws_instance.automq_byoc_console.id
value = aws_instance.automq_byoc_console.id
}

output "automq_byoc_console_role_arn" {
description = "AutoMQ BYOC is bound to the role arn of the Console."
value = aws_iam_role.automq_byoc_role.arn
value = aws_iam_role.automq_byoc_role.arn
}

output "automq_byoc_eks_node_role_arn" {
description = "AutoMQ BYOC requires this role to be bound to the EKS Node group."
value = aws_iam_role.automq_byoc_role.arn
value = aws_iam_role.automq_byoc_role.arn
}

/*
Expand Down Expand Up @@ -93,4 +93,4 @@ output "automq_byoc_env_console_cidr" {
description = "AutoMQ BYOC security group CIDR."
value = var.automq_byoc_env_console_cidr
}
*/
*/
Loading