VSChina / magic-modules

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

SDKType `Integer32/64Object` has precision loss issue #80

Closed magodo closed 4 years ago

magodo commented 4 years ago

Currently when a Integer property links to some Integer32Object (same for Integer64Object), the generated code for setting to and getting from schema.ResourceData is like below:

// get
integer2integer32Object := d.Get("integer2integer32_object").(int)
...
parameters := dummy.DummyCreateParameters{
        ...
    Integer32Object:      utils.Int32(int32(integer2integer32Object)),
...

// set
d.Set("integer2integer32_object", int(*resp.Integer32Object))

The prefered code should be like below:

// get
integer2integer32Object := d.Get("integer2integer32_object").(int32)
...
parameters := dummy.DummyCreateParameters{
        ...
    Integer32Object:      utils.Int32(integer2integer32Object),
...

// set
d.Set("integer2integer32_object", *resp.Integer32Object)
magodo commented 4 years ago

Just realized that in terrafrom schema type system, there is only schema.TypeInt, which corresponds to go's int type. So it makes sense to cast fetched data from ResourceData to int since those values were int by themselves.