Skip to content

Commit

Permalink
add gcp provider and generate addon (#245)
Browse files Browse the repository at this point in the history
* add gcp provider and generate addon

Signed-off-by: Nicola115 <[email protected]>

* Update hack/addons/terraform/provider-GCP.yaml

Co-authored-by: Zheng Xi Zhou <[email protected]>

* Update hack/addons/terraform/provider-GCP.yaml

Co-authored-by: Zheng Xi Zhou <[email protected]>

Co-authored-by: Zheng Xi Zhou <[email protected]>
  • Loading branch information
Avery and zzxwill authored Feb 10, 2022
1 parent c28d75f commit 9f63926
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
16 changes: 16 additions & 0 deletions addons/terraform-gcp/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: terraform-gcp
version: 1.0.0
description: Kubernetes Terraform Controller Provider for Google Cloud Platform
url: https://github.com/oam-dev/terraform-controller

tags:
- Terraform Controller Provider
- IaC
- Cloud Resources

deployTo:
control_plane: true
runtime_cluster: false

dependencies:
- name: terraform
3 changes: 3 additions & 0 deletions addons/terraform-gcp/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Addon terraform-gcp

This addon contains Terraform provider for Google Cloud Platform.
20 changes: 20 additions & 0 deletions addons/terraform-gcp/resources/account-creds.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "strings"

output: {
type: "raw"
properties: {
apiVersion: "v1"
kind: "Secret"
metadata: {
name: "gcp-account-creds"
namespace: "vela-system"
}
type: "Opaque"
stringData: credentials: strings.Join([
"gcpCredentialsJSON: " + parameter.GOOGLE_CREDENTIALS,

"gcpProject: " + parameter.GOOGLE_PROJECT,
], "\n")
}
}

8 changes: 8 additions & 0 deletions addons/terraform-gcp/resources/parameter.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameter: {
//+usage=Get gcpCredentialsJSON per this guide https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials
GOOGLE_CREDENTIALS: *"" | string
//+usage=Get GOOGLE_REGION by picking one RegionId from Google Cloud region list https://cloud.google.com/compute/docs/regions-zones
GOOGLE_REGION: *"" | string
//+usage=Set gcpProject per this guide https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#configuring-the-provider
GOOGLE_PROJECT: *"" | string
}
23 changes: 23 additions & 0 deletions addons/terraform-gcp/resources/provider.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output: {
type: "raw"
properties: {
apiVersion: "terraform.core.oam.dev/v1beta1"
kind: "Provider"
metadata: {
name: "gcp"
namespace: "default"
}
spec: {
provider: "gcp"
region: parameter.GOOGLE_REGION
credentials: {
source: "Secret"
secretRef: {
namespace: "vela-system"
name: "gcp-account-creds"
key: "credentials"
}
}
}
}
}
5 changes: 5 additions & 0 deletions addons/terraform-gcp/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
name: terraform-gcp
namespace: vela-system
19 changes: 19 additions & 0 deletions hack/addons/terraform/provider-GCP.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# provider name
name: gcp

# The Cloud name of the provider
cloudName: Google Cloud Platform

# When enabling a Terraform provider, these properties need to set for authentication. For Tencent Cloud,
# name: Environment variable name when authenticating Terraform, like https://github.com/oam-dev/terraform-controller/blob/master/controllers/provider/credentials.go#L59
# secretKey: Secret key when storing authentication information in a Kubernetes, like https://github.com/oam-dev/terraform-controller/blob/master/controllers/provider/credentials.go#L109.
properties:
- name: GOOGLE_CREDENTIALS
secretKey: gcpCredentialsJSON
description: Get GOOGLE_CREDENTIALS per this guide https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#adding-credentials
- name: GOOGLE_REGION
description: Get GOOGLE_REGION by picking one RegionId from Google Cloud region list https://cloud.google.com/compute/docs/regions-zones
isRegion: true
- name: GOOGLE_PROJECT
secretKey: gcpProject
description: Set GOOGLE_PROJECT per this guide https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started#configuring-the-provider

0 comments on commit 9f63926

Please sign in to comment.