-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add terraform GCP provider (preview) (#632)
Co-authored-by: Tim Holm <[email protected]> Co-authored-by: David Moore <[email protected]>
- Loading branch information
1 parent
1e794d9
commit f47bef0
Showing
176 changed files
with
12,953 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
deploy/runtime-gcp | ||
dist/ | ||
dist/ | ||
|
||
common/runtime/runtime-gcp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright Nitric Pty Ltd. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/nitrictech/nitric/cloud/common/deploy/provider" | ||
"github.com/nitrictech/nitric/cloud/gcp/common/runtime" | ||
"github.com/nitrictech/nitric/cloud/gcp/deploytf" | ||
) | ||
|
||
// Start the deployment server | ||
func main() { | ||
gcpStack := deploytf.NewNitricGcpProvider() | ||
|
||
providerServer := provider.NewTerraformProviderServer(gcpStack, runtime.NitricGcpRuntime) | ||
|
||
providerServer.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
resource "google_api_gateway_api" "api" { | ||
provider = google-beta | ||
api_id = var.name | ||
labels = { | ||
"x-nitric-${var.stack_id}-name" = var.name | ||
"x-nitric-${var.stack_id}-type" = "api" | ||
} | ||
} | ||
|
||
# Create a random id that changes when the openapi_spec changes | ||
# required to prevent name collisions on update | ||
resource "random_string" "api_config_id" { | ||
length = 4 | ||
special = false | ||
upper = false | ||
|
||
keepers = { | ||
spec: var.openapi_spec | ||
} | ||
} | ||
|
||
resource "google_api_gateway_api_config" "api_config" { | ||
provider = google-beta | ||
api = google_api_gateway_api.api.api_id | ||
# A random ID, along with 'create_before_destroy' lifecycle, is used to prevent errors when updating (replacing) the API config | ||
api_config_id = "${var.name}-conf-${random_string.api_config_id.result}" | ||
|
||
openapi_documents { | ||
document { | ||
path = "openapi.json" | ||
contents = base64encode(var.openapi_spec) | ||
} | ||
} | ||
|
||
gateway_config { | ||
backend_config { | ||
google_service_account = google_service_account.service_account.email | ||
} | ||
} | ||
|
||
labels = { | ||
"x-nitric-${var.stack_id}-name" = var.name | ||
"x-nitric-${var.stack_id}-type" = "api" | ||
} | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
|
||
resource "google_api_gateway_gateway" "gateway" { | ||
provider = google-beta | ||
gateway_id = "${var.name}-gateway" | ||
api_config = google_api_gateway_api_config.api_config.id | ||
|
||
labels = { | ||
"x-nitric-${var.stack_id}-name" = var.name | ||
"x-nitric-${var.stack_id}-type" = "api" | ||
} | ||
} | ||
|
||
resource "google_service_account" "service_account" { | ||
provider = google-beta | ||
account_id = "${var.name}-api" | ||
} | ||
|
||
resource "google_cloud_run_service_iam_member" "member" { | ||
for_each = var.target_services | ||
|
||
service = each.value | ||
role = "roles/run.invoker" | ||
member = "serviceAccount:${google_service_account.service_account.email}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "endpoint" { | ||
value = "https://${google_api_gateway_gateway.gateway.default_hostname}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "name" { | ||
description = "The name of the API Gateway" | ||
type = string | ||
} | ||
|
||
variable "stack_id" { | ||
description = "The ID of the stack" | ||
type = string | ||
} | ||
|
||
variable "openapi_spec" { | ||
description = "The OpenAPI spec as a JSON string" | ||
type = string | ||
} | ||
|
||
variable "target_services" { | ||
description = "The map of target service names" | ||
type = map(string) | ||
} |
Oops, something went wrong.