Terraform operates based on a model that can be best described as a "pseudo" programming language. However, a more precise description would be that it's a descriptive language, which essentially means it allows for the specification of what the end state of a system should be. It inherently provides a clear and comprehensive description of the desired state of the infrastructure.
On the other hand, Pulumi is a prescriptive language. This means it requires the user to specify the steps the system should take to reach the desired end state. It uses a traditional programming language, which allows for greater flexibility and control at a granular level.
Prescriptive approaches are a relatively new concept in the infrastructure as code domain. Unlike descriptive ones, they provide specific guidelines and instructions instead of just explaining or describing situations. This results in a more effective and efficient way of achieving the desired outcome.
In this figure we start out our lifecycle by creating a resource group followed shortly by creating a virtual machine and then setup the networking. This could be flipped around, tossed about, or inverted.
As we are using an "upsert" approach, we have the ability to call APIs for specific scopes effectively achieving eventual consistency. For example, if we only need to create the network topology and not the virtual machine, we can make an API call for just that scope. This allows us to be more precise and efficient in our infrastructure management.
package main
import (
"fmt"
azure "github.com/pulumi/pulumi-azure-native-sdk"
"github.com/pulumi/pulumi-azure-native-sdk/containerregistry/v2"
"github.com/pulumi/pulumi-azure-native-sdk/network"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
LoadConfig("tmp/config-1.yaml")
pulumi.Run(func(ctx *pulumi.Context) error {
provider, err := azure.NewProvider(ctx, Config.SubscriptionId, &azure.ProviderArgs{
SubscriptionId: pulumi.String(Config.SubscriptionId),
})
if err != nil {
return err
}
// See if container registry exists yet.
containerregistry := containerregistry.LookupRegistryOutput(ctx, containerregistry.LookupRegistryOutputArgs{
RegistryName: pulumi.String(Config.Name),
ResourceGroupName: pulumi.String(Config.ResourceGroupName),
}, pulumi.Provider(provider))
if err != nil {
return err
}
fmt.Printf("%s", containerregistry.Id().ApplyT(func(s string) string {
ctx.Log.Info(s, nil)
return s
}))
// Create new endpoint if it does not exist.
if pulumi.String(containerregistry.ToLookupRegistryResultOutput().ProvisioningState().ElementType().Name()) != pulumi.String("Succeeded") {
endpoint, err := network.NewPrivateEndpoint(ctx, "privateEndpointConnection", &network.PrivateEndpointArgs{
Location: pulumi.String(Config.Location),
PrivateEndpointName: pulumi.String("privateEndpointConnection"),
ResourceGroupName: pulumi.String(Config.ResourceGroupName),
// more crap
})
if err != nil {
return err
}
ctx.Log.Debug(endpoint.ID().ElementType().Name(), nil)
}
return nil
})
}