Skip to content

Commit

Permalink
fix data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Feb 12, 2026
1 parent 227f8eb commit eee325c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
8 changes: 1 addition & 7 deletions common/data.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
37 changes: 37 additions & 0 deletions common/locals.tf
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion common/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit eee325c

Please sign in to comment.