creamy-nail-67991
09/23/2021, 1:46 PMComponentResource
receives an argument of using the InputList<T>
where T is a custom class which we manipulate before creating the cloud resources.
This means we have to iterate over the InputList
property and create resources within the Apply()
block. According to the documentation (https://www.pulumi.com/docs/intro/concepts/inputs-outputs)
“During some program executions, apply doesn’t run. For example, it won’t run during a preview, when resource output values may be unknown. Therefore, you should avoid side-effects within the callbacks. For this reason, you should not allocate new resources inside of your callbacks either, as it could lead to pulumi preview being wrong.”Is there a better way of doing this, without creating resources within the
Apply()
?
Here is a code snippet for some reference.
frontendEndpointArgs.Apply(endpoints =>
{
....
foreach (var frontend in endpoints)
{
if (frontend.HttpsConfiguration == null)
{
continue;
}
var httpsConfigurationArgs = new CustomHttpsConfigurationArgs
{
FrontendEndpointId = Output.Format($"/subscriptions/{currentSubscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/frontDoors/{frontDoorName}/frontendEndpoints/{frontend.Name}"),
CustomHttpsProvisioningEnabled = true,
CustomHttpsConfigurationConfig = new CustomHttpsConfigurationCustomHttpsConfigurationArgs
{
CertificateSource = "AzureKeyVault",
AzureKeyVaultCertificateVaultId = frontend.HttpsConfiguration.Apply(fe => fe.AzureKeyVaultCertificateVaultId),
AzureKeyVaultCertificateSecretName = frontend.HttpsConfiguration.Apply(fe => fe.AzureKeyVaultCertificateSecretName),
AzureKeyVaultCertificateSecretVersion = frontend.HttpsConfiguration.Apply(fe => fe.AzureKeyVaultCertificateSecretVersion),
//MinimumTlsVersion = "1.2"
},
};
_ = frontend.Name.Apply(frontendName =>
new CustomHttpsConfiguration($"{frontendName}-SslCertificate", httpsConfigurationArgs, new CustomResourceOptions
{
Provider = provider,
Parent = parent,
}));
}
....
});
thousands-jordan-32051
10/01/2021, 10:05 AM