From eee325cb074ae7d8b2a6a281ec667fc075f7a578 Mon Sep 17 00:00:00 2001 From: "Matthew C. Morgan" Date: Thu, 12 Feb 2026 16:57:03 -0500 Subject: [PATCH] fix data sources --- common/data.tf | 8 +------- common/locals.tf | 37 +++++++++++++++++++++++++++++++++++++ common/outputs.tf | 2 +- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/common/data.tf b/common/data.tf index 8a542a9..8f58564 100644 --- a/common/data.tf +++ b/common/data.tf @@ -1,9 +1,3 @@ -# List portfolios to find by name pattern -data "aws_servicecatalog_portfolios" "all" { - count = var.portfolio_id == null ? 1 : 0 - accept_language = var.accept_language -} - # Get portfolio details if we provided the ID data "aws_servicecatalog_portfolio" "by_id" { count = var.portfolio_id != null ? 1 : 0 @@ -21,7 +15,7 @@ data "aws_servicecatalog_product" "by_id" { # Get the latest provisioning artifact (product version) data "aws_servicecatalog_provisioning_artifacts" "this" { accept_language = var.accept_language - product_id = var.product_id != null ? var.product_id : var.product_id + product_id = var.product_id } # Get CloudFormation stack outputs if provisioned product exists diff --git a/common/locals.tf b/common/locals.tf index e41bf43..5c23343 100644 --- a/common/locals.tf +++ b/common/locals.tf @@ -1,2 +1,39 @@ # Intentionally empty file for consistency with aws-s3 pattern # Module-specific locals should be defined in each submodule + +locals { + # Portfolio ID must be specified + portfolio_id = var.portfolio_id + + # Product ID must be specified + product_id = var.product_id + + # Get the latest provisioning artifact ID + latest_artifact_id = try( + [for artifact in data.aws_servicecatalog_provisioning_artifacts.this.provisioning_artifact_details : + artifact.id if artifact.active + ][0], + null + ) + + # Use provided path_id or default to latest + provisioning_artifact_id = var.path_id != null ? var.path_id : local.latest_artifact_id + + # Merge default parameters with user-provided parameters + default_parameters = {} + + parameters = merge( + local.default_parameters, + var.parameters + ) + + # Convert parameters map to the format expected by aws_servicecatalog_provisioned_product + provisioning_parameters = [ + for key, value in local.parameters : { + key = key + value = tostring(value) + } + ] + + module_name = try(data.aws_servicecatalog_product.by_id[0].name, "Unknown") +} \ No newline at end of file diff --git a/common/outputs.tf b/common/outputs.tf index 8db182f..d0cf5d6 100644 --- a/common/outputs.tf +++ b/common/outputs.tf @@ -30,7 +30,7 @@ output "provisioned_product_status_message" { output "cloudformation_stack_arn" { description = "The ARN of the CloudFormation stack" - value = aws_servicecatalog_provisioned_product.this.cloudformation_stack_arn + value = var.retrieve_stack_outputs ? try(data.aws_cloudformation_stack.this[0].stack_id, null) : null } output "launch_role_arn" {