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

google container_cluster master_auth should be optional #14630

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 11 additions & 10 deletions builtin/providers/google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func resourceContainerCluster() *schema.Resource {
Schema: map[string]*schema.Schema{
"master_auth": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
ForceNew: true,
MaxItems: 1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, missed this earlier- you'll also need to set this to computed to get tests without master_auth to pass, since the server does return master_auth info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do the tests pass now? 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you running the acceptance tests or are you just looking at the travis build output? The build passes but the acceptance tests didn't when I ran them (https://github.com/hashicorp/terraform/blob/master/.github/CONTRIBUTING.md#running-an-acceptance-test)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right, forgot about that.

Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_certificate": &schema.Schema{
Expand Down Expand Up @@ -342,19 +344,18 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
zoneName := d.Get("zone").(string)
clusterName := d.Get("name").(string)

masterAuths := d.Get("master_auth").([]interface{})
if len(masterAuths) > 1 {
return fmt.Errorf("Cannot specify more than one master_auth.")
cluster := &container.Cluster{
Name: clusterName,
InitialNodeCount: int64(d.Get("initial_node_count").(int)),
}
masterAuth := masterAuths[0].(map[string]interface{})

cluster := &container.Cluster{
MasterAuth: &container.MasterAuth{
if v, ok := d.GetOk("master_auth"); ok {
masterAuths := v.([]interface{})
masterAuth := masterAuths[0].(map[string]interface{})
cluster.MasterAuth = &container.MasterAuth{
Password: masterAuth["password"].(string),
Username: masterAuth["username"].(string),
},
Name: clusterName,
InitialNodeCount: int64(d.Get("initial_node_count").(int)),
}
}

if v, ok := d.GetOk("node_version"); ok {
Expand Down
24 changes: 24 additions & 0 deletions builtin/providers/google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func TestAccContainerCluster_basic(t *testing.T) {
})
}

func TestAccContainerCluster_withMasterAuth(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccContainerCluster_withMasterAuth,
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerCluster(
"google_container_cluster.with_master_auth"),
),
},
},
})
}

func TestAccContainerCluster_withAdditionalZones(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -375,6 +392,13 @@ resource "google_container_cluster" "primary" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 3
}`, acctest.RandString(10))

var testAccContainerCluster_withMasterAuth = fmt.Sprintf(`
resource "google_container_cluster" "with_master_auth" {
name = "cluster-test-%s"
zone = "us-central1-a"
initial_node_count = 3

master_auth {
username = "mr.yoda"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ resource "google_container_cluster" "primary" {
* `initial_node_count` - (Required) The number of nodes to create in this
cluster (not including the Kubernetes master).

* `master_auth` - (Required) The authentication information for accessing the
Kubernetes master.

* `name` - (Required) The name of the cluster, unique within the project and
zone.

* `zone` - (Required) The zone that the master and the number of nodes specified
in `initial_node_count` should be created in.

- - -
* `master_auth` - (Optional) The authentication information for accessing the
Kubernetes master.

* `additional_zones` - (Optional) If additional zones are configured, the number
of nodes specified in `initial_node_count` is created in all specified zones.

Expand Down