Example #1
0
        private static ResourceTransformationResult?Transform(ResourceTransformationArgs args)
        {
            var ambientSubscription = Ambient.Value;

            if (ambientSubscription == null)
            {
                return(null);
            }

            if (!args.Resource.IsAzureNextGenResource() || args.Resource is Provider)
            {
                return(null);
            }

            if (args.Options?.Provider != null)
            {
                Log.Debug($"The Ambient Subscription `{ambientSubscription.SubscriptionId}` could not be applied as this resource already has a provider applied to it");
                return(null);
            }

            var options = args.Options.CloneFor(args.Resource);

            options.Provider = ambientSubscription.AzureNextGenProvider;
            return(new ResourceTransformationResult(args.Args, options));
        }
Example #2
0
        private static ResourceTransformationResult?Transform(ResourceTransformationArgs args)
        {
            if (!args.Resource.IsAzureNextGenResource() || args.Resource is Provider)
            {
                return(null);
            }

            var nameProperty = args.Args.GetNameProperty();

            if (nameProperty == null)
            {
                Log.Debug($"Not applying auto-naming - could not find a matching name property for the resource args type `{args.Args.GetType()}`");
                return(null);
            }

            var existingName = nameProperty.GetValue(args.Args);

            if (existingName != null)
            {
                Log.Debug("Not applying auto-naming - a name is already manually specified");
                return(null);
            }

            var clonedArgs = args.Args.Clone();

            nameProperty.SetInputValue(clonedArgs, args.Resource.GetResourceName());

            return(new ResourceTransformationResult(clonedArgs, args.Options));
        }
        public static ResourceTransformationResult?AddLocation(ResourceTransformationArgs res)
        {
            var locationProp = res.Args.GetType().GetProperty("Location");

            if (locationProp is null)
            {
                return(null);
            }

            locationProp.SetValue(res.Args, (Input <string>) "West Europe");
            return(new ResourceTransformationResult(res.Args, res.Options));
        }
        public static ResourceTransformationResult?AddTags(ResourceTransformationArgs args)
        {
            {
                var tagp = args.Args.GetType().GetProperty("Tags");
                if (tagp is null)
                {
                    return(null);
                }

                var tags = (InputMap <string>)tagp.GetValue(args.Args, null) !;
                tags["ProvisionedBy"] = "Pulumi";

                tagp.SetValue(args.Args, tags, null);
                return(new ResourceTransformationResult(args.Args, args.Options));
            }
        }
Example #5
0
        private static ResourceTransformationResult?Transform(ResourceTransformationArgs args)
        {
            var ambientResourceGroup = Ambient.Value;

            if (ambientResourceGroup == null)
            {
                return(null);
            }

            if (!args.Resource.IsAzureNextGenResource() || args.Resource is Provider || args.Resource is ResourceGroup)
            {
                return(null);
            }

            var resourceGroupProperty = args.Args.GetResourceGroupProperty();
            var locationProperty      = args.Args.GetLocationProperty();

            var existingResourceGroupName = resourceGroupProperty?.GetValue(args.Args);
            var existingLocation          = locationProperty?.GetValue(args.Args);

            if (existingResourceGroupName != null && existingLocation != null)
            {
                Log.Debug("Both ResourceGroupName and Location have been manually specified on this resource, so the ambient resource group will not be applied");
                return(null);
            }
            else if (existingResourceGroupName != null)
            {
                Log.Debug("ResourceGroupName has already been manually specified on this resource, so the ambient resource group will not be applied");
                return(null);
            }
            else if (existingLocation != null)
            {
                Log.Debug("Location has already been manually specified on this resource, so the ambient resource group will not be applied");
                return(null);
            }

            var clonedArgs = args.Args.Clone();

            resourceGroupProperty?.SetInputValue(clonedArgs, ambientResourceGroup.ResourceGroup.Name);
            locationProperty?.SetInputValue(clonedArgs, ambientResourceGroup.ResourceGroup.Location);

            return(new ResourceTransformationResult(clonedArgs, args.Options));
        }
Example #6
0
        private static ResourceTransformationResult?Transform(ResourceTransformationArgs args)
        {
            var ambientLocation = Ambient.Value;

            if (ambientLocation == null)
            {
                return(null);
            }

            if (!args.Resource.IsAzureNextGenResource() || args.Resource is Provider)
            {
                return(null);
            }

            if (AmbientResourceGroup.Current != null)
            {
                Log.Debug("There is an ambient resource group in effect - that will set a Location if not already set");
                return(null);
            }

            var locationProperty = args.Args.GetLocationProperty();

            if (locationProperty == null)
            {
                Log.Debug($"No Location property on resource args type `{args.Args.GetType()}`, so not setting the ambient location");
                return(null);
            }

            var existingLocationValue = locationProperty.GetValue(args.Args);

            if (existingLocationValue != null)
            {
                Log.Debug("Location has already been manually specified on this resource, so the ambient location will not be applied");
                return(null);
            }

            var clonedArgs = args.Args.Clone();

            locationProperty.SetInputValue(clonedArgs, ambientLocation.Location);
            return(new ResourceTransformationResult(clonedArgs, args.Options));
        }