Add Output.concat to Python (#3006)

Fixes #2366
This commit is contained in:
Luke Hoban 2019-07-31 11:35:05 -07:00 committed by GitHub
parent 6804d640fc
commit 3d4c01abeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -3,9 +3,11 @@ CHANGELOG
## Unreleased
- Add `Ouput.concat` to Python SDK [#3006](https://github.com/pulumi/pulumi/pull/3006)
### Compatibility
* Deprecated functions in `@pulumi/pulumi` will now issue warnings if you call them. Please migrate
- Deprecated functions in `@pulumi/pulumi` will now issue warnings if you call them. Please migrate
off of these functions as they will be removed in a future release. The deprecated functions are.
1. `function computeCodePaths(extraIncludePaths?: string[], ...)`. Use the `computeCodePaths`
overload that takes a `CodePathOptions` instead.

View file

@ -317,3 +317,21 @@ class Output(Generic[T]):
known_futures = asyncio.ensure_future(is_known(all_outputs))
secret_futures = asyncio.ensure_future(is_secret(all_outputs))
return Output(resources, value_futures, known_futures, secret_futures)
@staticmethod
def concat(*args: List[Input[str]]) -> 'Output[str]':
"""
Concatenates a collection of Input[str] into a single Output[str].
This function takes a sequence of Input[str], stringifies each, and concatenates all values
into one final string. This can be used like so:
url = Output.concat("http://", server.hostname, ":", loadBalancer.port)
:param List[Input[str]] args: A list of string Inputs to concatenate.
:return: A concatenated output string.
:rtype: Output[str]
"""
transformed_items = [Output.from_input(v) for v in args]
return Output.all(*transformed_items).apply("".join)

View file

@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pulumi import Output, CustomResource
from pulumi import Output, CustomResource, export
class MyResource(CustomResource):
number: Output[str]
@ -43,3 +43,7 @@ res2.number.apply(lambda n: assert_eq(n, 3))
# Output.all combines a list of outputs into an output of a list.
resSum = Output.all(res1.number, res2.number).apply(lambda l: l[0] + l[1])
FinalResource("testResource3", resSum)
# Test additional Output helpers
hello_world = Output.concat("Hello ", Output.from_input("world!")).apply(lambda s: assert_eq(s, "Hello world!"))
export("helloworld", hello_world)