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

provider: Stabilization of singular data source id attributes with clear identifiers #15399

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions aws/data_source_aws_acm_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/acm"
Expand Down Expand Up @@ -169,7 +168,7 @@ func dataSourceAwsAcmCertificateRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("No certificate for domain %q found in this region", target)
}

d.SetId(time.Now().UTC().String())
d.SetId(aws.StringValue(matchedCertificate.CertificateArn))
d.Set("arn", matchedCertificate.CertificateArn)

tags, err := keyvaluetags.AcmListTags(conn, aws.StringValue(matchedCertificate.CertificateArn))
Expand Down
10 changes: 1 addition & 9 deletions aws/data_source_aws_autoscaling_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
Expand Down Expand Up @@ -105,7 +104,6 @@ func dataSourceAwsAutoscalingGroup() *schema.Resource {

func dataSourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).autoscalingconn
d.SetId(time.Now().UTC().String())

groupName := d.Get("name").(string)

Expand Down Expand Up @@ -142,13 +140,7 @@ func dataSourceAwsAutoscalingGroupRead(d *schema.ResourceData, meta interface{})

log.Printf("[DEBUG] aws_autoscaling_group - Single Auto Scaling Group found: %s", *group.AutoScalingGroupName)

err1 := groupDescriptionAttributes(d, group)
return err1
}

// Populate group attribute fields with the returned group
func groupDescriptionAttributes(d *schema.ResourceData, group *autoscaling.Group) error {
log.Printf("[DEBUG] Setting attributes: %s", group)
d.SetId(aws.StringValue(group.AutoScalingGroupName))
d.Set("name", group.AutoScalingGroupName)
d.Set("arn", group.AutoScalingGroupARN)
if err := d.Set("availability_zones", aws.StringValueSlice(group.AvailabilityZones)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_availability_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"log"
"sort"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -65,7 +64,6 @@ func dataSourceAwsAvailabilityZonesRead(d *schema.ResourceData, meta interface{}
conn := meta.(*AWSClient).ec2conn

log.Printf("[DEBUG] Reading Availability Zones.")
d.SetId(time.Now().UTC().String())

request := &ec2.DescribeAvailabilityZonesInput{}

Expand Down Expand Up @@ -130,6 +128,8 @@ func dataSourceAwsAvailabilityZonesRead(d *schema.ResourceData, meta interface{}
zoneIds = append(zoneIds, zoneID)
}

d.SetId(meta.(*AWSClient).region)

if err := d.Set("group_names", groupNames); err != nil {
return fmt.Errorf("error setting group_names: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_db_event_categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -56,7 +55,7 @@ func dataSourceAwsDbEventCategoriesRead(d *schema.ResourceData, meta interface{}
}
}

d.SetId(resource.UniqueId())
d.SetId(meta.(*AWSClient).region)
if err := d.Set("event_categories", eventCategories); err != nil {
return fmt.Errorf("Error setting Event Categories: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_ebs_default_kms_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -28,7 +27,7 @@ func dataSourceAwsEbsDefaultKmsKeyRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error reading EBS default KMS key: %q", err)
}

d.SetId(time.Now().UTC().String())
d.SetId(meta.(*AWSClient).region)
d.Set("key_arn", res.KmsKeyId)

return nil
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_ebs_encryption_by_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -28,7 +27,7 @@ func dataSourceAwsEbsEncryptionByDefaultRead(d *schema.ResourceData, meta interf
return fmt.Errorf("Error reading default EBS encryption toggle: %q", err)
}

d.SetId(time.Now().UTC().String())
d.SetId(meta.(*AWSClient).region)
d.Set("enabled", res.EbsEncryptionByDefault)

return nil
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_ec2_instance_type_offering.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand Down Expand Up @@ -122,7 +121,7 @@ func dataSourceAwsEc2InstanceTypeOfferingRead(d *schema.ResourceData, meta inter

d.Set("instance_type", resultInstanceType)

d.SetId(resource.UniqueId())
d.SetId(resultInstanceType)

return nil
}
2 changes: 1 addition & 1 deletion aws/data_source_aws_ecr_authorization_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func dataSourceAwsEcrAuthorizationTokenRead(d *schema.ResourceData, meta interfa
}
userName := basicAuthorization[0]
password := basicAuthorization[1]
d.SetId(time.Now().UTC().String())
d.SetId(meta.(*AWSClient).region)
d.Set("authorization_token", authorizationToken)
d.Set("proxy_endpoint", proxyEndpoint)
d.Set("expires_at", expiresAt)
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_ecr_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecr"
Expand Down Expand Up @@ -98,7 +97,7 @@ func dataSourceAwsEcrImageRead(d *schema.ResourceData, meta interface{}) error {

image := imageDetails[0]

d.SetId(time.Now().UTC().String())
d.SetId(aws.StringValue(image.ImageDigest))
if err = d.Set("registry_id", aws.StringValue(image.RegistryId)); err != nil {
return fmt.Errorf("failed to set registry_id: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_eks_cluster_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -41,7 +40,7 @@ func dataSourceAwsEksClusterAuthRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("error getting token: %v", err)
}

d.SetId(time.Now().UTC().String())
d.SetId(name)
d.Set("token", token.Token)

return nil
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_iam_account_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
Expand All @@ -27,7 +26,6 @@ func dataSourceAwsIamAccountAliasRead(d *schema.ResourceData, meta interface{})
conn := meta.(*AWSClient).iamconn

log.Printf("[DEBUG] Reading IAM Account Aliases.")
d.SetId(time.Now().UTC().String())

req := &iam.ListAccountAliasesInput{}
resp, err := conn.ListAccountAliases(req)
Expand All @@ -41,6 +39,7 @@ func dataSourceAwsIamAccountAliasRead(d *schema.ResourceData, meta interface{})
}

alias := aws.StringValue(resp.AccountAliases[0])
d.SetId(alias)
log.Printf("[DEBUG] Setting AWS IAM Account Alias to %s.", alias)
d.Set("account_alias", alias)

Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_kms_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/kms"
Expand Down Expand Up @@ -60,7 +59,7 @@ func dataSourceAwsKmsAliasRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("No alias with name %q found in this region.", target)
}

d.SetId(time.Now().UTC().String())
d.SetId(aws.StringValue(alias.AliasArn))
d.Set("arn", alias.AliasArn)

// ListAliases can return an alias for an AWS service key (e.g.
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aws

import (
"log"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -28,7 +27,7 @@ func dataSourceAwsPartitionRead(d *schema.ResourceData, meta interface{}) error
client := meta.(*AWSClient)

log.Printf("[DEBUG] Reading Partition.")
d.SetId(time.Now().UTC().String())
d.SetId(meta.(*AWSClient).partition)

log.Printf("[DEBUG] Setting AWS Partition to %s.", client.partition)
d.Set("partition", meta.(*AWSClient).partition)
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -53,7 +52,7 @@ func dataSourceAwsRegionsRead(d *schema.ResourceData, meta interface{}) error {
names = append(names, aws.StringValue(v.RegionName))
}

d.SetId(time.Now().UTC().String())
d.SetId(meta.(*AWSClient).partition)
if err := d.Set("names", names); err != nil {
return fmt.Errorf("error setting names: %s", err)
}
Expand Down
3 changes: 1 addition & 2 deletions aws/data_source_aws_sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/service/sns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -65,7 +64,7 @@ func dataSourceAwsSnsTopicsRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Multiple topics with name %q found in this region.", target)
}

d.SetId(time.Now().UTC().String())
d.SetId(arns[0])
d.Set("arn", arns[0])

return nil
Expand Down
3 changes: 2 additions & 1 deletion website/docs/d/acm_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ data "aws_acm_certificate" "rsa_4096" {

## Attributes Reference

* `arn` - Set to the ARN of the found certificate, suitable for referencing in other resources that support ACM certificates.
* `arn` - Amazon Resource Name (ARN) of the found certificate, suitable for referencing in other resources that support ACM certificates.
* `id` - Amazon Resource Name (ARN) of the found certificate, suitable for referencing in other resources that support ACM certificates.
* `tags` - A mapping of tags for the resource.

3 changes: 2 additions & 1 deletion website/docs/d/autoscaling_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ data "aws_autoscaling_group" "foo" {
interpolation.

* `arn` - The Amazon Resource Name (ARN) of the Auto Scaling group.
* `name` - The name of the Auto Scaling group.
* `availability_zones` - One or more Availability Zones for the group.
* `default_cool_down` - The amount of time, in seconds, after a scaling activity completes before another scaling activity can start.
* `desired_capacity` - The desired size of the group.
* `health_check_grace_period` - The amount of time, in seconds, that Amazon EC2 Auto Scaling waits before checking the health status of an EC2 instance that has come into service.
* `health_check_type` - The service to use for the health checks. The valid values are EC2 and ELB.
* `id` - Name of the Auto Scaling Group.
* `launch_configuration` - The name of the associated launch configuration.
* `load_balancers` - One or more load balancers associated with the group.
* `max_size` - The maximum size of the group.
* `min_size` - The minimum size of the group.
* `name` - Name of the Auto Scaling Group.
* `placement_group` - The name of the placement group into which to launch your instances, if any. For more information, see Placement Groups (http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/placement-groups.html) in the Amazon Elastic Compute Cloud User Guide.
* `service_linked_role_arn` - The Amazon Resource Name (ARN) of the service-linked role that the Auto Scaling group uses to call other AWS services on your behalf.
* `status` - The current state of the group when DeleteAutoScalingGroup is in progress.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/availability_zones.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The following arguments are supported by the `filter` configuration block:
In addition to all arguments above, the following attributes are exported:

* `group_names` A set of the Availability Zone Group names. For Availability Zones, this is the same value as the Region name. For Local Zones, the name of the associated group, for example `us-west-2-lax-1`.
* `id` - Region of the Availability Zones.
* `names` - A list of the Availability Zone names available to the account.
* `zone_ids` - A list of the Availability Zone IDs available to the account.

Expand Down
1 change: 1 addition & 0 deletions website/docs/d/db_event_categories.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `event_categories` - A list of the event categories.
* `id` - Region of the event categories.
1 change: 1 addition & 0 deletions website/docs/d/ebs_default_kms_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ resource "aws_ebs_volume" "example" {
The following attributes are exported:

* `key_arn` - Amazon Resource Name (ARN) of the default KMS key uses to encrypt an EBS volume in this region when no key is specified in an API call that creates the volume and encryption by default is enabled.
* `id` - Region of the default KMS Key.
1 change: 1 addition & 0 deletions website/docs/d/ebs_encryption_by_default.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ data "aws_ebs_encryption_by_default" "current" {}
The following attributes are exported:

* `enabled` - Whether or not default EBS encryption is enabled. Returns as `true` or `false`.
* `id` - Region of default EBS encryption.
1 change: 1 addition & 0 deletions website/docs/d/ec2_instance_type_offering.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `id` - EC2 Instance Type.
* `instance_type` - EC2 Instance Type.
5 changes: 3 additions & 2 deletions website/docs/d/ecr_authorization_token.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ The following arguments are supported:
In addition to the argument above, the following attributes are exported:

* `authorization_token` - Temporary IAM authentication credentials to access the ECR repository encoded in base64 in the form of `user_name:password`.
* `proxy_endpoint` - The registry URL to use in the docker login command.
* `expires_at` - The time in UTC RFC3339 format when the authorization token expires.
* `user_name` - User name decoded from the authorization token.
* `id` - Region of the authorization token.
* `password` - Password decoded from the authorization token.
* `proxy_endpoint` - The registry URL to use in the docker login command.
* `user_name` - User name decoded from the authorization token.
1 change: 1 addition & 0 deletions website/docs/d/ecr_image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `id` - SHA256 digest of the image manifest.
* `image_pushed_at` - The date and time, expressed as a unix timestamp, at which the current image was pushed to the repository.
* `image_size_in_bytes` - The size, in bytes, of the image in the repository.
* `image_tags` - The list of tags associated with this image.
1 change: 1 addition & 0 deletions website/docs/d/eks_cluster_auth.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ provider "kubernetes" {

## Attributes Reference

* `id` - Name of the cluster.
* `token` - The token to use to authenticate with the cluster.
1 change: 1 addition & 0 deletions website/docs/d/iam_account_alias.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ There are no arguments available for this data source.
In addition to all arguments above, the following attributes are exported:

* `account_alias` - The alias associated with the AWS account.
* `id` - The alias associated with the AWS account.
1 change: 1 addition & 0 deletions website/docs/d/kms_alias.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data "aws_kms_alias" "s3" {
## Attributes Reference

* `arn` - The Amazon Resource Name(ARN) of the key alias.
* `id` - The Amazon Resource Name(ARN) of the key alias.
* `target_key_id` - Key identifier pointed to by the alias.
* `target_key_arn` - ARN pointed to by the alias.
5 changes: 3 additions & 2 deletions website/docs/d/partition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ There are no arguments available for this data source.

## Attributes Reference

* `partition` is set to the identifier of the current partition.
* `dns_suffix` is set to the base DNS domain name for the current partition (e.g. `amazonaws.com` in AWS Commercial, `amazonaws.com.cn` in AWS China).
* `dns_suffix` - Base DNS domain name for the current partition (e.g. `amazonaws.com` in AWS Commercial, `amazonaws.com.cn` in AWS China).
* `id` - Identifier of the current partition (e.g. `aws` in AWS Commercial, `aws-cn` in AWS China).
* `partition` - Identifier of the current partition (e.g. `aws` in AWS Commercial, `aws-cn` in AWS China).
1 change: 1 addition & 0 deletions website/docs/d/regions.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The following arguments are supported by the `filter` configuration block:

In addition to all arguments above, the following attributes are exported:

* `id` - Identifier of the current partition (e.g. `aws` in AWS Commercial, `aws-cn` in AWS China).
* `names` - Names of regions that meets the criteria.

[1]: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-regions.html
5 changes: 4 additions & 1 deletion website/docs/d/sns_topic.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ data "aws_sns_topic" "example" {

## Attributes Reference

* `arn` - Set to the ARN of the found topic, suitable for referencing in other resources that support SNS topics.
In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name (ARN) of the found topic, suitable for referencing in other resources that support SNS topics.
* `id` - Amazon Resource Name (ARN) of the found topic, suitable for referencing in other resources that support SNS topics.