GoogleCloudPlatform / deploymentmanager-samples

Deployment Manager samples and templates.
Apache License 2.0
946 stars 716 forks source link

Error creating compute.v1.cluster #456

Closed mbaroody closed 5 years ago

mbaroody commented 5 years ago

I am trying to create a GKE cluster with Deployment Manager using the following as a reference: https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.zones.clusters. I know this differs from the examples in this repository slightly. I used the documentation instead of the examples because the examples use fields that are listed as deprecated. Here is my template:

def generate_config(context):
    CLUSTER_NAME = context.env["project"] + "-cluster"
    INITIAL_CLUSTER_VERSION = context.properties["initialClusterVersion"]
    INITIAL_NODE_COUNT = context.properties["initialNodeCount"]
    MACHINE_TYPE = context.properties["machineType"]
    ZONE = context.properties["zone"]
    SERVICE_ACCOUNT = context.properties["serviceAccount"]
    resources = [{
        "name": CLUSTER_NAME,
        "type": "container.v1.cluster",
        "properties": {
            "name": CLUSTER_NAME,
            "initialClusterVersion": INITIAL_CLUSTER_VERSION,
            "nodePools": [{
                "machineType": MACHINE_TYPE,
                "management": { "autoRepair": True },
                "initialNodeCount": INITIAL_NODE_COUNT,
                "config": {
                    "serviceAccount": SERVICE_ACCOUNT,
                    "oauthScopes": [
                        "https://www.googleapis.com/auth/compute",
                        "https://www.googleapis.com/auth/devstorage.read_only",
                        "https://www.googleapis.com/auth/logging.write",
                        "https://www.googleapis.com/auth/monitoring"
                    ]
                }
            }],
            "locations": [ ZONE ],
            "ipAllocationPolicy": { "useIpAliases": True },
            "loggingService": "logging.googleapis.com",
            "monitoringService": "monitoring.googleapis.com",
            "zone": context.properties["zone"],
        }
    }]
    outputs = []
    return { "resources": resources, "outputs": outputs }

When I try to create a deployment, I get the following error:

Missing property in path $['resource']['properties']['cluster']

This leads me to believe that the examples are the source of truth and not the documentation. Can someone help me figure out what I'm doing wrong?

ocsig commented 5 years ago

Thank you for your feedback, our team hear you loud and clear. We are working together with the documentation team to improve the usability and remove the ambiguity around the types and their properties used in Deployment Manager.

Let me try to explain what is happening here:

It is not always obvious what changes and why got applied and currently the best source is the 'examples/v2' and 'google/resource-snippets' folders. Soon there will be additional information about custom behaviour of the types.

Last but not least, please take a look at the CloudFoundation Toolkit implementation, it may saves you a lots of time as well. ( Currently we are pushing major updates to the new repo.)