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

Data sources don't return more than one TypeSet's #7198

Closed
kayrus opened this issue Jan 18, 2019 · 3 comments · Fixed by #10045
Closed

Data sources don't return more than one TypeSet's #7198

kayrus opened this issue Jan 18, 2019 · 3 comments · Fixed by #10045
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@kayrus
Copy link

kayrus commented Jan 18, 2019

Terraform Version

0.11.11

Affected Resource(s)

  • aws_instance data source
  • aws_launch_configuration data source

Terraform Configuration Files

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_instance" "test" {
  ami           = "${data.aws_ami.ubuntu.id}"
  instance_type = "t2.micro"

  tags = {
    Name = "kshcherban-test"
  }

  ebs_block_device {
     device_name = "/dev/sdf"
     volume_size = 10
   }
   ebs_block_device {
     device_name = "/dev/sdg"
     volume_size = 20
     volume_type = "gp2"
   }
}

data "aws_instance" "test" {
  instance_id = "${aws_instance.test.id}"
}

output "instance" {
  value = "${aws_instance.test.ebs_block_device}"
}

output "data" {
  value = "${data.aws_instance.test.ebs_block_device}"
}

Debug Output

Outputs:

data = [
    {
        delete_on_termination = 1,
        device_name = /dev/sdg,
        encrypted = 0,
        iops = 100,
        snapshot_id = ,
        volume_id = vol-014032926148b41b2,
        volume_size = 20,
        volume_type = gp2
    }
]

instance = [
    {
        delete_on_termination = 1,
        device_name = /dev/sdf,
        encrypted = 0,
        iops = 0,
        snapshot_id = ,
        volume_id = vol-061fe03c49cda6742,
        volume_size = 10,
        volume_type = standard
    },
    {
        delete_on_termination = 1,
        device_name = /dev/sdg,
        encrypted = 0,
        iops = 100,
        snapshot_id = ,
        volume_id = vol-014032926148b41b2,
        volume_size = 20,
        volume_type = gp2
    }
]

Expected Behavior

data source should return the same amount of block devices

Actual Behavior

data source returns only one device of two

Important Factoids

Test are written incorrectly:

There are only two cases found. I assume there are more, and this pattern should be revised for other data sources or resources.

@kayrus
Copy link
Author

kayrus commented Jan 19, 2019

I took a closer look into this issue and figured out that the Set function is not required, when you specify Optional: true for all subattributes in data sources and resources.

Here is the terraform code, responsible for this behavior: https://github.com/hashicorp/terraform/blob/ac4fff416318bf0915a0ab80e062a99ef3724334/helper/schema/serialize.go#L103

@bflad bflad added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 25, 2019
@aeschright aeschright added the needs-triage Waiting for first response or review from a maintainer. label Jun 24, 2019
@ryndaniels ryndaniels added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Sep 5, 2019
@ryndaniels ryndaniels self-assigned this Sep 5, 2019
bflad added a commit to hashicorp/terraform that referenced this issue Sep 6, 2019
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
@ryndaniels
Copy link
Contributor

Hi @kayrus - thanks for opening this bug report, and huge thanks for the work you did to discover the issue with the Set function! That link you found was the key to figuring out how to fix this! 👍 We've submitted a fix to the Terraform SDK here that will resolve this issue. As you also correctly noted, the tests for this data source do need some fixing as well, so I'm going to be working on getting that out the door here shortly. So this issue should be resolved soon and thanks again for your Set function sleuthing! 🙂

bflad added a commit to hashicorp/terraform-plugin-sdk that referenced this issue Oct 8, 2019
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this issue Feb 13, 2020
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this issue Feb 13, 2020
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this issue Feb 20, 2020
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this issue Mar 4, 2020
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
appilon pushed a commit to hashicorp/terraform-plugin-sdk that referenced this issue Mar 11, 2020
… block contains only Computed attributes

Reference: hashicorp/terraform-provider-aws#7198
Reference: hashicorp/terraform-provider-aws#10045
Reference: hashicorp/terraform-provider-aws#10339
Reference: hashicorp/terraform#22719

When a resource schema contains the following:

```go
"config_block_attribute": {
	Type:     schema.TypeSet,
	Computed: true,
	Elem: &schema.Resource{
		Schema: map[string]*schema.Schema{
			"attribute1": {
				Type:     schema.TypeBool,
				Computed: true,
			},
			"attribute2": {
				Type:     schema.TypeString,
				Computed: true,
			},
		},
	},
},
```

The TypeSet hash values were previously all collapsed to the zero-value, which meant that multiple set entries were lost. Here we check that all of the attributes are not just `Computed: true`. If they are all `Computed: true` attributes, ignore the check for user-defined attributes to compute the hash value.
@ghost
Copy link

ghost commented Mar 29, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
4 participants