Skip to content

New-Math-Data/terraform-aws-apprunner

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 = "app.terraform.io/NewMathData/apprunner/aws"

  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 = "app.terraform.io/NewMathData/apprunner/aws"

  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 = "app.terraform.io/NewMathData/apprunner/aws"
  
  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 >= 1.12.2
aws >= 5.100.0

Providers

Name Version
aws >= 5.100.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. Supports runtime_environment_secrets for secret environment variables. 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. Supports runtime_environment_secrets for secret environment variables. 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
ip_address_type App Runner provides you with the option to choose between Internet Protocol version 4 (IPv4) and dual stack (IPv4 and IPv6) for your incoming public network configuration. Valid values: IPV4, DUAL_STACK. Default: IPV4. string "IPV4" no
is_publicly_accessible Specifies whether your App Runner service is publicly accessible. To make the service publicly accessible set it to true. To make the service privately accessible, from only within an Amazon VPC set it to false. bool true 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
observability_configuration_arn ARN of the observability configuration that is associated with the service. Specified only when observability_enabled is true. string "" no
observability_enabled When true, an observability configuration resource is associated with the service. bool false 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

Example: Using Observability and Secret Environment Variables

module "my_app_runner" {
  source = "app.terraform.io/NewMathData/apprunner/aws"
  create = true
  service_name = "my-service"
  service_source_type = "image"
  image_repository_type = "ECR"
  image_identifier = "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:latest"
  image_access_role_arn = aws_iam_role.ecr_access.arn
  image_configuration = {
    port = 8080
    runtime_environment_variables = {
      ENV_VAR_1 = "value1"
    }
    runtime_environment_secrets = {
      SECRET_KEY = aws_secretsmanager_secret.example.arn
    }
  }
  observability_enabled = true
  observability_configuration_arn = aws_apprunner_observability_configuration.example.arn
}

About

Terraform module which creates AWS AppRunner resources

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HCL 100.0%