VSChina / magic-modules

Magic Modules: Automagically generate Google Cloud Platform support for OSS
Apache License 2.0
1 stars 4 forks source link

computed property appears in createUpdate method #34

Closed hund030 closed 5 years ago

hund030 commented 5 years ago

in api.yml, setting output: true for status property which is computed property, but it still appears in 'expand' method and causes creating error.

- !ruby/object:Api::Type::String
      name: 'status'
      output: true
      description: 'Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service.'
      azure_sdk_references: ['/manualPrivateLinkServiceConnections/privateLinkServiceConnectionState/status', '/properties/manualPrivateLinkServiceConnections/properties/privateLinkServiceConnectionState/status']
"private_link_service_connections": {
    Type:     schema.TypeList,
    Optional: true,
    Elem: &schema.Resource{
        Schema: map[string]*schema.Schema{
            "status": {
                Type:     schema.TypeString,
                Computed: true,
            },
        },
    },
},
func expandArmPrivateEndpointPrivateLinkServiceConnection(input []interface{}) *[]network.PrivateLinkServiceConnection {
    results := make([]network.PrivateLinkServiceConnection, 0)
    for _, item := range input {
        v := item.(map[string]interface{})
        privateLinkServiceID := v["private_link_service_id"].(string)
        groupIds := v["group_ids"].([]interface{})
        requestMessage := v["request_message"].(string)
        name := v["name"].(string)
        status := v["status"].(string)

        result := network.PrivateLinkServiceConnection{
            Name: utils.String(name),
            PrivateLinkServiceConnectionProperties: &network.PrivateLinkServiceConnectionProperties{
                GroupIds: utils.ExpandStringSlice(groupIds),
                PrivateLinkServiceConnectionState: &network.PrivateLinkServiceConnectionState{
                    Description: utils.String(status),
                },
                PrivateLinkServiceID: utils.String(privateLinkServiceID),
                RequestMessage: utils.String(requestMessage),
            },
        }

        results = append(results, result)
    }
    return &results
}
houkms commented 5 years ago

This issue was fixed in PR #35. We now support to specify an output sub-property in a nested input property.

When you have to mix them up:

  1. specify output=true for the sub-property
  2. delete the corresponding field in the request part of azure_sdk_definition (just for clear definition)
houkms commented 5 years ago

Even though, we do not recommend to mix up the input and output properties by specifying output=true for the sub-property of a nested object. Tries to:

  1. Remove the sub-property if it is not necessary
  2. Or split it out from the input part of the property, and declare a new pure output=true property
mybayern1974 commented 5 years ago

@hund030, could you please verify the fix and accordingly close this issue?

hund030 commented 5 years ago

@houkms Since the status property belongs to privateLinkServiceConnectionState, after the fixed in PR #35 . The status do not appear in create method directly, instead, the privateLinkServiceConnectionState appears.

result := network.PrivateLinkServiceConnection{
    Name: utils.String(name),
    PrivateLinkServiceConnectionProperties: &network.PrivateLinkServiceConnectionProperties{
        GroupIds:                          utils.ExpandStringSlice(groupIds),
        PrivateLinkServiceConnectionState: &network.PrivateLinkServiceConnectionState{},
        PrivateLinkServiceID:              utils.String(privateLinkServiceID),
        RequestMessage:                    utils.String(requestMessage),
    },
}

Need further work.

houkms commented 5 years ago

@hund030 Fixed in PR #38, please try it again.

hund030 commented 5 years ago

solved