This is a simple means of building a Docker image that can be used for building infrastructure using Terraform and with tfsec too.
Please note this is just something I've hacked together, I am quite sure it'll need tweaking for real world usage!
There is a file that has some commands in covering image build, tagging and upload to ECR (public and private repo).
The Example Terraform directory contains a trivial Terraform config and a buildspec.yml file for the CodeBuild project.
Relevant IAM policies will need to be attached to the CodeBuild service role, not only for the ECR pull, but S3 (for the state) and in this example, logs:...
too.