Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
change kubepath to take the raw bytes of the file (#11)
Browse files Browse the repository at this point in the history
* change kube_path to kube_file to take raw file text
  • Loading branch information
obadrawi committed Oct 24, 2019
1 parent 9347ccb commit 100e0f8
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Perform the following steps to use the provider:
> **NOTE:** To obtain the gardener secret and kubeconfig go to the [Gardener dashboard](https://dashboard.garden.canary.k8s.ondemand.com/login).
```bash
provider "gardener" {
kube_path = "<my-gardener-service-account-kubeconfig>"
kube_file = "${file("<my-gardener-service-account-kubeconfig>")}"
}
resource "gardener_shoot" "<Name>" {
metadata {
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type Client struct {

// Client configures and returns a fully initialized GardenerClient
func New(c *Config) (interface{}, error) {

config, err := clientcmd.BuildConfigFromFlags("", c.KubePath)
kubeBytes := []byte(c.KubeFile)
config, err := clientcmd.RESTConfigFromKubeConfig(kubeBytes)
if err != nil {
return nil, err
}
Expand All @@ -27,5 +27,5 @@ func New(c *Config) (interface{}, error) {
}

type Config struct {
KubePath string
KubeFile string
}
69 changes: 47 additions & 22 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
# Terraform Provider for Gardener Examples

## Overview

This folder contains a set of examples which use Gardener services to deploy [AWS](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/aws), [GCP](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/gcp) and [Azure](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/azure) clusters. All provided examples have the following section in common:

```bash
provider "gardener" {
kube_path = "<my-gardener-service-account-kubeconfig>"
}
```
This section includes the following parameters:
* **kube_path** - the path for the kubeconfig file of the service bot of the profile.

## Installation

Follow these steps to run an example:

1. Clone the `terraform-provider-gardener` repository.
2. Go to `terraform-provider-gardener/examples/{example_name}`.
3. Run `terraform apply`.

# Terraform Provider for Gardener Examples

## Overview

This folder contains a set of examples which use Gardener services to deploy [AWS](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/aws), [GCP](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/gcp) and [Azure](https://github.com/kyma-incubator/terraform-provider-gardener/tree/master/examples/azure) clusters. All provided examples have the following section in common:

```bash
provider "gardener" {
kube_file = "${file("<my-gardener-service-account-kubeconfig>")}"
}
```
You can pass the kube_file using the raw text alone as follows:
```bash
kube_file =<<-EOT
kind: Config
clusters:
- cluster:
certificate-authority-data: >-
<certificate-authority-data>
server: "https://gardener.garden.canary.k8s.ondemand.com"
name: garden
users:
- user:
token: >-
<token>
name: robot
contexts:
- context:
cluster: garden
user: robot
namespace: garden-<profile>
name: garden-<profile>-robot
current-context: garden-<profile>-robot
EOT
```
This section includes the following parameters:
* **kube_file** - the raw string of the kube config file.
## Installation
Follow these steps to run an example:
1. Clone the `terraform-provider-gardener` repository.
2. Go to `terraform-provider-gardener/examples/{example_name}`.
3. Run `terraform apply`.
24 changes: 23 additions & 1 deletion examples/aws/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
provider "gardener" {
kube_path = "<my-gardener-service-account-kubeconfig>"
kube_file = "${file("<my-gardener-service-account-kubeconfig>")}"
/*kube_file =<<-EOT
kind: Config
clusters:
- cluster:
certificate-authority-data: >-
<certificate-authority-data>
server: "https://gardener.garden.canary.k8s.ondemand.com"
name: garden
users:
- user:
token: >-
<token>
name: robot
contexts:
- context:
cluster: garden
user: robot
namespace: garden-<profile>
name: garden-<profile>-robot
current-context: garden-<profile>-robot
EOT*/
}

resource "gardener_shoot" "test_cluster" {
Expand Down
24 changes: 23 additions & 1 deletion examples/azure/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
provider "gardener" {
kube_path = "<my-gardener-service-account-kubeconfig>"
kube_file = "${file("<my-gardener-service-account-kubeconfig>")}"
/*kube_file =<<-EOT
kind: Config
clusters:
- cluster:
certificate-authority-data: >-
<certificate-authority-data>
server: "https://gardener.garden.canary.k8s.ondemand.com"
name: garden
users:
- user:
token: >-
<token>
name: robot
contexts:
- context:
cluster: garden
user: robot
namespace: garden-<profile>
name: garden-<profile>-robot
current-context: garden-<profile>-robot
EOT*/
}

resource "gardener_shoot" "test_cluster" {
Expand Down
24 changes: 23 additions & 1 deletion examples/gcp/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
provider "gardener" {
kube_path = "<my-gardener-service-account-kubeconfig>"
kube_file = "${file("<my-gardener-service-account-kubeconfig>")}"
/*kube_file =<<-EOT
kind: Config
clusters:
- cluster:
certificate-authority-data: >-
<certificate-authority-data>
server: "https://gardener.garden.canary.k8s.ondemand.com"
name: garden
users:
- user:
token: >-
<token>
name: robot
contexts:
- context:
cluster: garden
user: robot
namespace: garden-<profile>
name: garden-<profile>-robot
current-context: garden-<profile>-robot
EOT*/
}

resource "gardener_shoot" "test_cluster" {
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/gardener/gardener v0.0.0-20190906111529-f9ad04069615
github.com/gogo/protobuf v1.3.0 // indirect
github.com/google/go-cmp v0.3.1 // indirect
github.com/googleapis/gax-go v2.0.0+incompatible // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.9.2 // indirect
github.com/hashicorp/go-plugin v1.0.1 // indirect
Expand All @@ -18,6 +19,7 @@ require (
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/zclconf/go-cty v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20191001141032-4663e185863a // indirect
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect
Expand All @@ -26,7 +28,9 @@ require (
google.golang.org/appengine v1.6.4 // indirect
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c // indirect
google.golang.org/grpc v1.24.0 // indirect
gopkg.in/ini.v1 v1.44.0 // indirect
gopkg.in/yaml.v2 v2.2.3 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
)
Expand Down
9 changes: 4 additions & 5 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ var mutexKV = mutexkv.NewMutexKV()
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"kube_path": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("KUBECONFIG", ""),
"kube_file": {
Type: schema.TypeString,
Required: true,
},
},
ResourcesMap: map[string]*schema.Resource{
Expand All @@ -28,7 +27,7 @@ func Provider() terraform.ResourceProvider {
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := &client.Config{
KubePath: d.Get("kube_path").(string),
KubeFile: d.Get("kube_file").(string),
}
return client.New(config)
}

0 comments on commit 100e0f8

Please sign in to comment.