https://pulumi.com logo
Title
m

mysterious-australia-14256

07/14/2021, 10:06 AM
Hi All, I'm still struggling with using ARM template deployment to create a Web.CustomApi connector and then a Web.Connection that uses the API. The main issue is that the connection never shows up when I run a Pulumi Preview. It does however deploy if I run a Pulumi Up. I have code that creates the API via a deployment along the lines of
var connectorDeployment = new Pulumi.AzureNative.Resources.Deployment( .... )
I then create the connection using an expanded version of the following where I am retrieving the CustomApi object created by the above deployment and using that when creating the connection.
var outputResources = connectorDeployment.Properties.Apply(props => 
{
    Pulumi.AzureNative.Web.CustomApi bamConnector = Pulumi.AzureNative.Web.CustomApi.Get(connectorDeploymentResourceName, props.OutputResources[0].Id);
	var connection = Pulumi.AzureNative.Web.Connection(name, args, new CustomResourceOptions
    {
        DependsOn = bamConnector,
        Parent = bamConnector
    });
    return props;
}
This does deploy correctly and everything works but I would like to get Pulumi Preview to pick up this operation. How can I tweak my code so that Pulumi Preview is picking up the connection correctly? I also have an issue where a Pulumi Destroy is only removing the deployment and not the actual object that was created.
t

tall-librarian-49374

07/14/2021, 11:04 AM
That’s because you create your Connection resource inside an
Apply
which doesn’t run in the original preview (there’s no value to apply yet)
You should be able to refactor your code to avoid creating resources within an
Apply
. Instead, create it always, but pass args that are calculates with `Apply`s
Also, you wouldn’t need
dependsOn
in this case. Not sure you can do
Parent
though.
m

mysterious-australia-14256

07/14/2021, 11:12 AM
Thanks @tall-librarian-49374, I'll give it a go. Is there a way to get the destroy to remove the created object rather than the deployment?
t

tall-librarian-49374

07/14/2021, 11:24 AM
No, I’m afraid
Deployment is a black box for us
m

mysterious-australia-14256

07/14/2021, 11:25 AM
ok thanks
@tall-librarian-49374 given that I can get the ID of the created resource via the OutputResources returned by the deployment, is there any way I can then import the object so Pulumi then knows about it and can delete it? I'm guessing not as I think you have to specify all of the settings when doing an import and the reason I'm using an ARM deployment in the first place is that some properties aren't supported by the Pulumi code.
t

tall-librarian-49374

07/14/2021, 11:52 AM
Yes, I think you are correct that you can’t import a resource if you can’t define it.
👍 1