-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from avinetworks/Added-GCP-Examples
Added GCP examples
- Loading branch information
Showing
14 changed files
with
616 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,7 @@ | |
.glide/ | ||
|
||
.idea/ | ||
|
||
#MACOSX | ||
.DS_Store | ||
|
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,2 @@ | ||
*.tfstate | ||
|
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,68 @@ | ||
// Configure the Google Cloud provider | ||
provider "google" { | ||
credentials = file(var.credential_file) | ||
} | ||
|
||
// Get our controllers | ||
data "google_compute_instance" "avi_controller" { | ||
count = var.controller_count | ||
name = "${var.controller_name}-${count.index}" | ||
zone = var.zone | ||
project = var.project_id | ||
} | ||
|
||
// Avi provider | ||
provider "avi" { | ||
avi_username = var.avi_username | ||
avi_password = var.avi_current_password | ||
avi_controller = data.google_compute_instance.avi_controller.*.network_interface.0.network_ip[0] | ||
avi_tenant = "admin" | ||
avi_version = var.avi_version | ||
} | ||
|
||
// Avi tenant | ||
data "avi_tenant" "default_tenant" { | ||
name = "admin" | ||
} | ||
|
||
// CloudConnector user | ||
resource "avi_cloudconnectoruser" "gcp_user" { | ||
name = var.gcp_user | ||
tenant_ref = data.avi_tenant.default_tenant.id | ||
|
||
gcp_credentials { | ||
service_account_keyfile_data = file(var.credential_file) | ||
} | ||
} | ||
|
||
// Making our cloud | ||
resource "avi_cloud" "gcp_cloud_cfg" { | ||
name = var.gcp_cloud_name | ||
vtype = "CLOUD_GCP" | ||
|
||
gcp_configuration { | ||
match_se_group_subnet = false | ||
|
||
network_config { | ||
config = "INBAND_MANAGEMENT" | ||
|
||
inband { | ||
vpc_project_id = var.vpc_project_id | ||
vpc_subnet_name = var.vpc_subnetwork | ||
vpc_network_name = var.vpc_network | ||
} | ||
} | ||
region_name = var.region_name | ||
se_project_id = var.se_project_id | ||
firewall_target_tags = var.firewall_target_tags | ||
zones = var.zones | ||
cloud_credentials_ref = avi_cloudconnectoruser.gcp_user.id | ||
# gcs_project_id = "${var.gcs_project_id}" // optional, read description for more info. | ||
# gcs_bucket_name = "${var.gcs_bucket_name}" // optional, read description for more info. | ||
} | ||
|
||
license_tier = "ENTERPRISE_18" | ||
license_type = "LIC_CORES" | ||
tenant_ref = data.avi_tenant.default_tenant.id | ||
} | ||
|
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 @@ | ||
// You may define the variables here, read more about it here: https://learn.hashicorp.com/terraform/getting-started/variables.html#assigning-variables |
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,99 @@ | ||
variable "credential_file" { | ||
type = string | ||
description = "Please enter the path to your google service account's credential file, for instance if my credential file is at \"~/Desktop/my_credential_file.json\", I would enter: ~/Desktop/my_credential_file.json" | ||
} | ||
|
||
variable "controller_count" { | ||
type = string | ||
description = "Number of Controller instances (should be either 1 or 3)" | ||
} | ||
|
||
variable "project_id" { | ||
type = string | ||
description = "The ID of the project in which the controller's belong." | ||
} | ||
|
||
variable "se_project_id" { | ||
type = string | ||
description = "Google Cloud Platform Project ID where Service Engines will be spawned." | ||
} | ||
|
||
variable "region_name" { | ||
type = string | ||
description = "Google Cloud Platform Region Name where Service Engines will be spawned." | ||
} | ||
|
||
variable "zone" { | ||
type = string | ||
description = "Zone of your VM" | ||
} | ||
|
||
variable "avi_username" { | ||
type = string | ||
description = "Username of your Avi account" | ||
} | ||
|
||
variable "avi_current_password" { | ||
type = string | ||
description = "Current password of your Avi account" | ||
} | ||
|
||
variable "avi_version" { | ||
type = string | ||
description = "Avi version" | ||
} | ||
|
||
variable "controller_name" { | ||
type = string | ||
description = "Controller name" | ||
default = "avi-controller" | ||
} | ||
|
||
variable "vpc_project_id" { | ||
type = string | ||
description = "Enter VPC Project ID" | ||
} | ||
|
||
variable "vpc_network" { | ||
type = string | ||
description = "Enter VPC Network" | ||
} | ||
|
||
variable "vpc_subnetwork" { | ||
type = string | ||
description = "Enter VPC Subnetwork" | ||
} | ||
|
||
variable "zones" { | ||
type = list(string) | ||
description = "Google Cloud Platform Zones where Service Engines will be distributed for HA." | ||
} | ||
|
||
variable "gcp_cloud_name" { | ||
type = string | ||
description = "Enter name for GCP Cloud object" | ||
} | ||
|
||
variable "firewall_target_tags" { | ||
type = list(string) | ||
description = "Firewall rule network target tags which will be applied on Service Engines to allow ingress and egress traffic for Service Engines." | ||
default = ["http-server", "https-server"] | ||
} | ||
|
||
variable "gcp_user" { | ||
type = string | ||
description = "Name of cloud connector user" | ||
} | ||
|
||
variable "gcs_bucket_name" { | ||
type = string | ||
description = "(Optional) Google Cloud Storage Bucket Name where Service Engine image will be uploaded. This image will be deleted once the image is created in Google compute images. By default, a bucket will be created if this field is not specified." | ||
default = "not-given" | ||
} | ||
|
||
variable "gcs_project_id" { | ||
type = string | ||
description = "(Optional) Google Cloud Storage Project ID where Service Engine image will be uploaded. This image will be deleted once the image is created in Google compute images. By default, se_project_id will be used." | ||
default = "not-given" | ||
} | ||
|
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,61 @@ | ||
// Configure the Google Cloud provider | ||
provider "google" { | ||
credentials = file(var.credential_file) | ||
project = var.project_id | ||
} | ||
|
||
// Getting our VM's (Controller's) | ||
data "google_compute_instance" "avi_controller" { | ||
count = 3 | ||
name = "${var.controller_name}-${count.index}" | ||
zone = var.zone | ||
} | ||
|
||
// Configure the Avi provider | ||
provider "avi" { | ||
avi_username = var.avi_username | ||
avi_password = var.avi_current_password | ||
avi_controller = data.google_compute_instance.avi_controller.*.network_interface.0.network_ip[0] | ||
avi_tenant = "admin" | ||
avi_version = var.avi_version | ||
} | ||
|
||
// Creating our cluster | ||
resource "avi_cluster" "gcp_cluster" { | ||
name = var.cluster_name | ||
|
||
nodes { | ||
ip { | ||
type = "V4" | ||
addr = data.google_compute_instance.avi_controller.*.network_interface.0.network_ip[0] | ||
} | ||
|
||
name = "${var.controller_name}-0" | ||
} | ||
|
||
nodes { | ||
ip { | ||
type = "V4" | ||
addr = data.google_compute_instance.avi_controller.*.network_interface.0.network_ip[1] | ||
} | ||
|
||
name = "${var.controller_name}-1" | ||
} | ||
|
||
nodes { | ||
ip { | ||
type = "V4" | ||
addr = data.google_compute_instance.avi_controller.*.network_interface.0.network_ip[2] | ||
} | ||
|
||
name = "${var.controller_name}-2" | ||
} | ||
} | ||
|
||
// In case you would like to update your password | ||
resource "avi_useraccount" "avi_user" { | ||
username = var.avi_username | ||
old_password = var.avi_current_password | ||
password = var.avi_new_password | ||
} | ||
|
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 @@ | ||
// You may define the variables here, read more about it here: https://learn.hashicorp.com/terraform/getting-started/variables.html#assigning-variables |
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,51 @@ | ||
// GCP Variables | ||
|
||
variable "credential_file" { | ||
type = string | ||
description = "Please enter the path to your credential file, for instance if my credential file is at \"~/Desktop/my_credential_file.json\", I would enter: ~/Desktop/my_credential_file.json" | ||
} | ||
|
||
variable "project_id" { | ||
type = string | ||
description = "The ID of the project in which the VM's belongs" | ||
} | ||
|
||
variable "zone" { | ||
type = string | ||
description = "Zone of your VM" | ||
} | ||
|
||
variable "controller_name" { | ||
type = string | ||
description = "Controller name" | ||
default = "avi-controller" | ||
} | ||
|
||
// Avi Variables | ||
|
||
variable "avi_username" { | ||
type = string | ||
description = "Username for your Avi account" | ||
} | ||
|
||
variable "avi_current_password" { | ||
type = string | ||
description = "Current password of your Avi account" | ||
} | ||
|
||
variable "avi_version" { | ||
type = string | ||
description = "Avi version" | ||
} | ||
|
||
variable "avi_new_password" { | ||
type = string | ||
description = "New password for your Avi account" | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
description = "Cluster name" | ||
default = "avi-cluster" | ||
} | ||
|
Oops, something went wrong.