mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(cloudformation): resolve SecretTargetAttachment targets in the stack region (#3740)
Use the provisioning context region for RDS and DocumentDB target lookups.
This commit is contained in:
1 parent
573094720d
commit
cf235cfb81
3 files changed
+47
-41
No files matched your search
+14
-14
@@ -109,7 +109,7 @@ public class SecretTargetAttachmentCfnProvisioner implements CfnResourceProvisio
|
||||
String targetId = requireSecretTargetProperty(props, "TargetId", ctx);
|
||||
String targetType = requireSecretTargetProperty(props, "TargetType", ctx);
|
||||
validateSecretTargetType(targetType);
|
||||
SecretTargetConnection connection = resolveSecretTargetConnection(targetType, targetId);
|
||||
SecretTargetConnection connection = resolveSecretTargetConnection(targetType, targetId, region);
|
||||
|
||||
String previousSecretId = r.getPhysicalId();
|
||||
String previousManagedKeys = r.getAttributes().get(SECRET_TARGET_MANAGED_KEYS_ATTR);
|
||||
@@ -246,18 +246,18 @@ public class SecretTargetAttachmentCfnProvisioner implements CfnResourceProvisio
|
||||
"SecretString for AWS::SecretsManager::SecretTargetAttachment must be a JSON object.", 400);
|
||||
}
|
||||
|
||||
private SecretTargetConnection resolveSecretTargetConnection(String targetType, String targetId) {
|
||||
private SecretTargetConnection resolveSecretTargetConnection(String targetType, String targetId, String region) {
|
||||
return switch (targetType) {
|
||||
case "AWS::RDS::DBInstance" -> dbInstanceConnection(targetId);
|
||||
case "AWS::RDS::DBCluster" -> dbClusterConnection(targetId);
|
||||
case "AWS::DocDB::DBInstance" -> docDbInstanceConnection(targetId);
|
||||
case "AWS::DocDB::DBCluster" -> docDbClusterConnection(targetId);
|
||||
case "AWS::RDS::DBInstance" -> dbInstanceConnection(targetId, region);
|
||||
case "AWS::RDS::DBCluster" -> dbClusterConnection(targetId, region);
|
||||
case "AWS::DocDB::DBInstance" -> docDbInstanceConnection(targetId, region);
|
||||
case "AWS::DocDB::DBCluster" -> docDbClusterConnection(targetId, region);
|
||||
default -> throw new IllegalStateException("Validated target type was not handled: " + targetType);
|
||||
};
|
||||
}
|
||||
|
||||
private SecretTargetConnection dbInstanceConnection(String targetId) {
|
||||
DbInstance instance = rdsService.getDbInstance(targetId);
|
||||
private SecretTargetConnection dbInstanceConnection(String targetId, String region) {
|
||||
DbInstance instance = rdsService.getDbInstance(targetId, region);
|
||||
if (instance == null || instance.getEngine() == null || instance.getEndpoint() == null
|
||||
|| instance.getEndpoint().address() == null
|
||||
|| instance.getEndpoint().address().isBlank()
|
||||
@@ -275,8 +275,8 @@ public class SecretTargetAttachmentCfnProvisioner implements CfnResourceProvisio
|
||||
instance.getDbInstanceIdentifier());
|
||||
}
|
||||
|
||||
private SecretTargetConnection dbClusterConnection(String targetId) {
|
||||
DbCluster cluster = rdsService.getDbCluster(targetId);
|
||||
private SecretTargetConnection dbClusterConnection(String targetId, String region) {
|
||||
DbCluster cluster = rdsService.getDbCluster(targetId, region);
|
||||
if (cluster == null || cluster.getEngine() == null || cluster.getEndpoint() == null
|
||||
|| cluster.getEndpoint().address() == null
|
||||
|| cluster.getEndpoint().address().isBlank()
|
||||
@@ -294,8 +294,8 @@ public class SecretTargetAttachmentCfnProvisioner implements CfnResourceProvisio
|
||||
cluster.getDbClusterIdentifier());
|
||||
}
|
||||
|
||||
private SecretTargetConnection docDbInstanceConnection(String targetId) {
|
||||
DocDbInstance instance = docDbService.getDbInstance(targetId);
|
||||
private SecretTargetConnection docDbInstanceConnection(String targetId, String region) {
|
||||
DocDbInstance instance = docDbService.getDbInstance(targetId, region);
|
||||
if (instance == null || instance.getEndpoint() == null
|
||||
|| instance.getEndpoint().isBlank()
|
||||
|| instance.getPort() <= 0
|
||||
@@ -312,8 +312,8 @@ public class SecretTargetAttachmentCfnProvisioner implements CfnResourceProvisio
|
||||
instance.getDbInstanceIdentifier());
|
||||
}
|
||||
|
||||
private SecretTargetConnection docDbClusterConnection(String targetId) {
|
||||
DocDbCluster cluster = docDbService.getDbCluster(targetId);
|
||||
private SecretTargetConnection docDbClusterConnection(String targetId, String region) {
|
||||
DocDbCluster cluster = docDbService.getDbCluster(targetId, region);
|
||||
if (cluster == null || cluster.getEndpoint() == null
|
||||
|| cluster.getEndpoint().isBlank()
|
||||
|| cluster.getPort() <= 0
|
||||
|
||||
@@ -457,7 +457,10 @@ public class DocDbService {
|
||||
}
|
||||
|
||||
public DocDbCluster getDbCluster(String id) {
|
||||
String region = regionResolver.getRegion();
|
||||
return getDbCluster(id, regionResolver.getRegion());
|
||||
}
|
||||
|
||||
public DocDbCluster getDbCluster(String id, String region) {
|
||||
DocDbCluster cluster = findCluster(region, id).orElseThrow(() ->
|
||||
new AwsException("DBClusterNotFoundFault",
|
||||
"DocDB cluster " + id + " not found.", 404));
|
||||
@@ -706,7 +709,10 @@ public class DocDbService {
|
||||
}
|
||||
|
||||
public DocDbInstance getDbInstance(String id) {
|
||||
String region = regionResolver.getRegion();
|
||||
return getDbInstance(id, regionResolver.getRegion());
|
||||
}
|
||||
|
||||
public DocDbInstance getDbInstance(String id, String region) {
|
||||
DocDbInstance instance = findInstance(region, id).orElseThrow(() ->
|
||||
new AwsException("DBInstanceNotFound",
|
||||
"DocDB instance " + id + " not found.", 404));
|
||||
|
||||
Reference in new issue
Block a user