AWS::CodeBuild::Build
Name of the resource
Other
Resource name
AWS::CodeBuild::Build
Description
There is currently no way to start a CodeBuild Build from CloudFormation. this could be useful in cases where build should be started (at least) once.
Other Details
See https://github.com/WeAreCloudar/cloudformation-samples/tree/main/resource_providers/cloudar_codebuild_build for an example implementation
CloudFormation is a state-based tool for managing resource, CodeBuild project execution is something rather imperative, not declarative. If you need to run CodeBuild I would rather use Event Bus (you can define Event Rule in CloudFormation for that) or CodePipeline to first deploy CloudFormation and after that, in next phase run CodeBuild with input from stack outputs.
It depends a bit on how you look at the build. The options you give work if you only care about triggering the build. If you care about the build actually succeeding (and the stack rolling back if it doesn't), a CodeBuild Build is very similar to a CloudFormation Custom Resource.
As you pointed out CodeBuild in this case acts as a custom resource handler, which means it's the underlying implementaiton, not really description of the resource itself. Succeeded build is not a persistet state, but rather temporary one - for that still a CodePipeline seems more accurate (for which you can define a AWS::CodePipeline::Pipeline resource with CodeBuild step in it).
Succeeded build is not a persistet state
It is for that particular build. It's perfectly doable to create a CloudFormation Resources Type that follows the required contract.
You might not need this resource, but that does not make the request invalid
I'd point out that there's an AWS blog on running bash scripts in a CloudFormation template: https://aws.amazon.com/blogs/mt/running-bash-commands-in-aws-cloudformation-templates/
It feels like we should also be having a discussion on cfn-language-discussion about how best to include imperative steps in the stack update process. I'm not convinced "inside the template" is the best answer.