Terraform-provider-google: Inappropriate value for attribute "ip_allocation_policy"

Created on 9 Sep 2019  ·  4Comments  ·  Source: hashicorp/terraform-provider-google


Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

Terraform v0.12.8
+ provider.google v2.14.0
+ provider.google-beta v2.14.0
+ provider.random v2.2.0
+ provider.template v2.1.2

Affected Resource(s)

  • google_container_cluster

Terraform Configuration Files

{
  "resource": {
    "google_container_cluster": {
      "sw01": {
        "addons_config": {
          "istio_config": {
            "auth": "AUTH_MUTUAL_TLS",
            "disabled": false
          }   
        },  
        "depends_on": [
          "google_project_service.enable_container_service"
        ],  
        "initial_node_count": 1,
        "ip_allocation_policy": [
          {   
            "use_ip_aliases": true,
            "create_subnetwork": true
          }]  
        ,   
        "location": "europe-west1",
        "master_auth": {
          "client_certificate_config": {
            "issue_client_certificate": false
          },  
          "password": "", 
          "username": ""
        },  
        "min_master_version": "1.13.7-gke.24",
        "name": "sw01",
        "network": "${google_compute_network.sw01.self_link}",
        "provider": "google",
        "remove_default_node_pool": true
      }   
    },
  }
} 

Debug Output

Panic Output

Expected Behavior

Create cluster it alias_ip

Actual Behavior

Error: Incorrect attribute value type

  on kubernetes.tf.json line 15, in resource.google_container_cluster.sw01:
  15:         "ip_allocation_policy": [

Inappropriate value for attribute "ip_allocation_policy": element 0:
attributes "cluster_ipv4_cidr_block", "cluster_secondary_range_name",
"node_ipv4_cidr_block", "services_ipv4_cidr_block",
"services_secondary_range_name", and "subnetwork_name" are required.

Steps to Reproduce

  1. terraform apply

Important Factoids

I am using json instead of hcl

bug

All 4 comments

Please note I have tried with several different combinations of ip_allocation_policy, all leading to similar errors

Hi @ademariag! ip_allocation_policy is an unusual field in the provider, because it has a special property that we had to set to enable certain features to work with 0.12. This has the side effect that, when using JSON, you have to set all the fields for this block, even optional ones.

https://www.terraform.io/docs/configuration/attr-as-blocks.html has some more details, but the relevant quotes are:

The interpretation of these values in JSON syntax is, therefore, equivalent to that described under Arbitrary Expressions with Argument Syntax above, but expressed in JSON syntax instead.

and

Because of the rule that argument declarations like this fully override any default value, when creating a list-of-objects expression directly the usual handling of optional arguments does not apply, so all of the arguments must be assigned a value, even if it's an explicit null

tl;dr: I'd recommend modifying your config to look like this:

        "ip_allocation_policy": [
          {
            "cluster_ipv4_cidr_block": null,
            "cluster_secondary_range_name": null,
            "node_ipv4_cidr_block": null,
            "services_ipv4_cidr_block":  null,
            "services_secondary_range_name": null,
            "subnetwork_name": null,
            "use_ip_aliases": true,
            "create_subnetwork": true
          }]  
        , 

I'm going to go ahead and close this issue out, but if it doesn't work or anything else comes up, we can reopen it.

FYI @danawillow that worked, thank you.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings