|
| 1 | +# Copyright 2025 Cloudera, Inc. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +terraform { |
| 16 | + required_version = ">= 1.5.7" |
| 17 | + required_providers { |
| 18 | + cdp = { |
| 19 | + source = "cloudera/cdp" |
| 20 | + version = ">= 0.6.1" |
| 21 | + } |
| 22 | + aws = { |
| 23 | + source = "hashicorp/aws" |
| 24 | + version = "~>5.30" |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +provider "aws" { |
| 30 | + region = var.aws_region |
| 31 | +} |
| 32 | + |
| 33 | +module "xaccount_iam_role" { |
| 34 | + source = "../../../terraform-aws-cred-permissions" |
| 35 | + |
| 36 | + tags = var.tags |
| 37 | + |
| 38 | + # Using CDP TF Provider cred pre-reqs data source for values of xaccount account_id and external_id |
| 39 | + xaccount_account_id = data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.account_id |
| 40 | + xaccount_external_id = data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.external_id |
| 41 | + |
| 42 | + xaccount_policy_name = "${var.env_prefix}-xaccount-policy" |
| 43 | + xaccount_account_policy_doc = base64decode(data.cdp_environments_aws_credential_prerequisites.cdp_prereqs.policy) |
| 44 | + |
| 45 | + xaccount_role_name = "${var.env_prefix}-xaccount-role" |
| 46 | + |
| 47 | + # Create assume role trust relationship required for CML backup and restore |
| 48 | + create_cml_assume_role_policy = true |
| 49 | +} |
| 50 | + |
| 51 | +module "ex01_minimal_inputs" { |
| 52 | + source = "../.." |
| 53 | + |
| 54 | + tags = var.tags |
| 55 | + |
| 56 | + cml_backup_policy_name = "${var.env_prefix}-cml-backup-policy" |
| 57 | + cml_restore_policy_name = "${var.env_prefix}-cml-restore-policy" |
| 58 | + |
| 59 | + xaccount_role_name = module.xaccount_iam_role.aws_xaccount_role_name |
| 60 | + |
| 61 | + depends_on = [module.xaccount_iam_role] |
| 62 | +} |
| 63 | + |
| 64 | +# Use the CDP Terraform Provider to find the xaccount account and external ids |
| 65 | +data "cdp_environments_aws_credential_prerequisites" "cdp_prereqs" {} |
| 66 | + |
| 67 | +# ------- Outputs ------- |
| 68 | +output "xaccount_role_arn" { |
| 69 | + value = module.xaccount_iam_role.aws_xaccount_role_arn |
| 70 | + |
| 71 | + description = "The ARN of the created Cross Account Role" |
| 72 | +} |
0 commit comments