Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating TypeMap during create doesn't work #81

Closed
deasmi opened this issue Sep 26, 2017 · 3 comments
Closed

Updating TypeMap during create doesn't work #81

deasmi opened this issue Sep 26, 2017 · 3 comments
Labels
bug Something isn't working

Comments

@deasmi
Copy link

deasmi commented Sep 26, 2017

Terraform Version

Terraform v0.10.7-dev

This could quite possibly be my lack of understanding but I am working on the libvirt provider and cannot seem to update an entry in a TypeMap during the Create cycle, updating a TypeString works fine.

Here is part of the schema

			"graphics": &schema.Schema{
				Type:     schema.TypeMap,
				Optional: true,
				Computed: true,
			},
			"video_type": &schema.Schema{
				Type:     schema.TypeString,
				Optional: true,
				Computed: true,
			},

during

func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error {

I am checking various things and if video_type or graphics.autoport are not set I add defaults.

d.Set("video_type", "cirrus")
d.Set("graphics.autoport", "yes")

When the resource is created and read back video_type correctly appears, graphics.autoport does not.

I was wondering if this is just expected behaviour and I should be using TypeList or TypeSet so I can specify the individual structure that forms the graphics block, or is this a bug ?

Full code is in my graphicsandvnc branch file libvirt/resource_libvirt_domain.go

TestAccLibvirtDomain_GraphicsVNCSimple

is failing because of this.

Thanks

@apparentlymart
Copy link
Contributor

Hi @deasmi! Sorry for the inconsistencies in how Set behaves here.

I believe you should be able to get that attribute updated by setting the entire map at once, like this:

    d.Set("graphics", map[string]interface{
        "autoport": "yes",
    })

Note that d.Set actually returns an error value, so you may get more insight into what's going on here by checking that return value to see if the method is giving some detail about what's not working here:

err := d.Set("graphics.autoport", "yes")
if err != nil {
    return err
}

Setting whole objects at once is generally the more robust approach, so I'd suggest doing that if possible, but the above error check may give you a hint about why setting just that map key isn't working.

@deasmi
Copy link
Author

deasmi commented Nov 15, 2017

I will try and make a simple test case, setting the whole map shows the same result.

@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@hashibot hashibot added the bug Something isn't working label Oct 2, 2019
@ghost
Copy link

ghost commented Apr 1, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants