-
Notifications
You must be signed in to change notification settings - Fork 0
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
Aws Flow module #10
Aws Flow module #10
Changes from all commits
df30680
dff2f62
f36253a
c01c55e
b6d985b
f1bb7eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~>3.0 | | ||
| <a name="requirement_illumio-cloudsecure"></a> [illumio-cloudsecure](#requirement\_illumio-cloudsecure) | ~> 1.0.11 | | ||
|
||
## Providers | ||
|
||
No providers. | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_aws_flows_dev"></a> [aws\_flows\_dev](#module\_aws\_flows\_dev) | github.com/illumio/terraform-illumio-cloudsecure//modules/aws_flows | v1.2.0 | | ||
|
||
## Resources | ||
|
||
No resources. | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_flow_logs_bucket_arns"></a> [flow\_logs\_bucket\_arns](#input\_flow\_logs\_bucket\_arns) | List of S3 buckets having flow logs | `list(string)` | n/a | yes | | ||
| <a name="input_illumio_cloudsecure_client_id"></a> [illumio\_cloudsecure\_client\_id](#input\_illumio\_cloudsecure\_client\_id) | The OAuth 2 client identifier used to authenticate against the CloudSecure Config API. | `string` | n/a | yes | | ||
| <a name="input_illumio_cloudsecure_client_secret"></a> [illumio\_cloudsecure\_client\_secret](#input\_illumio\_cloudsecure\_client\_secret) | The OAuth 2 client secret used to authenticate against the CloudSecure Config API. | `string` | n/a | yes | | ||
| <a name="input_illumio_cloudsecure_role_arn"></a> [illumio\_cloudsecure\_role\_arn](#input\_illumio\_cloudsecure\_role\_arn) | The ARN of the IAM role granted to the CloudSecure account. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
provider "aws" { | ||
region = "us-west-1" | ||
} | ||
|
||
provider "illumio-cloudsecure" { | ||
client_id = var.illumio_cloudsecure_client_id | ||
client_secret = var.illumio_cloudsecure_client_secret | ||
} | ||
|
||
module "aws_flows_dev" { | ||
source = "github.com/illumio/terraform-illumio-cloudsecure//modules/aws_flows?ref=v1.2.0" | ||
role_arn = var.illumio_cloudsecure_role_arn | ||
flow_logs_bucket_arns = var.flow_logs_bucket_arns | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||||||||||||
variable "flow_logs_bucket_arns" { | ||||||||||||||||||
type = list(string) | ||||||||||||||||||
description = "List of S3 buckets having flow logs" | ||||||||||||||||||
validation { | ||||||||||||||||||
condition = length(var.flow_logs_bucket_arns) > 0 | ||||||||||||||||||
error_message = "The flow_logs_bucket_arns value must not be empty." | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
Comment on lines
+1
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this. Give a concrete list of literal ARNs in the example to illustrate how to use the module.
Suggested change
You can see how we removed all variables other than client_id and client_secret from the other examples. |
||||||||||||||||||
variable "illumio_cloudsecure_client_id" { | ||||||||||||||||||
type = string | ||||||||||||||||||
description = "The OAuth 2 client identifier used to authenticate against the CloudSecure Config API." | ||||||||||||||||||
validation { | ||||||||||||||||||
condition = length(var.illumio_cloudsecure_client_id) > 1 | ||||||||||||||||||
error_message = "The illumio_cloudsecure_client_id value must not be empty." | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
variable "illumio_cloudsecure_client_secret" { | ||||||||||||||||||
type = string | ||||||||||||||||||
sensitive = true | ||||||||||||||||||
description = "The OAuth 2 client secret used to authenticate against the CloudSecure Config API." | ||||||||||||||||||
validation { | ||||||||||||||||||
condition = length(var.illumio_cloudsecure_client_secret) > 1 | ||||||||||||||||||
error_message = "The illumio_cloudsecure_client_secret value must not be empty." | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
variable "illumio_cloudsecure_role_arn" { | ||||||||||||||||||
type = string | ||||||||||||||||||
description = "The ARN of the IAM role granted to the CloudSecure account." | ||||||||||||||||||
validation { | ||||||||||||||||||
condition = length(var.illumio_cloudsecure_role_arn) > 1 | ||||||||||||||||||
error_message = "The illumio_cloudsecure_role_arn value must not be empty." | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
Comment on lines
+29
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this. Add an
Suggested change
You can see how we removed all variables other than client_id and client_secret from the other examples. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
illumio-cloudsecure = { | ||
source = "illumio/illumio-cloudsecure" | ||
version = "~> 1.0.11" | ||
} | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~>3.0" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
output "role_arn" { | ||
value = aws_iam_role.role.arn | ||
description = "The ARN of the IAM role granted to the CloudSecure account." | ||
} | ||
|
||
output "role_name" { | ||
value = aws_iam_role.role.name | ||
description = "The name of the IAM role granted to the CloudSecure account." | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.0 | | ||
| <a name="requirement_illumio-cloudsecure"></a> [illumio-cloudsecure](#requirement\_illumio-cloudsecure) | ~> 1.0.11 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | ~> 3.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.0 | | ||
| <a name="provider_illumio-cloudsecure"></a> [illumio-cloudsecure](#provider\_illumio-cloudsecure) | ~> 1.0.11 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_iam_role_policy.IllumioCloudBucketListPolicy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource | | ||
| [aws_iam_role_policy.IllumioCloudBucketReadPolicy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource | | ||
| [illumio-cloudsecure_aws_flow_logs_s3_bucket.buckets](https://registry.terraform.io/providers/illumio/illumio-cloudsecure/latest/docs/resources/aws_flow_logs_s3_bucket) | resource | | ||
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| [aws_iam_role.illumio_cloud_integration_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_role) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_flow_logs_bucket_arns"></a> [flow\_logs\_bucket\_arns](#input\_flow\_logs\_bucket\_arns) | List of S3 buckets having flow logs | `list(string)` | n/a | yes | | ||
| <a name="input_role_name"></a> [role\_name](#input\_role\_name) | The name of the IAM role granted to the CloudSecure account. | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the names consistent with the Terraform provider's resources. |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||||||
terraform { | ||||||||||
required_providers { | ||||||||||
illumio-cloudsecure = { | ||||||||||
source = "illumio/illumio-cloudsecure" | ||||||||||
version = "~> 1.0.11" | ||||||||||
} | ||||||||||
aws = { | ||||||||||
source = "hashicorp/aws" | ||||||||||
version = "~> 3.0" | ||||||||||
} | ||||||||||
random = { | ||||||||||
source = "hashicorp/random" | ||||||||||
version = "~> 3.0" | ||||||||||
} | ||||||||||
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove. Not needed.
Suggested change
|
||||||||||
} | ||||||||||
} | ||||||||||
Comment on lines
+1
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this into a separate |
||||||||||
|
||||||||||
locals { | ||||||||||
# Extract just the bucket ARN (without paths) for ListBucket actions | ||||||||||
flow_logs_bucket_list = [ | ||||||||||
for bucket_arn in var.flow_logs_bucket_arns : regex("^arn:aws:s3:::[^/]+", bucket_arn) | ||||||||||
] | ||||||||||
|
||||||||||
# Use the full ARN with path for GetObject actions | ||||||||||
flow_logs_bucket_read = [ | ||||||||||
for bucket_arn in var.flow_logs_bucket_arns : "${bucket_arn}/*" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also replace |
||||||||||
] | ||||||||||
} | ||||||||||
|
||||||||||
data "aws_iam_role" "illumio_cloud_integration_role" { | ||||||||||
name = var.role_name | ||||||||||
} | ||||||||||
|
||||||||||
resource "aws_iam_role_policy" "IllumioCloudBucketListPolicy" { | ||||||||||
count = length(local.flow_logs_bucket_list) > 0 ? 1 : 0 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove. The
Suggested change
|
||||||||||
name = "IllumioCloudBucketListPolicy" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hardcode names. Follow the same pattern as for |
||||||||||
role = data.aws_iam_role.illumio_cloud_integration_role.id | ||||||||||
policy = jsonencode({ | ||||||||||
Version = "2012-10-17" | ||||||||||
Statement = [{ | ||||||||||
Effect = "Allow" | ||||||||||
Sid = "IllumioBucketListAccess" | ||||||||||
Action = [ | ||||||||||
"s3:ListBucket", | ||||||||||
"s3:ListBucketVersion", | ||||||||||
"s3:GetBucketLocation" | ||||||||||
] | ||||||||||
Resource = local.flow_logs_bucket_list | ||||||||||
}] | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
resource "aws_iam_role_policy" "IllumioCloudBucketReadPolicy" { | ||||||||||
count = length(local.flow_logs_bucket_read) > 0 ? 1 : 0 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove. The
Suggested change
|
||||||||||
name = "IllumioCloudBucketReadPolicy" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hardcode names. Follow the same pattern as for |
||||||||||
role = data.aws_iam_role.illumio_cloud_integration_role.id | ||||||||||
policy = jsonencode({ | ||||||||||
Version = "2012-10-17" | ||||||||||
Statement = [{ | ||||||||||
Effect = "Allow" | ||||||||||
Sid = "IllumioBucketReadAccess" | ||||||||||
Action = ["s3:GetObject"] | ||||||||||
Resource = local.flow_logs_bucket_read | ||||||||||
}] | ||||||||||
}) | ||||||||||
} | ||||||||||
Comment on lines
+37
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just define one policy with two statements. |
||||||||||
|
||||||||||
# Data source to get the AWS account ID. | ||||||||||
data "aws_caller_identity" "current" {} | ||||||||||
|
||||||||||
|
||||||||||
// Onboards this AWS account with CloudSecure. | ||||||||||
resource "illumio-cloudsecure_aws_flow_logs_s3_bucket" "buckets" { | ||||||||||
for_each = toset(var.flow_logs_bucket_arns) | ||||||||||
account_id = data.aws_caller_identity.current.account_id | ||||||||||
s3_bucket_arn = each.key | ||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
variable "flow_logs_bucket_arns" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the naming of variables with the naming of attributes of the provider resource:
Suggested change
|
||||||
description = "List of S3 buckets having flow logs" | ||||||
type = list(string) | ||||||
validation { | ||||||
condition = length(var.flow_logs_bucket_arns) > 0 | ||||||
error_message = "The flow_logs_bucket_arns value must not be empty." | ||||||
} | ||||||
} | ||||||
|
||||||
variable "role_name" { | ||||||
description = "The name of the IAM role granted to the CloudSecure account." | ||||||
type = string | ||||||
validation { | ||||||
condition = length(var.role_name) > 1 | ||||||
error_message = "The role_name value must not be empty." | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modify this example to add an
aws_account
to show how those should be used together, instead of taking the role ARN as a variable.