-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add cloud endpoints resource #933
Merged
nat-henderson
merged 8 commits into
hashicorp:master
from
nat-henderson:cloud-endpoints
Jan 24, 2018
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a9a8d9
Initial commit for OpenAPI Endpoints on Compute Engine.
nat-henderson 552d59c
Added update functionality.
nat-henderson 23192b9
Add a test for the endpoints service.
nat-henderson defe865
Added first draft of doc.
nat-henderson 67ff205
Added support for GRPC, and a test.
nat-henderson a4a3332
Added some comments.
nat-henderson 7d97213
Docs tweaks to make gRPC more clear.
nat-henderson 437df02
Code review comments
nat-henderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform.tfstate | ||
terraform.tfstate.backup | ||
terraform.tfvars |
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,134 @@ | ||
provider "google" { | ||
region = "${var.region}" | ||
credentials = "${file("${var.credentials_file_path}")}" | ||
} | ||
|
||
provider "random" {} | ||
|
||
resource "random_id" "project_name" { | ||
byte_length = 8 | ||
} | ||
|
||
resource "google_project" "endpoints_project" { | ||
name = "Endpoints Project" | ||
project_id = "tf-ep-${random_id.project_name.hex}" | ||
org_id = "${var.org_id}" | ||
billing_account = "${var.billing_account_id}" | ||
} | ||
|
||
resource "google_project_service" "endpoints_project" { | ||
project = "${google_project.endpoints_project.project_id}" | ||
service = "compute.googleapis.com" | ||
} | ||
|
||
resource "google_project_service" "endpoints_project_sm" { | ||
project = "${google_project.endpoints_project.project_id}" | ||
service = "servicemanagement.googleapis.com" | ||
} | ||
|
||
resource "google_endpoints_service" "endpoints_service" { | ||
service_name = "echo-api.endpoints.${google_project.endpoints_project.project_id}.cloud.goog" | ||
project = "${google_project.endpoints_project.project_id}" | ||
config_text = <<EOF | ||
swagger: "2.0" | ||
info: | ||
description: "A simple Google Cloud Endpoints API example." | ||
title: "Endpoints Example" | ||
version: "1.0.0" | ||
host: "echo-api.endpoints.${google_project.endpoints_project.project_id}.cloud.goog" | ||
basePath: "/" | ||
consumes: | ||
- "application/json" | ||
produces: | ||
- "application/json" | ||
schemes: | ||
- "https" | ||
paths: | ||
"/echo": | ||
post: | ||
description: "Echo back a given message." | ||
operationId: "echo" | ||
produces: | ||
- "application/json" | ||
responses: | ||
200: | ||
description: "Echo" | ||
schema: | ||
$ref: "#/definitions/echoMessage" | ||
parameters: | ||
- description: "Message to echo" | ||
in: body | ||
name: message | ||
required: true | ||
schema: | ||
$ref: "#/definitions/echoMessage" | ||
security: | ||
- api_key: [] | ||
definitions: | ||
echoMessage: | ||
properties: | ||
message: | ||
type: "string" | ||
EOF | ||
depends_on = ["google_project_service.endpoints_project_sm"] | ||
} | ||
|
||
resource "google_compute_network" "network" { | ||
name = "ep-network" | ||
auto_create_subnetworks = "true" | ||
project = "${google_project.endpoints_project.project_id}" | ||
depends_on = ["google_project_service.endpoints_project"] | ||
} | ||
|
||
# Allow the hosted network to be hit over ICMP, SSH, and HTTP. | ||
resource "google_compute_firewall" "network" { | ||
name = "allow-ssh-and-icmp" | ||
network = "${google_compute_network.network.self_link}" | ||
project = "${google_compute_network.network.project}" | ||
|
||
allow { | ||
protocol = "icmp" | ||
} | ||
|
||
allow { | ||
protocol = "tcp" | ||
ports = ["22", "80"] | ||
} | ||
} | ||
|
||
resource "google_compute_instance" "project_1_vm" { | ||
name = "tf-ep-vm" | ||
project = "${google_project.endpoints_project.project_id}" | ||
machine_type = "f1-micro" | ||
zone = "${var.region_zone}" | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "projects/debian-cloud/global/images/family/debian-8" | ||
} | ||
} | ||
|
||
metadata { | ||
endpoints-service-name = "${google_endpoints_service.endpoints_service.service_name}" | ||
endpoints-service-config-id = "${google_endpoints_service.endpoints_service.config_id}" | ||
startup-script = "${file("scripts/install-vm.sh")}" | ||
} | ||
|
||
network_interface { | ||
network = "${google_compute_firewall.network.network}" | ||
|
||
access_config { | ||
// Ephemeral IP | ||
} | ||
} | ||
|
||
service_account { | ||
scopes = ["https://www.googleapis.com/auth/cloud-platform"] | ||
} | ||
|
||
depends_on = ["google_project_service.endpoints_project_sm", "google_project_service.endpoints_project"] | ||
} | ||
|
||
output "ip" { | ||
value = "${google_compute_instance.project_1_vm.network_interface.0.access_config.0.assigned_nat_ip}" | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/endpoints-on-compute-engine/scripts/install-vm.sh
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,14 @@ | ||
#!/bin/bash | ||
|
||
sudo apt-get install git -y | ||
curl https://storage.googleapis.com/golang/go1.7.3.linux-amd64.tar.gz | tar xzf - | ||
wget https://raw.githubusercontent.com/GoogleCloudPlatform/golang-samples/master/endpoints/getting-started/app.go | ||
GOPATH=$PWD GOROOT=$PWD/go go/bin/go get ./... 2> /tmp/goget_log.txt > /tmp/goget_outlog.txt | ||
echo "deb http://packages.cloud.google.com/apt google-cloud-endpoints-jessie main" | sudo tee /etc/apt/sources.list.d/google-cloud-endpoints.list | ||
curl --silent https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - | ||
sudo apt-get update && sudo apt-get install google-cloud-sdk | ||
sudo apt-get install endpoints-runtime | ||
sudo echo "PORT=80" >> /etc/default/nginx | ||
PORT=8081 GOPATH=$PWD GOROOT=$PWD/go go/bin/go run app.go > /tmp/gorun_outlog.txt 2> /tmp/gorun_log.txt & | ||
sleep 10 | ||
sudo service nginx restart |
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,20 @@ | ||
variable "region" { | ||
default = "us-central1" | ||
} | ||
|
||
variable "region_zone" { | ||
default = "us-central1-f" | ||
} | ||
|
||
variable "org_id" { | ||
description = "The ID of the Google Cloud Organization." | ||
} | ||
|
||
variable "billing_account_id" { | ||
description = "The ID of the associated billing account (optional)." | ||
} | ||
|
||
variable "credentials_file_path" { | ||
description = "Location of the credentials to use." | ||
default = "~/.gcloud/Terraform.json" | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alignment (
terraform fmt
in this directory should take care of it)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.