Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executor Improvements Part 01 #52

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
generate random uuid for prefix variable
  • Loading branch information
mpvgithub committed Feb 1, 2024
commit bcded11018597594ef4941f370f32221376759bc
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

## Added

- Generate random UUID for prefix variable to avoid name conflicting deployed resources

## Changed

- Moved the terraform files into **covalent_ec2_plugin/assets/infra** folder.
19 changes: 14 additions & 5 deletions covalent_ec2_plugin/assets/infra/main.tf
Original file line number Diff line number Diff line change
@@ -14,15 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

provider "aws" {
profile = var.aws_profile
region = var.aws_region
provider "aws" {}

data "aws_region" "current" {}

resource "random_string" "default_prefix" {
length = 9
upper = false
special = false
}

locals {
username = "ubuntu"
prefix = var.prefix == "" ? random_string.default_prefix.result : var.prefix
subnet_id = var.subnet_id == "" ? aws_default_subnet.default.id : var.subnet_id
region = var.region == "" ? data.aws_region.current.name : var.region
username = "ubuntu"
}


data "aws_ami" "ubuntu" {
most_recent = true

@@ -53,7 +62,7 @@ resource "aws_instance" "covalent_ec2_instance" {
}

tags = {
"Name" = var.name
"Name" = "covalent-ec2-${local.prefix}"
}
}

6 changes: 3 additions & 3 deletions covalent_ec2_plugin/assets/infra/networking.tf
Original file line number Diff line number Diff line change
@@ -19,10 +19,10 @@ module "vpc" {

create_vpc = (var.vpc_id == "")

name = "${var.name}-vpc"
name = "covalent-${local.prefix}-vpc"
cidr = var.vpc_cidr

azs = ["${var.aws_region}a"]
azs = ["${var.region}a"]

public_subnets = [
cidrsubnet(var.vpc_cidr, 0, 0)
@@ -40,7 +40,7 @@ data "http" "myip" {
}

resource "aws_security_group" "covalent_firewall" {
name = "${var.name}-firewall"
name = "covalent-${var.prefix}-firewall"
description = "Allow traffic to Covalent server"
vpc_id = var.vpc_id == "" ? module.vpc.vpc_id : var.vpc_id

8 changes: 4 additions & 4 deletions covalent_ec2_plugin/assets/infra/variables.tf
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

variable "name" {
default = "covalent-executor-ec2"
variable "prefix" {
default = ""
description = "Name used to prefix AWS resources"
}

variable "aws_region" {
default = "us-east-1"
variable "region" {
default = ""
description = "Region where resources for the EC2 plugin are deployed"
}

5 changes: 3 additions & 2 deletions covalent_ec2_plugin/ec2.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
import os
import subprocess
from pathlib import Path
from typing import Dict, List
from typing import Dict, List, Optional

import boto3
from covalent._shared_files import logger
@@ -65,6 +65,7 @@ class ExecutorPluginDefaults(BaseModel):


class ExecutorInfraDefaults(BaseModel):
prefix: Optional[str] = ""
profile: str = ""
credentials_file: str = ""
region: str = ""
@@ -270,7 +271,7 @@ async def setup(self, task_metadata: Dict) -> None:
self.infra_vars = [
f"-var=aws_region={region}",
f"-var=aws_profile={profile}",
f"-var=name=covalent-ec2-task-{task_metadata['dispatch_id']}-{task_metadata['node_id']}",
f"-var=prefix=covalent-ec2-task-{task_metadata['dispatch_id']}-{task_metadata['node_id']}",
f"-var=instance_type={self.instance_type}",
f"-var=disk_size={self.volume_size}",
f"-var=key_file={self.ssh_key_file}",
Loading