From d9d0f8d18454f62b311dd647657efe2cdac0b800 Mon Sep 17 00:00:00 2001 From: Fabrizio Branca Date: Tue, 18 Oct 2016 11:09:53 +0000 Subject: [PATCH] Ignore AWS_UNSET_PROFILE in [profile:...] --- .../ValueResolver/Stage/ProfileSwitcher.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/StackFormation/ValueResolver/Stage/ProfileSwitcher.php b/src/StackFormation/ValueResolver/Stage/ProfileSwitcher.php index 5b296eb..b120267 100644 --- a/src/StackFormation/ValueResolver/Stage/ProfileSwitcher.php +++ b/src/StackFormation/ValueResolver/Stage/ProfileSwitcher.php @@ -10,6 +10,11 @@ public function invoke($string) $string = preg_replace_callback( '/\[profile:([^:\]\[]+?):([^\]\[]+?)\]/', function ($matches) { + + // [profile:...] ignores AWS_UNSET_PROFILE. Backup up value here + $unsetProfileBackup = getenv('AWS_UNSET_PROFILE'); + putenv('AWS_UNSET_PROFILE'); + // recursively create another ValueResolver, but this time with a different profile $subValueResolver = new \StackFormation\ValueResolver\ValueResolver( $this->valueResolver->getDependencyTracker(), @@ -17,7 +22,13 @@ function ($matches) { $this->valueResolver->getConfig(), $matches[1] ); - return $subValueResolver->resolvePlaceholders($matches[2], $this->sourceBlueprint, $this->sourceType, $this->sourceKey); + $value = $subValueResolver->resolvePlaceholders($matches[2], $this->sourceBlueprint, $this->sourceType, $this->sourceKey); + + // restoring AWS_UNSET_PROFILE value if it was set before + if ($unsetProfileBackup) { + putenv('AWS_UNSET_PROFILE=1'); + } + return $value; }, $string );