36
loading...
This website collects cookies to deliver better user experience
doppler login
brew install tfenv && tfenv install latest
terraform version
aws configure
aws s3 ls # this will list all s3 buckets in the region
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-east-1" # you can change if you are in a different country/region
}
resource "aws_s3_bucket" "bucket" {
bucket = "my-super-cool-tf-bucket"
acl = "private"
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
}
terraform apply
will run your code and then create the resources that you specified and terraform plan will produce the result of what you intend to run.aws s3 ls | grep my-super-cool-tf-bucket
2021-09-05 66:66:66 my-super-cool-tf-bucket
# Install the Doppler provider
terraform {
required_providers {
doppler = {
source = "DopplerHQ/doppler"
version = "1.0.0" # Always specify the latest version
}
}
}
# Define a variable so we can pass in our token
variable "doppler_token" {
type = string
description = "A token to authenticate with Doppler"
}
# Configure the Doppler provider with the token
provider "doppler" {
doppler_token = var.doppler_token
}
# Generate a random password
resource "random_password" "db_password" {
length = 32
special = true
}
# Save the random password to Doppler
resource "doppler_secret" "db_password" {
project = "rocket"
config = "dev"
name = "DB_PASSWORD"
value = random_password.db_password.result
}
# Access the secret value
output "resource_value" {
# nonsensitive used for demo purposes only
value = nonsensitive(doppler_secret.db_password.value)
}
terraform init
terraform apply
aws cp model.pt s3://my-super-cool-tf-bucket
Create a file and call it providers.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
provider "aws" {
region = "us-east-1" # you can change if you are in a different country/region
}
resource "random_pet" "vpc_name" {
length = 2
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = random_pet.vpc_name.id
cidr = "10.10.0.0/16"
azs = ["us-east-1"]
intra_subnets = ["10.10.101.0/24"]
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
}
resource "aws_efs_file_system" "model_efs" {}
resource "aws_efs_mount_target" "model_target" {
file_system_id = aws_efs_file_system.shared.id
subnet_id = module.vpc.intra_subnets[0]
security_groups = [module.vpc.default_security_group_id]
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
}
resource "aws_efs_access_point" "lambda_ap" {
file_system_id = aws_efs_file_system.shared.id
posix_user {
gid = 1000
uid = 1000
}
root_directory {
path = "/lambda"
creation_info {
owner_gid = 1000
owner_uid = 1000
permissions = "0777"
}
}
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
}
resource "aws_datasync_location_s3" "s3_loc" {
s3_bucket_arn = "arn" # copy the bucket arn you created in the previous step
}
resource "aws_datasync_location_efs" "efs_loc" {
efs_file_system_arn = aws_efs_mount_target.model_target.file_system_arn
ec2_config {
security_group_arns = [module.vpc.default_security_group_id]
subnet_arn = module.vpc.intra_subnets[0]
}
}
resource "aws_datasync_task" "model_sync" {
name = "named-entity-model-sync-job"
destination_location_arn = aws_datasync_location_s3.efs_loc.arn
source_location_arn = aws_datasync_location_nfs.s3_loc.arn
options {
bytes_per_second = -1
}
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
}
def predict(event, ctx):
...
resource "random_pet" "lambda_name" {
length = 2
}
module "lambda" {
source = "terraform-aws-modules/lambda/aws"
function_name = random_pet.lambda_name.id
description = "Named Entity Recognition Model"
handler = "model.predict"
runtime = "python3.8"
source_path = "${path.module}"
vpc_subnet_ids = module.vpc.intra_subnets
vpc_security_group_ids = [module.vpc.default_security_group_id]
attach_network_policy = true
file_system_arn = aws_efs_access_point.lambda.arn
file_system_local_mount_path = "/mnt/shared-storage"
tags = {
Name = "machine-learning" # tags are important for cost tracking
Environment = "prod"
}
depends_on = [aws_efs_mount_target.model_target]
}
terraform destroy