Skip to content

Commit

Permalink
Azure.Provisioning - add BicepFunction.Concat (#45936)
Browse files Browse the repository at this point in the history
  • Loading branch information
tg-msft authored Sep 12, 2024
1 parent fa3fac3 commit ed7ce4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ await test.Define(
BicepVariable funcAppName =
new(nameof(funcAppName), typeof(string))
{
Value = BicepFunction.Interpolate($"functionApp-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}")
Value = BicepFunction.Concat("functionApp-", BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id))
};
WebSite functionApp =
Expand Down Expand Up @@ -148,7 +148,7 @@ await test.Define(
}
}

var funcAppName = 'functionApp-${uniqueString(resourceGroup().id)}'
var funcAppName = concat('functionApp-', uniqueString(resourceGroup().id))

resource functionApp 'Microsoft.Web/sites@2023-12-01' = {
name: funcAppName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ public ArrayExpression(params Azure.Provisioning.Expressions.Expression[] values
public static partial class BicepFunction
{
public static Azure.Provisioning.BicepValue<string> AsString(Azure.Provisioning.BicepValue<object> value) { throw null; }
public static Azure.Provisioning.BicepValue<string> Concat(params Azure.Provisioning.BicepValue<string>[] values) { throw null; }
public static Azure.Provisioning.BicepValue<string> CreateGuid(params Azure.Provisioning.BicepValue<string>[] values) { throw null; }
public static Azure.Provisioning.Resources.ArmDeployment GetDeployment() { throw null; }
public static Azure.Provisioning.Resources.ResourceGroup GetResourceGroup() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,26 @@ public static BicepValue<string> ToLower(BicepValue<object> value) =>
public static BicepValue<string> ToUpper(BicepValue<object> value) =>
BicepSyntax.Call("toUpper", value.Compile());

/// <summary>
/// Combines multiple string values <paramref name="values"/> and returns
/// the concatenated string. This represents the <c>concat</c> Bicep
/// function. To improve readability, prefer
/// <see cref="BicepFunction.Interpolate"/> instead of
/// <see cref="Concat"/>.
/// </summary>
/// <param name="values">Strings in sequential order for concatenation.</param>
/// <returns>A string or array of concatenated values.</returns>
/// <remarks>
/// See the
/// <see href="https://learn.microsoft.com/azure/azure-resource-manager/bicep/bicep-functions-string#concat">
/// Bicep Functions Reference</see> for more.
/// </remarks>
public static BicepValue<string> Concat(params BicepValue<string>[] values)
{
if (values.Length < 1) { throw new ArgumentException($"{nameof(Concat)} requires at least one value.", nameof(values)); }
return BicepSyntax.Call("concat", values.Select(v => v.Compile()).ToArray());
}

/// <summary>
/// Convert a formattable string with literal text, C# expressions, and
/// Bicep expressions into an interpolated Bicep string.
Expand Down

0 comments on commit ed7ce4b

Please sign in to comment.