The aws_api_gateway_deployment resource manages a snapshot of a REST API configuration. Once a deployment is created, it can be published to callable endpoints using the aws_api_gateway_stage resource.
To ensure that the deployment is recreated whenever the underlying API configuration changes (such as changes to resources, methods, or integrations), you must use the triggers argument. Using triggers is preferred over the depends_on meta-argument because triggers will force a redeployment, whereas depends_on only manages ordering.
Critical Requirement: Always include the lifecycle { create_before_destroy = true } block in your aws_api_gateway_deployment configuration. This prevents errors like BadRequestException: Active stages pointing to this deployment must be moved or deleted during redeployments.