コード例 #1
0
        /// <summary>
        /// Computes a URN from the combination of a resource name, resource type, optional parent,
        /// optional project and optional stack.
        /// </summary>
        /// <returns></returns>
        internal static Output <string> Create(
            Input <string> name, Input <string> type,
            Resource?parent, Input <string>?parentUrn,
            Input <string>?project, Input <string>?stack)
        {
            if (parent != null && parentUrn != null)
            {
                throw new ArgumentException("Only one of 'parent' and 'parentUrn' can be non-null.");
            }

            Output <string> parentPrefix;

            if (parent != null || parentUrn != null)
            {
                var parentUrnOutput = parent != null
                    ? parent.Urn
                    : parentUrn !.ToOutput();

                parentPrefix = parentUrnOutput.Apply(
                    parentUrnString => parentUrnString.Substring(
                        0, parentUrnString.LastIndexOf("::", StringComparison.Ordinal)) + "$");
            }
            else
            {
                parentPrefix = Output.Create($"urn:pulumi:{stack ?? Deployment.Instance.StackName}::{project ?? Deployment.Instance.ProjectName}::");
            }

            return(Output.Format($"{parentPrefix}{type}::{name}"));
        }