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

fix(gcptf): Fix provider versions and output issues #700

Merged
merged 9 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions cloud/aws/deploytf/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (a *NitricAwsTerraformProvider) CdkTfModules() (string, fs.FS, error) {
return ".nitric/modules", modules, nil
}

func (a *NitricAwsTerraformProvider) RequiredProviders() map[string]interface{} {
return map[string]interface{}{}
}

func (a *NitricAwsTerraformProvider) Pre(stack cdktf.TerraformStack, resources []*deploymentspb.Resource) error {
tfRegion := cdktf.NewTerraformVariable(stack, jsii.String("region"), &cdktf.TerraformVariableConfig{
Type: jsii.String("string"),
Expand Down
4 changes: 4 additions & 0 deletions cloud/azure/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func createStorageAccount(ctx *pulumi.Context, group *resources.ResourceGroup, t
return storageAccount, nil
}

func (a *NitricAzurePulumiProvider) RequiredProviders() map[string]interface{} {
return map[string]interface{}{}
}

func (a *NitricAzurePulumiProvider) createDatabaseServer(ctx *pulumi.Context, tags map[string]string) error {
var err error

Expand Down
5 changes: 5 additions & 0 deletions cloud/common/deploy/provider/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type NitricTerraformProvider interface {
// CdkTfModules - Return the relative parent directory (root golang packed) and embedded modules directory
CdkTfModules() (string, fs.FS, error)

// RequiredProviders - Return a list of required providers for this provider
RequiredProviders() map[string]interface{}

// Order - Return the order that resources should be deployed in.
// The order of resources is important as some resources depend on others.
// Changing the default order is not recommended unless you know what you are doing.
Expand Down Expand Up @@ -199,6 +202,8 @@ func createTerraformStackForNitricProvider(req *deploymentspb.DeploymentUpReques

stack := cdktf.NewTerraformStack(app, &fullStackName)

stack.AddOverride(jsii.String("terraform.required_providers"), nitricProvider.RequiredProviders())

// The code that defines your stack goes here
resources := nitricProvider.Order(req.Spec.Resources)

Expand Down
2 changes: 1 addition & 1 deletion cloud/gcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ generate-mocks:
generate-sources: generate-mocks

generate-terraform:
@cd deploytf && npx -y [email protected].8 get
@cd deploytf && npx -y [email protected].10 get

tidy:
@go mod tidy
Expand Down
68 changes: 37 additions & 31 deletions cloud/gcp/deploytf/.nitric/modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,57 +64,63 @@ resource "google_cloud_run_v2_service" "service" {
location = var.region
project = var.project_id
# set launch_stage to BETA if gpus set otherwise GA
launch_stage = var.gpus > 0 ? "BETA" : "GA"
# launch_stage = var.gpus > 0 ? "BETA" : "GA"
launch_stage = "GA"
deletion_protection = false

template {
scaling {
max_instance_count = var.min_instances
min_instance_count = var.max_instances
}

# dynamic "node_selector" {
# for_each = var.gpus > 0 ? [1] : []
# content {
# accelerator = "nvidia-l4"
# }
# }
containers {
image = "${local.service_image_url}@${docker_registry_image.push.sha256_digest}"
resources {
limits = merge({
cpu = "${var.cpus}"
limits = {
cpu = var.cpus
memory = "${var.memory_mb}Mi"
}, var.gpus > 0 ? { "nvidia.com/gpu" = var.gpus } : {})
}

dynamic "node_selector" {
for_each = var.gpus > 0 ? [1] : []
content {
accelerator = "nvidia-l4"
}

# limits = merge({
# cpu = "${var.cpus}"
# memory = "${var.memory_mb}Mi"
# }, var.gpus > 0 ? { "nvidia.com/gpu" = var.gpus } : {})
}

ports {
container_port = 9001
}
env {
name = "EVENT_TOKEN"
value = random_password.event_token.result
}
env {
name = "SERVICE_ACCOUNT_EMAIL"
value = google_service_account.service_account.email
}
env {
name = "GCP_REGION"
value = var.region
}
name = "EVENT_TOKEN"
value = random_password.event_token.result
}
env {
name = "SERVICE_ACCOUNT_EMAIL"
value = google_service_account.service_account.email
}
env {
name = "GCP_REGION"
value = var.region
}

dynamic "env" {
for_each = var.environment
content {
name = env.key
value = env.value
}
dynamic "env" {
for_each = var.environment
content {
name = env.key
value = env.value
}
}
}

service_account = google_service_account.service_account.email
timeout = var.timeout_seconds
timeout = var.timeout_seconds
}

depends_on = [docker_registry_image.push]
Expand All @@ -137,8 +143,8 @@ resource "google_service_account" "invoker_service_account" {

# Give the above service account permissions to execute the CloudRun service
resource "google_cloud_run_service_iam_member" "invoker" {
service = google_cloud_run_service.service.name
location = google_cloud_run_service.service.location
service = google_cloud_run_v2_service.service.name
location = google_cloud_run_v2_service.service.location
role = "roles/run.invoker"
member = "serviceAccount:${google_service_account.invoker_service_account.email}"
}
Expand Down
4 changes: 2 additions & 2 deletions cloud/gcp/deploytf/.nitric/modules/service/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "service_endpoint" {
value = google_cloud_run_service.service.status[0].url
value = google_cloud_run_v2_service.service.uri
}

output "service_account_email" {
Expand All @@ -15,5 +15,5 @@ output "event_token" {
}

output "service_name" {
value = google_cloud_run_service.service.name
value = google_cloud_run_v2_service.service.name
}
13 changes: 13 additions & 0 deletions cloud/gcp/deploytf/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ func (a *NitricGcpTerraformProvider) Init(attributes map[string]interface{}) err
//go:embed .nitric/modules/**/*
var modules embed.FS

func (a *NitricGcpTerraformProvider) RequiredProviders() map[string]interface{} {
return map[string]interface{}{
"google": map[string]string{
"source": "hashicorp/google",
"version": "~> 6.12.0",
},
"google-beta": map[string]string{
"source": "hashicorp/google-beta",
"version": "~> 6.12.0",
},
}
}

func (a *NitricGcpTerraformProvider) CdkTfModules() (string, fs.FS, error) {
return ".nitric/modules", modules, nil
}
Expand Down
Binary file modified cloud/gcp/deploytf/generated/api/jsii/api-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/bucket/jsii/bucket-0.0.0.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion cloud/gcp/deploytf/generated/constraints.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"cdktf": "0.20.8",
"cdktf": "0.20.10",
"providers": {}
}
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/policy/jsii/policy-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/queue/jsii/queue-0.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/secret/jsii/secret-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/service/jsii/service-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/stack/jsii/stack-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/topic/jsii/topic-0.0.0.tgz
Binary file not shown.
Loading