-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module for CML on AWS permissions (#94)
Signed-off-by: Jim Enright <jenright@cloudera.com>
- Loading branch information
Showing
19 changed files
with
482 additions
and
11 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
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,61 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
# Terraform Module for AWS IAM Permissions for CML | ||
|
||
This module contains resource files and example variable definition files for creation of the AWS IAM policies required for the Cloudera Machine Learning (CML) backup and restore functionality. This requirement is described [in this section](https://docs.cloudera.com/machine-learning/cloud/workspaces/topics/ml-backup-restore-prerequisites.html) of the CML documentation. | ||
|
||
## Usage | ||
|
||
The [examples](./examples) directory has an example AWS IAM policy creation on AWS: | ||
|
||
* `ex01-minimal-inputs` uses the minimum set of inputs for the module. | ||
|
||
An example `terraform.tfvars.sample` values file is included to show input variable values. | ||
|
||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~>5.30 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~>5.30 | | ||
| <a name="provider_http"></a> [http](#provider\_http) | n/a | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_iam_policy.cml_backup_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | ||
| [aws_iam_policy.cml_restore_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | ||
| [aws_iam_role_policy_attachment.cdp_xaccount_role_cml_backup_attach](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | ||
| [aws_iam_role_policy_attachment.cdp_xaccount_role_cml_restore_attach](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | ||
| [aws_iam_role.xaccount_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_role) | data source | | ||
| [http_http.cml_backup_policy_doc](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | | ||
| [http_http.cml_restore_policy_doc](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_cml_backup_policy_name"></a> [cml\_backup\_policy\_name](#input\_cml\_backup\_policy\_name) | CDP CML Backup Policy name | `string` | n/a | yes | | ||
| <a name="input_cml_restore_policy_name"></a> [cml\_restore\_policy\_name](#input\_cml\_restore\_policy\_name) | CDP CML Restore Policy name | `string` | n/a | yes | | ||
| <a name="input_xaccount_role_name"></a> [xaccount\_role\_name](#input\_xaccount\_role\_name) | Name of existing cross account Assume role Name. | `string` | n/a | yes | | ||
| <a name="input_cml_backup_policy_doc"></a> [cml\_backup\_policy\_doc](#input\_cml\_backup\_policy\_doc) | Contents of CDP CML Backup Policy Document. If not specified document is downloaded from Cloudera Document repository | `string` | `null` | no | | ||
| <a name="input_cml_restore_policy_doc"></a> [cml\_restore\_policy\_doc](#input\_cml\_restore\_policy\_doc) | Contents of CDP CML Restore Policy Document. If not specified document is downloaded from Cloudera Document repository | `string` | `null` | no | | ||
| <a name="input_tags"></a> [tags](#input\_tags) | Tags applied to provised resources | `map(any)` | `null` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_aws_cml_backup_policy_arn"></a> [aws\_cml\_backup\_policy\_arn](#output\_aws\_cml\_backup\_policy\_arn) | CML Backup IAM Policy ARN | | ||
| <a name="output_aws_cml_restore_policy_arn"></a> [aws\_cml\_restore\_policy\_arn](#output\_aws\_cml\_restore\_policy\_arn) | CML Restore IAM Policy ARN | | ||
<!-- END_TF_DOCS --> |
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,29 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
data "aws_iam_role" "xaccount_role" { | ||
|
||
name = var.xaccount_role_name | ||
} | ||
|
||
# HTTP get request to download policy documents | ||
# ..CML Backup Policy | ||
data "http" "cml_backup_policy_doc" { | ||
url = "https://docs.cloudera.com/machine-learning/cloud/cml-backup-policy.json" | ||
} | ||
|
||
# ..CML Restore Policy | ||
data "http" "cml_restore_policy_doc" { | ||
url = "https://docs.cloudera.com/machine-learning/cloud/cml-restore-policy.json" | ||
} |
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,23 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
locals { | ||
|
||
# CML Backup Policy document | ||
cml_backup_policy_doc = coalesce(var.cml_backup_policy_doc, data.http.cml_backup_policy_doc.response_body) | ||
|
||
# CML Backup Policy document | ||
cml_restore_policy_doc = coalesce(var.cml_restore_policy_doc, data.http.cml_restore_policy_doc.response_body) | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
modules/terraform-aws-cml-permissions/doc_fragments/header.md
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,11 @@ | ||
# Terraform Module for AWS IAM Permissions for CML | ||
|
||
This module contains resource files and example variable definition files for creation of the AWS IAM policies required for the Cloudera Machine Learning (CML) backup and restore functionality. This requirement is described [in this section](https://docs.cloudera.com/machine-learning/cloud/workspaces/topics/ml-backup-restore-prerequisites.html) of the CML documentation. | ||
|
||
## Usage | ||
|
||
The [examples](./examples) directory has an example AWS IAM policy creation on AWS: | ||
|
||
* `ex01-minimal-inputs` uses the minimum set of inputs for the module. | ||
|
||
An example `terraform.tfvars.sample` values file is included to show input variable values. |
72 changes: 72 additions & 0 deletions
72
modules/terraform-aws-cml-permissions/examples/ex01-minimal-inputs/main.tf
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,72 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
required_version = ">= 1.5.7" | ||
required_providers { | ||
cdp = { | ||
source = "cloudera/cdp" | ||
version = ">= 0.6.1" | ||
} | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~>5.30" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.aws_region | ||
} | ||
|
||
module "xaccount_iam_role" { | ||
source = "../../../terraform-aws-cred-permissions" | ||
|
||
tags = var.tags | ||
|
||
# Using CDP TF Provider cred pre-reqs data source for values of xaccount account_id and external_id | ||
xaccount_account_id = data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.account_id | ||
xaccount_external_id = data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.external_id | ||
|
||
xaccount_policy_name = "${var.env_prefix}-xaccount-policy" | ||
xaccount_account_policy_doc = base64decode(data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.policy) | ||
|
||
xaccount_role_name = "${var.env_prefix}-xaccount-role" | ||
|
||
# Create assume role trust relationship required for CML backup and restore | ||
create_cml_assume_role_policy = true | ||
} | ||
|
||
module "ex01_minimal_inputs" { | ||
source = "../.." | ||
|
||
tags = var.tags | ||
|
||
cml_backup_policy_name = "${var.env_prefix}-cml-backup-policy" | ||
cml_restore_policy_name = "${var.env_prefix}-cml-restore-policy" | ||
|
||
xaccount_role_name = module.xaccount_iam_role.aws_xaccount_role_name | ||
|
||
depends_on = [module.xaccount_iam_role] | ||
} | ||
|
||
# Use the CDP Terraform Provider to find the xaccount account and external ids | ||
data "cdp_environments_aws_credential_prerequisites" "cdp_prereqs" {} | ||
|
||
# ------- Outputs ------- | ||
output "xaccount_role_arn" { | ||
value = module.xaccount_iam_role.aws_xaccount_role_arn | ||
|
||
description = "The ARN of the created Cross Account Role" | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/terraform-aws-cml-permissions/examples/ex01-minimal-inputs/terraform.tfvars.sample
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,27 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# ------- Global settings ------- | ||
env_prefix = "<ENTER_VALUE>" # Required name prefix for cloud and CDP resources, e.g. cldr1 | ||
|
||
# ------- Cloud Settings ------- | ||
aws_region = "<ENTER_VALUE>" # Change this to specify Cloud Provider region, e.g. eu-west-1 | ||
|
||
# ------- Resource Tagging ------- | ||
# **NOTE: An example of how to specify tags is below; uncomment & edit if required | ||
tags = { | ||
owner = "<ENTER_VALUE>" | ||
project = "<ENTER_VALUE>" | ||
enddate = "<ENTER_VALUE>" | ||
} |
31 changes: 31 additions & 0 deletions
31
modules/terraform-aws-cml-permissions/examples/ex01-minimal-inputs/variables.tf
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,31 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# ------- Global settings ------- | ||
variable "aws_region" { | ||
type = string | ||
description = "Region which Cloud resources will be created" | ||
} | ||
|
||
variable "env_prefix" { | ||
type = string | ||
description = "Shorthand name for the environment. Used in resource descriptions" | ||
} | ||
|
||
variable "tags" { | ||
type = map(any) | ||
description = "Tags applied to provised resources" | ||
|
||
default = null | ||
} |
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,44 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# ------- Cross Account Policy ------- | ||
resource "aws_iam_policy" "cml_backup_policy" { | ||
name = var.cml_backup_policy_name | ||
description = "CDP CML Workspace Backup policy" | ||
|
||
tags = merge(var.tags, { Name = var.cml_backup_policy_name }) | ||
|
||
policy = local.cml_backup_policy_doc | ||
} | ||
|
||
resource "aws_iam_policy" "cml_restore_policy" { | ||
name = var.cml_restore_policy_name | ||
description = "CDP CML Workspace Restore policy" | ||
|
||
tags = merge(var.tags, { Name = var.cml_restore_policy_name }) | ||
|
||
policy = local.cml_restore_policy_doc | ||
} | ||
|
||
# Attach CML backup policy to the xaccount role | ||
resource "aws_iam_role_policy_attachment" "cdp_xaccount_role_cml_backup_attach" { | ||
role = data.aws_iam_role.xaccount_role.name | ||
policy_arn = aws_iam_policy.cml_backup_policy.arn | ||
} | ||
|
||
# Attach CML restore policy to the xaccount role | ||
resource "aws_iam_role_policy_attachment" "cdp_xaccount_role_cml_restore_attach" { | ||
role = data.aws_iam_role.xaccount_role.name | ||
policy_arn = aws_iam_policy.cml_restore_policy.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,25 @@ | ||
# Copyright 2025 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
output "aws_cml_backup_policy_arn" { | ||
value = aws_iam_policy.cml_backup_policy.arn | ||
|
||
description = "CML Backup IAM Policy ARN" | ||
} | ||
|
||
output "aws_cml_restore_policy_arn" { | ||
value = aws_iam_policy.cml_restore_policy.arn | ||
|
||
description = "CML Restore IAM Policy 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,28 @@ | ||
# Copyright 2023 Cloudera, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~>5.30" | ||
} | ||
http = { | ||
source = "hashicorp/http" | ||
version = ">= 3.2.1" | ||
} | ||
} | ||
|
||
required_version = ">= 1.3.0" | ||
} |
Oops, something went wrong.