Skip to content

Commit

Permalink
make UI optional (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
oavdeev authored Mar 16, 2022
1 parent 7699033 commit 2f1cc22
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,67 @@ This module consists of submodules that can be used separately as well:

You can either use this high-level module, or submodules individually. See each module's corresponding `README.md` for more details.

You can find a complete example that uses this module but also includes setting up VPC and other non-Metaflow-specific parts of infra [in this repo](https://github.com/outerbounds/metaflow-tools/tree/master/aws/terraform).
Here's a minimal end-to-end example of using this module with VPC:
```terraform
# Random suffix for this deployment
resource "random_string" "suffix" {
length = 8
special = false
upper = false
}
locals {
resource_prefix = "metaflow"
resource_suffix = random_string.suffix.result
}
data "aws_availability_zones" "available" {
}
# VPC infra using https://github.com/terraform-aws-modules/terraform-aws-vpc
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.13.0"
name = "${local.resource_prefix}-${local.resource_suffix}"
cidr = "10.10.0.0/16"
azs = data.aws_availability_zones.available.names
private_subnets = ["10.10.8.0/21", "10.10.16.0/21", "10.10.24.0/21"]
public_subnets = ["10.10.128.0/21", "10.10.136.0/21", "10.10.144.0/21"]
enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
}
module "metaflow" {
source = "outerbounds/metaflow/aws"
version = "0.3.0"
resource_prefix = local.resource_prefix
resource_suffix = local.resource_suffix
enable_step_functions = false
subnet1_id = module.vpc.public_subnets[0]
subnet2_id = module.vpc.public_subnets[1]
vpc_cidr_block = module.vpc.vpc_cidr_block
vpc_id = module.vpc.vpc_id
tags = {
"managedBy" = "terraform"
}
}
# The module will generate a Metaflow config in JSON format, write it to a file
resource "local_file" "metaflow_config" {
content = module.metaflow.metaflow_profile_json
filename = "./metaflow_profile.json"
}
```

You can find a more complete example that uses this module but also includes setting up sagemaker notebooks and other non-Metaflow-specific parts of infra [in this repo](https://github.com/outerbounds/metaflow-tools/tree/master/aws/terraform).

<!-- BEGIN_TF_DOCS -->
## Modules
Expand Down Expand Up @@ -52,7 +112,7 @@ You can find a complete example that uses this module but also includes setting
| <a name="input_subnet1_id"></a> [subnet1\_id](#input\_subnet1\_id) | First subnet used for availability zone redundancy | `string` | n/a | yes |
| <a name="input_subnet2_id"></a> [subnet2\_id](#input\_subnet2\_id) | Second subnet used for availability zone redundancy | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | aws tags | `map(string)` | n/a | yes |
| <a name="input_ui_certificate_arn"></a> [ui\_certificate\_arn](#input\_ui\_certificate\_arn) | SSL certificate for UI | `string` | n/a | yes |
| <a name="input_ui_certificate_arn"></a> [ui\_certificate\_arn](#input\_ui\_certificate\_arn) | SSL certificate for UI. If set to empty string, UI is disabled. | `string` | `""` | no |
| <a name="input_vpc_cidr_block"></a> [vpc\_cidr\_block](#input\_vpc\_cidr\_block) | The VPC CIDR block that we'll access list on our Metadata Service API to allow all internal communications | `string` | n/a | yes |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The id of the single VPC we stood up for all Metaflow resources to exist in. | `string` | n/a | yes |

Expand Down
61 changes: 61 additions & 0 deletions examples/minimal_example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
###############################################################################
# An example using this module to set up a minimal deployment Metaflow
# with AWS Batch support, without the UI.
###############################################################################

# Random suffix for this deployment
resource "random_string" "suffix" {
length = 8
special = false
upper = false
}

locals {
resource_prefix = "metaflow"
resource_suffix = random_string.suffix.result
}

data "aws_availability_zones" "available" {
}

# VPC infra using https://github.com/terraform-aws-modules/terraform-aws-vpc
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.13.0"

name = "${local.resource_prefix}-${local.resource_suffix}"
cidr = "10.10.0.0/16"

azs = data.aws_availability_zones.available.names
private_subnets = ["10.10.8.0/21", "10.10.16.0/21", "10.10.24.0/21"]
public_subnets = ["10.10.128.0/21", "10.10.136.0/21", "10.10.144.0/21"]

enable_nat_gateway = true
single_nat_gateway = true
enable_dns_hostnames = true
}


module "metaflow" {
source = "outerbounds/metaflow/aws"
version = "0.3.0"

resource_prefix = local.resource_prefix
resource_suffix = local.resource_suffix

enable_step_functions = false
subnet1_id = module.vpc.public_subnets[0]
subnet2_id = module.vpc.public_subnets[1]
vpc_cidr_block = module.vpc.vpc_cidr_block
vpc_id = module.vpc.vpc_id

tags = {
"managedBy" = "terraform"
}
}

# The module will generate a Metaflow config in JSON format, write it to a file
resource "local_file" "metaflow_config" {
content = module.metaflow.metaflow_profile_json
filename = "./metaflow_profile.json"
}
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module "metaflow-metadata-service" {

module "metaflow-ui" {
source = "./modules/ui"
count = var.ui_certificate_arn == "" ? 0 : 1

resource_prefix = local.resource_prefix
resource_suffix = local.resource_suffix
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ output "migration_function_arn" {
}

output "ui_alb_dns_name" {
value = module.metaflow-ui.alb_dns_name
value = (length(module.metaflow-ui) > 0) ? module.metaflow-ui[0].alb_dns_name : ""
description = "UI ALB DNS name"
}
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ variable "vpc_id" {

variable "ui_certificate_arn" {
type = string
description = "SSL certificate for UI"
default = ""
description = "SSL certificate for UI. If set to empty string, UI is disabled. "
}

variable "extra_ui_backend_env_vars" {
Expand Down

0 comments on commit 2f1cc22

Please sign in to comment.