-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from chkp-meravbe/mb-aws-tf-add-iam-role-gwlb
merging two branches
- Loading branch information
Showing
14 changed files
with
312 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# AWS IAM Role for Cloud Management Extension (CME) manages Gateway Load Balancer Auto Scale Group Terraform module | ||
|
||
Terraform module which creates an AWS IAM Role for Cloud Management Extension (CME) manages Gateway Load Balancer Auto Scale Group on Security Management Server. | ||
|
||
These types of Terraform resources are supported: | ||
* [AWS IAM role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | ||
* [AWS IAM policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | ||
* [AWS IAM policy attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | ||
|
||
This type of Terraform data source is supported: | ||
* [AWS IAM policy document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | ||
|
||
See the [Creating an AWS IAM Role for Security Management Server](https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk122074) for additional information | ||
|
||
## Configurations | ||
|
||
The **main.tf** file includes the following provider configuration block used to configure the credentials for the authentication with AWS, as well as a default region for your resources: | ||
``` | ||
provider "aws" { | ||
region = var.region | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
} | ||
``` | ||
The provider credentials can be provided either as static credentials or as [Environment Variables](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#environment-variables). | ||
- Static credentials can be provided by adding an access_key and secret_key in /terraform/aws/cme-iam-role-gwlb/**terraform.tfvars** file as follows: | ||
``` | ||
region = "us-east-1" | ||
access_key = "my-access-key" | ||
secret_key = "my-secret-key" | ||
``` | ||
- In case the Environment Variables are used, perform modifications described below:<br/> | ||
a. The next lines in main.tf file, in the provider aws resource, need to be commented: | ||
``` | ||
provider "aws" { | ||
// region = var.region | ||
// access_key = var.access_key | ||
// secret_key = var.secret_key | ||
} | ||
``` | ||
|
||
## Usage | ||
- Fill all variables in the /terraform/aws/cme-iam-role-gwlb/**terraform.tfvars** file with proper values (see below for variables descriptions). | ||
- From a command line initialize the Terraform configuration directory: | ||
``` | ||
terraform init | ||
``` | ||
- Create an execution plan: | ||
``` | ||
terraform plan | ||
``` | ||
- Create or modify the deployment: | ||
``` | ||
terraform apply | ||
``` | ||
- Variables are configured in /terraform/aws/cme-iam-role-gwlb/**terraform.tfvars** file as follows: | ||
``` | ||
//PLEASE refer to README.md for accepted values FOR THE VARIABLES BELOW | ||
|
||
permissions = "Create with read permissions" | ||
sts_roles = ['arn:aws:iam::111111111111:role/role_name'] | ||
trusted_account = "" | ||
``` | ||
- To tear down your resources: | ||
``` | ||
terraform destroy | ||
``` | ||
## Inputs | ||
| Name | Description | Type | Allowed values | Default | Required | | ||
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|----------| | ||
| permissions | The IAM role permissions | string | - Create with assume role permissions (specify an STS role ARN) <br/> - Create with read permissions <br/> - Create with read-write permissions | Create with read permissions | no | | ||
| sts_roles | The IAM role will be able to assume these STS Roles (map of string ARNs) | list(string) | n/a | [] | no | | ||
| trusted_account | A 12 digits number that represents the ID of a trusted account. IAM users in this account will be able assume the IAM role and receive the permissions attached to it | string | n/a | "" | no | | ||
## Outputs | ||
| Name | Description | | ||
|----------------------|---------------------------------------| | ||
| cme_iam_role_arn | The created AWS IAM Role arn | | ||
| cme_iam_role_name | The created AWS IAM Role name | | ||
| cme_iam_profile_name | The created AWS instance profile name | | ||
| cme_iam_profile_arn | The created AWS instance profile arn | | ||
## Revision History | ||
In order to check the template version, please refer to [sk116585](https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk116585) | ||
| Template Version | Description | | ||
|------------------|--------------------------------------------------------------------| | ||
| 20230926 | CME instance profile for IAM Role | | ||
## License | ||
This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
provider "aws" { | ||
region = var.region | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
} | ||
|
||
resource "aws_iam_role" "cme_iam_role_gwlb" { | ||
assume_role_policy = data.aws_iam_policy_document.cme_role_assume_policy_document.json | ||
path = "/" | ||
} | ||
|
||
data "aws_iam_policy_document" "cme_role_assume_policy_document" { | ||
version = "2012-10-17" | ||
statement { | ||
effect = "Allow" | ||
actions = ["sts:AssumeRole"] | ||
principals { | ||
type = var.trusted_account == "" ? "Service" : "AWS" | ||
identifiers = var.trusted_account == "" ? ["ec2.amazonaws.com"] : [var.trusted_account] | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
provided_sts_roles = length(var.sts_roles) == 0 ? 0 : 1 | ||
allow_read_permissions = var.permissions == "Create with read-write permissions" || var.permissions == "Create with read permissions" ? 1 : 0 | ||
allow_write_permissions = var.permissions == "Create with read-write permissions" ? 1 : 0 | ||
} | ||
|
||
data "aws_iam_policy_document" "cme_role_sts_policy_doc" { | ||
version = "2012-10-17" | ||
statement { | ||
effect = "Allow" | ||
actions = ["sts:AssumeRole"] | ||
resources = var.sts_roles | ||
} | ||
} | ||
resource "aws_iam_policy" "cme_role_sts_policy" { | ||
count = local.provided_sts_roles | ||
policy = data.aws_iam_policy_document.cme_role_sts_policy_doc.json | ||
|
||
} | ||
resource "aws_iam_role_policy_attachment" "attach_sts_policy" { | ||
count = local.provided_sts_roles | ||
policy_arn = aws_iam_policy.cme_role_sts_policy[0].arn | ||
role = aws_iam_role.cme_iam_role_gwlb.id | ||
} | ||
|
||
data "aws_iam_policy_document" "cme_role_read_policy_doc" { | ||
version = "2012-10-17" | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"autoscaling:DescribeAutoScalingGroups", | ||
"ec2:DescribeInstances", | ||
"ec2:DescribeNetworkInterfaces", | ||
"ec2:DescribeRouteTables", | ||
"ec2:DescribeSecurityGroups", | ||
"ec2:DescribeSubnets", | ||
"ec2:DescribeVpcs", | ||
"ec2:DescribeInternetGateways", | ||
"ec2:DescribeVpcEndpoints", | ||
"ec2:DescribeVpcEndpointServiceConfigurations", | ||
"elasticloadbalancing:DescribeLoadBalancers", | ||
"elasticloadbalancing:DescribeTags", | ||
"elasticloadbalancing:DescribeListeners", | ||
"elasticloadbalancing:DescribeTargetGroups", | ||
"elasticloadbalancing:DescribeRules", | ||
"elasticloadbalancing:DescribeTargetHealth"] | ||
resources = ["*"] | ||
} | ||
} | ||
resource "aws_iam_policy" "cme_role_read_policy" { | ||
count = local.allow_read_permissions | ||
policy = data.aws_iam_policy_document.cme_role_read_policy_doc.json | ||
} | ||
resource "aws_iam_role_policy_attachment" "attach_read_policy" { | ||
count = local.allow_read_permissions | ||
policy_arn = aws_iam_policy.cme_role_read_policy[0].arn | ||
role = aws_iam_role.cme_iam_role_gwlb.id | ||
} | ||
|
||
data "aws_iam_policy_document" "cme_role_write_policy_doc" { | ||
version = "2012-10-17" | ||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"ec2:CreateRoute", | ||
"ec2:ReplaceRoute", | ||
"ec2:DeleteRoute", | ||
"ec2:CreateRouteTable", | ||
"ec2:AssociateRouteTable", | ||
"ec2:CreateTags" | ||
] | ||
resources = ["*"] | ||
} | ||
} | ||
resource "aws_iam_policy" "cme_role_write_policy" { | ||
count = local.allow_write_permissions | ||
policy = data.aws_iam_policy_document.cme_role_write_policy_doc.json | ||
} | ||
resource "aws_iam_role_policy_attachment" "attach_write_policy" { | ||
count = local.allow_write_permissions | ||
policy_arn = aws_iam_policy.cme_role_write_policy[0].arn | ||
role = aws_iam_role.cme_iam_role_gwlb.id | ||
} | ||
resource "aws_iam_instance_profile" "iam_instance_profile" { | ||
role = aws_iam_role.cme_iam_role_gwlb.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
output "cme_iam_role_arn" { | ||
value = aws_iam_role.cme_iam_role_gwlb.arn | ||
} | ||
output "cme_iam_role_name" { | ||
value = aws_iam_role.cme_iam_role_gwlb.name | ||
} | ||
output "cme_iam_profile_name" { | ||
value = aws_iam_instance_profile.iam_instance_profile.name | ||
} | ||
output "cme_iam_profile_arn" { | ||
value = aws_iam_instance_profile.iam_instance_profile.arn | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//PLEASE refer to README.md for accepted values FOR THE VARIABLES BELOW | ||
|
||
permissions = "Create with read permissions" | ||
sts_roles = [] | ||
trusted_account = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Module: IAM role for selected permissions | ||
|
||
// --- AWS Provider --- | ||
variable "region" { | ||
type = string | ||
description = "AWS region" | ||
default = "" | ||
} | ||
variable "access_key" { | ||
type = string | ||
description = "AWS access key" | ||
default = "" | ||
} | ||
variable "secret_key" { | ||
type = string | ||
description = "AWS secret key" | ||
default = "" | ||
} | ||
|
||
variable "permissions" { | ||
type = string | ||
description = "The IAM role permissions" | ||
default = "Create with read permissions" | ||
} | ||
locals { | ||
permissions_allowed_values = [ | ||
"Create with assume role permissions (specify an STS role ARN)", | ||
"Create with read permissions", | ||
"Create with read-write permissions"] | ||
// Will fail if var.permissions is invalid | ||
validate_permissions = index(local.permissions_allowed_values, var.permissions) | ||
} | ||
variable "sts_roles" { | ||
type = list(string) | ||
description = "The IAM role will be able to assume these STS Roles (map of string ARNs)" | ||
default = [] | ||
} | ||
variable "trusted_account" { | ||
type = string | ||
description = "A 12 digits number that represents the ID of a trusted account. IAM users in this account will be able assume the IAM role and receive the permissions attached to it" | ||
default = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_version = ">= 0.14.3" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 3.24.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.