Skip to content

bhegazy/terraform-aws-apprunner

Repository files navigation

AWS App Runner Module

Terraform module which creates AWS AppRunner resources, currently only creates aws_apprunner_service, and have to provide arns for extra apprunner related resources.

Future Improvements Plan

Usage

The Official AWS App Runner hello app example that uses public ECR image source

module "hello_app_runner" {
  source = "bhegazy/terraform-aws-app-runner"

  create = true
  service_name             = "hello-app-runner"

  tags = {
    Name = "hello-app-runner"
  }

  service_source_type      = "image"
  image_repository_type    = "ECR_PUBLIC"
  image_identifier         = "public.ecr.aws/aws-containers/hello-app-runner:latest"
  auto_deployments_enabled = false # Must set to false to disable auto deployment for ECR_PUBLIC type
}

Create App runner service from private image source (ECR) for example

Example uses aws-app-runner-rust-example

module "image_repository_private" {
  source = "bhegazy/terraform-aws-app-runner"

  create = true
  service_name             = "my-service"

  tags = {
    Name = "my-service"
  }

  service_source_type      = "image"
  auto_deployments_enabled = true
  image_repository_type    = "ECR"
  image_access_role_arn    = module.image_repository_private_ecr_role.iam_role_arn
  image_identifier         = "112233445566.dkr.ecr.us-east-1.amazonaws.com/aws-app-runner-rust-example:latest"
  image_configuration      = {
    port                          = 8080
    start_command                 = "./aws-app-runner-rust-example"
    runtime_environment_variables = {
      ENV_VAR_1 = "value1"
      ENV_VAR_2 = "value2"
    }
  }
}

Create App runner service from code source that have an app config (apprunner.yml file).

module "code_repository_source" {
  source = "bhegazy/terraform-aws-app-runner"
  
  create = true
  service_name             = "my-service"
  
  tags = {
    Name = "my-service"
  }
  
  service_source_type      = "code"
  auto_deployments_enabled = true
  code_connection_arn       = aws_apprunner_connection.main.arn
  code_repository_url       = "https://github.com/bhegazy/apprunner-python-app"
  code_version_type         = "BRANCH"
  code_version_value        = "main"
  code_configuration_source = "REPOSITORY"
}

Examples

Requirements

Name Version
terraform >= 0.13.1
aws >= 4.10.0

Providers

Name Version
aws >= 4.10.0

Modules

No modules.

Resources

Name Type
aws_apprunner_service.this resource

Inputs

Name Description Type Default Required
auto_deployments_enabled Whether continuous integration from the source repository is enabled for the App Runner service. Defaults to true. bool true no
auto_scaling_configuration_arn The ARN of auto scaling configuration for the App Runner service string "" no
code_configuration_source The source of the App Runner configuration. Valid values: REPOSITORY, API string "REPOSITORY" no
code_configuration_values Basic configuration for building and running the App Runner service. Use this parameter to quickly launch an App Runner service without providing an apprunner.yaml file in the source code repository (or ignoring the file if it exists). any {} no
code_connection_arn The connection ARN to use for the App Runner service if the service_source_type is 'code' string "" no
code_repository_url The location of the repository that contains the source code. This is required for service_source_type 'code' string "" no
code_version_type The type of version identifier. For a git-based repository, branches represent versions. Valid values: BRANCH string "BRANCH" no
code_version_value A source code version. For a git-based repository, a branch name maps to a specific version. App Runner uses the most recent commit to the branch. string "main" no
create Controls if App Runner resources should be created bool true no
health_check_configuration The health check configuration for the App Runner service map(string) {} no
image_access_role_arn The access role ARN to use for the App Runner service if the service_source_type is 'image' and image_repository_type is not 'ECR_PUBLIC' string "" no
image_configuration Configuration for running the identified image. any {} no
image_identifier The identifier of an image. For an image in Amazon Elastic Container Registry (Amazon ECR), this is an image name. string "" no
image_repository_type The type of the image repository. This reflects the repository provider and whether the repository is private or public. Defaults to ECR string "ECR" no
instance_configuration The instance configuration for the App Runner service map(string) {} no
kms_key_arn The ARN of the custom KMS key to be used to encrypt the copy of source repository and service logs. By default, App Runner uses an AWS managed CMK string "" no
service_name App Runner service name string "" no
service_source_type The service source type, valid values are 'code' or 'image' string "image" no
tags A map of tags to add to all resources map(string) {} no
vpc_connector_arn The ARN of the VPC connector to use for the App Runner service string "" no

Outputs

Name Description
service_arn The App Runner Service ARN
service_status The App Runner Service Status
service_url The App Runner Service URL

Authors

Module is maintained by Bill Hegazy.

License

Apache 2 Licensed. See LICENSE for full details