Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that could cause Go SDK to drop dependencies #5930

Merged
merged 2 commits into from
Dec 12, 2020
Merged

Conversation

EvanBoyle
Copy link
Contributor

Fixes #5928

There's a marshaling loop that can run multiple times for the purposes of unpacking pointer fields. The dependency array was mistakenly declared inside the loop, causing accumulated dependencies to be clobbered if the loop runs more than once.

A similar issue was fixed for secrets via #4387, but this was missed. Reading through this method in full, it doesn't seem like there are any additional bugs of this category lurking in the loop...

Used the following program to verify the fix locally. The subnet dependency is missing from the state file before this patch, and present with the patch applied.

package main

import (
	"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
	"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/network"
	"github.com/pulumi/pulumi-azure/sdk/v3/go/azure/storage"
	"github.com/pulumi/pulumi/sdk/v2/go/common/util/logging"
	"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

func main() {
	logging.InitLogging(true, 9, true)
	pulumi.Run(func(ctx *pulumi.Context) error {
		resourceGroup, err := core.NewResourceGroup(ctx, "testpulumi", &core.ResourceGroupArgs{
			Location: pulumi.String("WestUS"),
		})
		if err != nil {
			return err
		}

		account, err := storage.NewAccount(ctx, "storage", &storage.AccountArgs{
			ResourceGroupName:      resourceGroup.Name,
			AccountTier:            pulumi.String("Standard"),
			AccountReplicationType: pulumi.String("LRS"),
		})
		if err != nil {
			return err
		}

		virtualNetwork, err := network.NewVirtualNetwork(ctx, "vnet", &network.VirtualNetworkArgs{
			ResourceGroupName: resourceGroup.Name,
			Location:          resourceGroup.Location,
			AddressSpaces:     pulumi.StringArray{pulumi.String("10.0.6.0/24")},
		})
		if err != nil {
			return err
		}

		subnet, err := network.NewSubnet(ctx, "subnet", &network.SubnetArgs{
			ResourceGroupName:  resourceGroup.Name,
			VirtualNetworkName: virtualNetwork.Name,
			AddressPrefixes: pulumi.StringArray{
				pulumi.String("10.0.6.0/24"),
			},
		})
		if err != nil {
			return err
		}

		_, err = network.NewNetworkInterface(ctx, "networkinterface", &network.NetworkInterfaceArgs{
			Location:          resourceGroup.Location,
			ResourceGroupName: resourceGroup.Name,
			IpConfigurations: network.NetworkInterfaceIpConfigurationArray{
				&network.NetworkInterfaceIpConfigurationArgs{
					Name:                       pulumi.String("webserveripcfg"),
					Primary:                    pulumi.Bool(true),
					PrivateIpAddressAllocation: pulumi.String("Dynamic"),
					// ==========> BUG:
					// ==========> BUG: why doesn't the following line result in a dependency between the NIC and Subnet?
					// ==========> BUG:
					SubnetId: subnet.ID(),
				},
			},
			// ==========> BUG:
			// ==========> BUG: without this, there is no dependency:
			// ==========> BUG:
			//}, pulumi.DependsOn([]pulumi.Resource{subnet}))
		})
		if err != nil {
			return err
		}

		// Export the connection string for the storage account
		ctx.Export("connectionString", account.PrimaryConnectionString)
		return nil
	})
}

@@ -184,11 +184,11 @@ func marshalInputAndDetermineSecret(v interface{},
destType reflect.Type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we could benefit from some deeper testing of this marshalInputAndDetermineSecret function?

@EvanBoyle EvanBoyle merged commit 069f9f2 into master Dec 12, 2020
@pulumi-bot pulumi-bot deleted the evan/goDepBug branch December 12, 2020 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Go SDK can lose dependencies
3 participants