terraform

Announcing Launch Day Support for AWS App Runner in the Terraform AWS Provider

The Terraform AWS provider now supports AWS AppRunner, a purpose-built container application service that enables customers to build and run containerized web applications in just a few clicks.

In partnership with AWS, we are pleased to announce launch day support for AWS App Runner in the Terraform AWS Provider. AWS App Runner is a purpose-built container application service that enables you to build and run containerized web applications, mobile backends, and API services in just a few clicks.

»How It Works

App Runner is powered by AWS Fargate, a serverless compute engine that runs billions of containers, and provides customers with a secure compute environment with no infrastructure overhead. With App Runner, there are no servers or container orchestrators to manage.

You provide your source code or image repository and App Runner automatically builds and deploys the container image, sets up and manages load balancing, delivers encryption, and scales up or down based on incoming request traffic. App Runner connects directly to your code or image repository, providing an automatic integration and delivery pipeline with fully managed operations, high performance, scalability, and security.

You can use App Runner to easily and immediately deploy a new version of your code or container image. App Runner enables automatic deployments each time a commit is pushed to the code repository or a new container image version is pushed to the image repository.

Additional information about this service can be found within this blog post from AWS, and the AWS App Runner documentation.

»Configuring App Runner in the Terraform AWS Provider

To set up AWS App Runner in the Terraform AWS provider, you will employ a few new resources: aws_apprunner_connection, aws_apprunner_service, aws_apprunner_autoscaling_configuration_version, aws_apprunner_custom_domain_association.

In order to try out this feature, you will need:

To create an App Runner service built from a GitHub repository source, you will first apply the following configuration and then complete the authentication handshake in the AWS App Runner console:

resource "aws_apprunner_connection" "example" {
  connection_name = "example"
  provider_type       = "GITHUB"
  tags = {
    Name = "example-gh-connection"
  }
}

Once you have completed the authentication step and the connection status is “AVAILABLE”, you can further configure AWS App Runner using the sample configuration below as a guide.

resource "aws_apprunner_auto_scaling_configuration_version" "example" {
  auto_scaling_configuration_name = "example"
  max_concurrency                 = 100
  max_size                        = 10
  min_size                        = 2

  tags = {
    Name = "apprunner-auto-scaling-example"
  }
}

resource "aws_apprunner_service" "example" {
  auto_scaling_configuration_arn = aws_apprunner_auto_scaling_configuration_version.example.arn

  service_name = "example"

  source_configuration {
    authentication_configuration {
      connection_arn = aws_apprunner_connection.example.arn
    }

    code_repository {
      code_configuration {
        configuration_source = "API"

        code_configuration_values {
          runtime       = "python3"
          build_command = "python setup.py develop"
          start_command = "python runapp.py"
          port          = "8000"
        }
      }

      repository_url = "https://github.com/example/my-python-app"

      source_code_version {
        type  = "BRANCH"
        value = "main"
      }

    }
  }
  tags = {
    Name = "my-apprunner-service"
  }
}

resource "aws_apprunner_custom_domain_association" "example" {
  domain_name = "example.com"
  service_arn = aws_apprunner_service.example.arn
}

»Further Information

For more information on how to use this feature in Terraform, consult the provider documentation in the Terraform Registry.

To report bugs and request enhancements for this feature, open an issue on the Terraform AWS Provider repository on GitHub. We would love to hear your feedback!

Sign up for the latest HashiCorp news