Skip to content

Commit

Permalink
[#274] Add project name to IAM group names
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihisil committed Jan 8, 2024
1 parent d132c5c commit a53d21b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ export default class Generator extends Command {

const generalPrompt = await prompt<GeneralOptions>([...providerChoices]);

const projectName = args.projectName.toLowerCase().replace(/\s/g, '-');
const generalOptions: GeneralOptions = {
projectName: args.projectName,
projectName: projectName,
provider: generalPrompt.provider,
};

await this.generate(generalOptions);
await postProcess(generalOptions);

ux.info(
`The infrastructure code was generated at '${generalOptions.projectName}'`
);
ux.info(`The infrastructure code was generated at '${args.projectName}'`);
}

private async generate(generalOptions: GeneralOptions) {
Expand Down
2 changes: 2 additions & 0 deletions src/generators/addons/aws/modules/core/iamUserAndGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const iamVariablesContent = dedent`
const iamGroupsModuleContent = dedent`
module "iam_groups" {
source = "../modules/iam_groups"
project_name = local.project_name
}`;

const iamUsersModuleContent = dedent`
Expand Down
1 change: 1 addition & 0 deletions src/generators/terraform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const applyTerraformCore = async (generalOptions: GeneralOptions) => {
// Use projectName to append the Namespace local in the main.tf file
const coreLocalsContent = dedent`
locals {
project_name = "${projectName}"
env_namespace = "${projectName}-\${var.environment}"
}`;

Expand Down
6 changes: 3 additions & 3 deletions templates/addons/aws/modules/iam_groups/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#tfsec:ignore:aws-iam-enforce-group-mfa
resource "aws_iam_group" "admin" {
name = "Admin-group"
name = "${var.project_name}-admin-group"
}

#tfsec:ignore:aws-iam-enforce-group-mfa
resource "aws_iam_group" "infra-service-account" {
name = "Infra-service-account-group"
name = "${var.project_name}-infra-service-account-group"
}

#tfsec:ignore:aws-iam-enforce-group-mfa
resource "aws_iam_group" "developer" {
name = "Developer-group"
name = "${var.project_name}-developer-group"
}

resource "aws_iam_group_policy_attachment" "admin_access" {
Expand Down
4 changes: 4 additions & 0 deletions templates/addons/aws/modules/iam_groups/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "project_name" {
description = "The name of the project"
type = string
}

0 comments on commit a53d21b

Please sign in to comment.