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

feat: add support to create well-known attributes for blocks #2504

Merged
merged 1 commit into from
Jun 22, 2023

Conversation

hugorut
Copy link
Contributor

@hugorut hugorut commented Jun 21, 2023

Goes some way to solving #1856

Adds support to return well-known values for blocks where mock data is insufficient. This is mostly applicable to data blocks. In particular data blocks such as aws_availability_zones where the return values can be inferred and don't require account/api access. This PR allows us to override the Values function for the Block with a more specific value func.

Initial supported blocks are:

  • data.aws_availability_zones
  • data.google_compute_zones
  • resource.random_shuffle

This pr also resolves an issue where the provider data was being set incorrectly in the evaluation context, using the key provider instead of aws, google, e.t.c.

@hugorut hugorut force-pushed the feat/support-complex-fake-values branch from a6d6cb6 to 179a9c3 Compare June 21, 2023 10:44
@hugorut
Copy link
Contributor Author

hugorut commented Jun 21, 2023

Note:

  • GCP/Azure test failures are on master - not related to these changes
  • zones_aws is incomplete at the moment until we enable more regions on our account - I will update when these come online

@hugorut hugorut marked this pull request as ready for review June 21, 2023 13:04
@hugorut hugorut self-assigned this Jun 21, 2023
@hugorut hugorut requested review from tim775 and aliscott and removed request for tim775 June 21, 2023 13:04
}
)

func randomShuffleValues(b *Block) cty.Value {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what we're doing here. From what I can tell we're essentially slicing the list - I assume that's so the result of this is always consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a function to mock the values returned from resource.random_shuffle https://github.com/hashicorp/terraform-provider-random/blob/main/docs/resources/shuffle.md. This resource uses the result_count attribute to return a slice of the input attribute, which is randomly sorted. We don't randomly sort it here as it's unecessary for us, and a consistent output is probably better for debuging/tests. I'll add a comment to clarify.

regionalSvc := ec2.NewFromConfig(regionalConf)

result, err := regionalSvc.DescribeAvailabilityZones(context.Background(), &ec2.DescribeAvailabilityZonesInput{
AllAvailabilityZones: aws.Bool(true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this returns the wavelength and other zones as well. I guess we only want these if the user has all_available_zones on the data.aws_availability_zones resource. I guess this is difficult because we have no way of knowing if the user has opted into them or not. So maybe if we find this is an issue with anyone in the future, we can always assume they've not opted into these zones as a default.

@hugorut hugorut force-pushed the feat/support-complex-fake-values branch from 179a9c3 to 74d20b4 Compare June 22, 2023 14:05
Goes some way to solving #1856

Adds support to return well-known values for blocks where mock data is insufficient. This is mostly applicable to data blocks. In particular data blocks such as `aws_availability_zones` where the return values can be inferred and don't require account/api access. This PR allows us to override the `Values` function for the `Block` with a more specific value func.

Initial supported blocks are:

* data.aws_availability_zones
* data.google_compute_zones
* resource.random_shuffle

This pr also resolves an issue where the provider data was being set incorrectly in the evaluation context, using the key `provider` instead of `aws`, `google`, e.t.c.
@hugorut hugorut force-pushed the feat/support-complex-fake-values branch from 74d20b4 to 6b7ec98 Compare June 22, 2023 14:33
@hugorut hugorut merged commit baa9cce into master Jun 22, 2023
7 of 10 checks passed
@hugorut hugorut deleted the feat/support-complex-fake-values branch June 22, 2023 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants