|
| 1 | +package logging |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + |
| 6 | + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai" |
| 7 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| 8 | + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 9 | +) |
| 10 | + |
| 11 | +func ResourceConverterLogOrganizationSink() cai.ResourceConverter { |
| 12 | + return cai.ResourceConverter{ |
| 13 | + AssetType: logSinkAssetType, |
| 14 | + Convert: GetLogOrganizationSinkCaiObject, |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +func GetLogOrganizationSinkCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { |
| 19 | + name, err := cai.AssetName(d, config, "//logging.googleapis.com/organizations/{{org_id}}/sinks/{{name}}") |
| 20 | + if err != nil { |
| 21 | + return []cai.Asset{}, err |
| 22 | + } |
| 23 | + obj, err := GetLogOrganizationSinkApiObject(d, config) |
| 24 | + if err != nil { |
| 25 | + return []cai.Asset{}, err |
| 26 | + } |
| 27 | + return []cai.Asset{{ |
| 28 | + Name: name, |
| 29 | + Type: logSinkAssetType, |
| 30 | + Resource: &cai.AssetResource{ |
| 31 | + Version: "v2", |
| 32 | + DiscoveryDocumentURI: "https://logging.googleapis.com/$discovery/rest", |
| 33 | + DiscoveryName: "LogSink", |
| 34 | + Data: obj, |
| 35 | + }, |
| 36 | + }}, nil |
| 37 | +} |
| 38 | + |
| 39 | +func GetLogOrganizationSinkApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { |
| 40 | + obj := make(map[string]interface{}) |
| 41 | + |
| 42 | + nameProp, err := expandLogOrganizationSinkName(d.Get("name"), d, config) |
| 43 | + if err != nil { |
| 44 | + return nil, err |
| 45 | + } else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { |
| 46 | + obj["name"] = nameProp |
| 47 | + } |
| 48 | + |
| 49 | + destinationProp, err := expandLogOrganizationSinkDestination(d.Get("destination"), d, config) |
| 50 | + if err != nil { |
| 51 | + return nil, err |
| 52 | + } else if v, ok := d.GetOkExists("destination"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationProp)) && (ok || !reflect.DeepEqual(v, destinationProp)) { |
| 53 | + obj["destination"] = destinationProp |
| 54 | + } |
| 55 | + |
| 56 | + filterProp, err := expandLogOrganizationSinkFilter(d.Get("filter"), d, config) |
| 57 | + if err != nil { |
| 58 | + return nil, err |
| 59 | + } else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) { |
| 60 | + obj["filter"] = filterProp |
| 61 | + } |
| 62 | + |
| 63 | + descriptionProp, err := expandLogOrganizationSinkDescription(d.Get("description"), d, config) |
| 64 | + if err != nil { |
| 65 | + return nil, err |
| 66 | + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| 67 | + obj["description"] = descriptionProp |
| 68 | + } |
| 69 | + |
| 70 | + disabledProp, err := expandLogOrganizationSinkDisabled(d.Get("disabled"), d, config) |
| 71 | + if err != nil { |
| 72 | + return nil, err |
| 73 | + } else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) { |
| 74 | + obj["disabled"] = disabledProp |
| 75 | + } |
| 76 | + |
| 77 | + exclusionsProp, err := expandLogOrganizationSinkExclusions(d.Get("exclusions"), d, config) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } else if v, ok := d.GetOkExists("exclusions"); !tpgresource.IsEmptyValue(reflect.ValueOf(exclusionsProp)) && (ok || !reflect.DeepEqual(v, exclusionsProp)) { |
| 81 | + obj["exclusions"] = exclusionsProp |
| 82 | + } |
| 83 | + |
| 84 | + includeChildrenProp, err := expandLogOrganizationSinkIncludeChildren(d.Get("include_children"), d, config) |
| 85 | + if err != nil { |
| 86 | + return nil, err |
| 87 | + } else if v, ok := d.GetOkExists("include_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(includeChildrenProp)) && (ok || !reflect.DeepEqual(v, includeChildrenProp)) { |
| 88 | + obj["includeChildren"] = includeChildrenProp |
| 89 | + } |
| 90 | + |
| 91 | + interceptChildrenProp, err := expandLogOrganizationSinkInterceptChildren(d.Get("intercept_children"), d, config) |
| 92 | + if err != nil { |
| 93 | + return nil, err |
| 94 | + } else if v, ok := d.GetOkExists("intercept_children"); !tpgresource.IsEmptyValue(reflect.ValueOf(interceptChildrenProp)) && (ok || !reflect.DeepEqual(v, interceptChildrenProp)) { |
| 95 | + obj["interceptChildren"] = interceptChildrenProp |
| 96 | + } |
| 97 | + |
| 98 | + bigqueryOptionsProp, err := expandLogOrganizationSinkBigqueryOptions(d.Get("bigquery_options"), d, config) |
| 99 | + if err != nil { |
| 100 | + return nil, err |
| 101 | + } else if v, ok := d.GetOkExists("bigquery_options"); !tpgresource.IsEmptyValue(reflect.ValueOf(bigqueryOptionsProp)) && (ok || !reflect.DeepEqual(v, bigqueryOptionsProp)) { |
| 102 | + obj["bigqueryOptions"] = bigqueryOptionsProp |
| 103 | + } |
| 104 | + |
| 105 | + return obj, nil |
| 106 | +} |
| 107 | + |
| 108 | +func expandLogOrganizationSinkName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 109 | + return v, nil |
| 110 | +} |
| 111 | + |
| 112 | +func expandLogOrganizationSinkDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 113 | + return v, nil |
| 114 | +} |
| 115 | + |
| 116 | +func expandLogOrganizationSinkFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 117 | + return v, nil |
| 118 | +} |
| 119 | + |
| 120 | +func expandLogOrganizationSinkDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 121 | + return v, nil |
| 122 | +} |
| 123 | + |
| 124 | +func expandLogOrganizationSinkDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 125 | + return v, nil |
| 126 | +} |
| 127 | + |
| 128 | +func expandLogOrganizationSinkIncludeChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 129 | + return v, nil |
| 130 | +} |
| 131 | + |
| 132 | +func expandLogOrganizationSinkInterceptChildren(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 133 | + return v, nil |
| 134 | +} |
| 135 | + |
| 136 | +func expandLogOrganizationSinkExclusions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 137 | + l, ok := v.([]interface{}) |
| 138 | + if !ok { |
| 139 | + return nil, nil |
| 140 | + } |
| 141 | + req := make([]interface{}, 0, len(l)) |
| 142 | + for _, raw := range l { |
| 143 | + if raw == nil { |
| 144 | + continue |
| 145 | + } |
| 146 | + original := raw.(map[string]interface{}) |
| 147 | + transformed := make(map[string]interface{}) |
| 148 | + |
| 149 | + transformedName, err := expandLogOrganizationSinkExclusionsName(original["name"], d, config) |
| 150 | + if err != nil { |
| 151 | + return nil, err |
| 152 | + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 153 | + transformed["name"] = transformedName |
| 154 | + } |
| 155 | + |
| 156 | + transformedDescription, err := expandLogOrganizationSinkExclusionsDescription(original["description"], d, config) |
| 157 | + if err != nil { |
| 158 | + return nil, err |
| 159 | + } else if val := reflect.ValueOf(transformedDescription); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 160 | + transformed["description"] = transformedDescription |
| 161 | + } |
| 162 | + |
| 163 | + transformedFilter, err := expandLogOrganizationSinkExclusionsFilter(original["filter"], d, config) |
| 164 | + if err != nil { |
| 165 | + return nil, err |
| 166 | + } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 167 | + transformed["filter"] = transformedFilter |
| 168 | + } |
| 169 | + |
| 170 | + transformedDisabled, err := expandLogOrganizationSinkExclusionsDisabled(original["disabled"], d, config) |
| 171 | + if err != nil { |
| 172 | + return nil, err |
| 173 | + } else if val := reflect.ValueOf(transformedDisabled); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 174 | + transformed["disabled"] = transformedDisabled |
| 175 | + } |
| 176 | + |
| 177 | + req = append(req, transformed) |
| 178 | + } |
| 179 | + |
| 180 | + return req, nil |
| 181 | +} |
| 182 | + |
| 183 | +func expandLogOrganizationSinkExclusionsName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 184 | + return v, nil |
| 185 | +} |
| 186 | + |
| 187 | +func expandLogOrganizationSinkExclusionsDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 188 | + return v, nil |
| 189 | +} |
| 190 | + |
| 191 | +func expandLogOrganizationSinkExclusionsFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 192 | + return v, nil |
| 193 | +} |
| 194 | + |
| 195 | +func expandLogOrganizationSinkExclusionsDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 196 | + return v, nil |
| 197 | +} |
| 198 | + |
| 199 | +func expandLogOrganizationSinkBigqueryOptions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 200 | + l := v.([]interface{}) |
| 201 | + if len(l) == 0 || l[0] == nil { |
| 202 | + return nil, nil |
| 203 | + } |
| 204 | + raw := l[0] |
| 205 | + original := raw.(map[string]interface{}) |
| 206 | + transformed := make(map[string]interface{}) |
| 207 | + |
| 208 | + transformedUsePartitionedTables, err := expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(original["use_partitioned_tables"], d, config) |
| 209 | + if err != nil { |
| 210 | + return nil, err |
| 211 | + } else if val := reflect.ValueOf(transformedUsePartitionedTables); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 212 | + transformed["usePartitionedTables"] = transformedUsePartitionedTables |
| 213 | + } |
| 214 | + |
| 215 | + return transformed, nil |
| 216 | +} |
| 217 | + |
| 218 | +func expandLogOrganizationSinkBigqueryOptionsUsePartitionedTables(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 219 | + return v, nil |
| 220 | +} |
0 commit comments