/***************************************************************************
* IaCpp — Infrastructure as Code for Azure, in modern C++ *
* *
* Describe Azure infrastructure as strongly typed C++23. Compile it. *
* Run it. Out comes a valid ARM deployment template. *
* *
* If it compiles, it deploys: *
* - invalid resource names ............ compile error *
* - missing required properties ....... compile error *
* - hard-coded secrets ................ compile error *
* - dependsOn ......................... inferred, never written *
* *
* Press Alt-F9 to compile. Press Ctrl-F9 to run. *
* New here? Press F1. https://github.com/mcfbytes/iacpp *
***************************************************************************/
// examples/demo/main.cpp — the §4 IaCpp demo (T204/T205 final form).
//
// Reads like Bicep, compiles like C++. Running this binary emits a valid ARM
// deployment template to stdout; pipe to az deployment group create to deploy.
//
// Fidelity note (vs §4): the storage account name is LOWERCASE
// ("iacppdemo001"). The §4 prose shows "IaCppdemo001", but that violates the
// lowercase-only rule the AccountName consteval type now enforces — lowercase
// is the correct, compiling form.
#include <iacpp/iacpp.hpp>
#include <iacpp/resources/network.hpp>
#include <iacpp/resources/storage.hpp>
#include <iostream>
int main() { // NOLINT(bugprone-exception-escape)
using namespace iacpp;
using namespace iacpp::resources;
using namespace iacpp::resources::storage; // for _storageName UDL
Template deployment{Scope::ResourceGroup};
auto location = deployment.parameter<arm::Location>(
"location", {.defaultValue = arm::resourceGroupLocation()});
deployment.add(network::VirtualNetwork{
.name = "demo-vnet",
.location = location,
.addressSpace = {.addressPrefixes = {"10.0.0.0/16"}},
.subnets = {{.name = "workloads", .addressPrefix = "10.0.1.0/24"}},
});
auto storage = deployment.add(StorageAccount{
.name = "iacppdemo001"_storageName, // validated at compile time
.location = location,
.sku = Sku::StandardLrs,
.kind = Kind::StorageV2,
.properties = {.allowBlobPublicAccess = false, .minimumTlsVersion = TlsVersion::Tls1_2},
});
deployment.add(storage::BlobContainer{
.parent = storage.ref(), // full name + dependency edge composed for you
.name = "artifacts",
});
deployment.output("blobEndpoint", storage.ref().primaryBlobEndpoint());
std::cout << deployment.toJson();
return 0;
}