Skip to content
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 a limited generic YAML resource to the provider #195

Closed
wants to merge 15 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -30,3 +30,5 @@ website/vendor
# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/
**/terraform-provider-kubernetes
**/terraform-provider-kubernetes-yaml
39 changes: 39 additions & 0 deletions _examples/yaml/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "kubernetes" {}

resource "kubernetes_yaml" "test" {
yaml_body = <<YAML
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
azure/frontdoor: enabled
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
YAML
}


resource "kubernetes_yaml" "test-service" {
yaml_body = <<YAML
apiVersion: v1
kind: Service
metadata:
name: terraform-nginx-example
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
App: TerraformNginxExample
type: LoadBalancer
YAML
}
15 changes: 15 additions & 0 deletions _examples/yaml/yamltest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
azure/frontdoor: enabled
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
131 changes: 0 additions & 131 deletions kubernetes/data_source_kubernetes_service.go

This file was deleted.

50 changes: 0 additions & 50 deletions kubernetes/data_source_kubernetes_service_test.go

This file was deleted.

30 changes: 0 additions & 30 deletions kubernetes/data_source_kubernetes_storage_class.go

This file was deleted.

49 changes: 0 additions & 49 deletions kubernetes/data_source_kubernetes_storage_class_test.go

This file was deleted.

33 changes: 13 additions & 20 deletions kubernetes/provider.go
Original file line number Diff line number Diff line change
@@ -103,32 +103,18 @@ func Provider() terraform.ResourceProvider {
},
},

DataSourcesMap: map[string]*schema.Resource{
"kubernetes_service": dataSourceKubernetesService(),
"kubernetes_storage_class": dataSourceKubernetesStorageClass(),
},
DataSourcesMap: map[string]*schema.Resource{},

ResourcesMap: map[string]*schema.Resource{
"kubernetes_config_map": resourceKubernetesConfigMap(),
"kubernetes_deployment": resourceKubernetesDeployment(),
"kubernetes_horizontal_pod_autoscaler": resourceKubernetesHorizontalPodAutoscaler(),
"kubernetes_limit_range": resourceKubernetesLimitRange(),
"kubernetes_namespace": resourceKubernetesNamespace(),
"kubernetes_persistent_volume": resourceKubernetesPersistentVolume(),
"kubernetes_persistent_volume_claim": resourceKubernetesPersistentVolumeClaim(),
"kubernetes_pod": resourceKubernetesPod(),
"kubernetes_replication_controller": resourceKubernetesReplicationController(),
"kubernetes_resource_quota": resourceKubernetesResourceQuota(),
"kubernetes_secret": resourceKubernetesSecret(),
"kubernetes_service": resourceKubernetesService(),
"kubernetes_service_account": resourceKubernetesServiceAccount(),
"kubernetes_storage_class": resourceKubernetesStorageClass(),
"kubernetes_cluster_role_binding": resourceKubernetesClusterRoleBinding(),
"kubernetes_yaml": resourceKubernetesYAML(),
},
ConfigureFunc: providerConfigure,
}
}

// KubeProvider func to return client and config to work with K8s API
type KubeProvider func() (*kubernetes.Clientset, restclient.Config)

func providerConfigure(d *schema.ResourceData) (interface{}, error) {

var cfg *restclient.Config
@@ -178,7 +164,14 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, fmt.Errorf("Failed to configure: %s", err)
}

return k, nil
var meta KubeProvider
meta = func() (*kubernetes.Clientset, restclient.Config) {
// Defref config to create a shallow copy, allowing each func
// to manipulate the state without affecting another func
return k, *cfg
}

return meta, nil
}

func tryLoadingConfigFile(d *schema.ResourceData) (*restclient.Config, error) {
3 changes: 1 addition & 2 deletions kubernetes/provider_test.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import (
"github.com/terraform-providers/terraform-provider-google/google"
api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubernetes "k8s.io/client-go/kubernetes"
)

var testAccProviders map[string]terraform.ResourceProvider
@@ -247,7 +246,7 @@ func getFirstNode() (api.Node, error) {
if meta == nil {
return api.Node{}, errors.New("Provider not initialized, unable to get cluster node")
}
conn := meta.(*kubernetes.Clientset)
conn, _ := meta.(KubeProvider)()
resp, err := conn.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return api.Node{}, err
Loading