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

rd/ami resources - add attributes #13971

Merged
merged 12 commits into from
Feb 18, 2021
14 changes: 14 additions & 0 deletions .changelog/13971.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
```release-note:enhancement
resource/aws_ami: Add `usage_operation`, `platform_details`, `image_owner_alias`, `image_type`, `hypervisor`, `owner_id`, `platform`, `public` attributes
```
```release-note:enhancement
resource/aws_ami_copy: Add `usage_operation`, `platform_details`, `image_owner_alias`, `image_type`, `hypervisor`, `owner_id`, `platform`, `public` attributes
```

```release-note:enhancement
resource/aws_ami_from_instance: Add `usage_operation`, `platform_details`, `image_owner_alias`, `image_type`, `hypervisor`, `owner_id`, `platform`, `public` attributes
```

```release-note:enhancement
data-source/aws_ami: Add `usage_operation`, `platform_details`, `ena_support` attributes
```
16 changes: 16 additions & 0 deletions aws/data_source_aws_ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ func dataSourceAwsAmi() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"usage_operation": {
Type: schema.TypeString,
Computed: true,
},
"platform_details": {
Type: schema.TypeString,
Computed: true,
},
"ena_support": {
Type: schema.TypeBool,
Computed: true,
},
// Complex computed values
"block_device_mappings": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -287,6 +299,10 @@ func amiDescriptionAttributes(d *schema.ResourceData, image *ec2.Image, meta int
}
d.Set("state", image.State)
d.Set("virtualization_type", image.VirtualizationType)
d.Set("usage_operation", image.UsageOperation)
d.Set("platform_details", image.PlatformDetails)
d.Set("ena_support", image.EnaSupport)

// Complex types get their own functions
if err := d.Set("block_device_mappings", amiBlockDeviceMappings(image.BlockDeviceMappings)); err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions aws/data_source_aws_ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func TestAccAWSAmiDataSource_natInstance(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "state_reason.message", "UNSET"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "virtualization_type", "hvm"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Linux/UNIX"),
resource.TestCheckResourceAttr(resourceName, "ena_support", "true"),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances"),
),
},
},
Expand Down Expand Up @@ -91,6 +94,9 @@ func TestAccAWSAmiDataSource_windowsInstance(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "state_reason.message", "UNSET"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "virtualization_type", "hvm"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Windows"),
bflad marked this conversation as resolved.
Show resolved Hide resolved
resource.TestCheckResourceAttr(resourceName, "ena_support", "true"),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances:0002"),
bflad marked this conversation as resolved.
Show resolved Hide resolved
),
},
},
Expand Down Expand Up @@ -127,6 +133,9 @@ func TestAccAWSAmiDataSource_instanceStore(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "state_reason.message", "UNSET"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "virtualization_type", "hvm"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Linux/UNIX"),
resource.TestCheckResourceAttr(resourceName, "ena_support", "true"),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances"),
),
},
},
Expand Down
73 changes: 53 additions & 20 deletions aws/resource_aws_ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ func resourceAwsAmi() *schema.Resource {
ForceNew: true,
},
"architecture": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ec2.ArchitectureTypeX8664,
ValidateFunc: validation.StringInSlice([]string{
ec2.ArchitectureTypeX8664,
ec2.ArchitectureValuesI386,
ec2.ArchitectureValuesArm64,
}, false),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ec2.ArchitectureValuesX8664,
ValidateFunc: validation.StringInSlice(ec2.ArchitectureValues_Values(), false),
},
"description": {
Type: schema.TypeString,
Expand Down Expand Up @@ -212,19 +208,48 @@ func resourceAwsAmi() *schema.Resource {
},
"tags": tagsSchema(),
"virtualization_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ec2.VirtualizationTypeParavirtual,
ValidateFunc: validation.StringInSlice([]string{
ec2.VirtualizationTypeParavirtual,
ec2.VirtualizationTypeHvm,
}, false),
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: ec2.VirtualizationTypeParavirtual,
ValidateFunc: validation.StringInSlice(ec2.VirtualizationType_Values(), false),
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"usage_operation": {
Type: schema.TypeString,
Computed: true,
},
"platform_details": {
Type: schema.TypeString,
Computed: true,
},
"image_owner_alias": {
Type: schema.TypeString,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
Computed: true,
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"platform": {
Type: schema.TypeString,
Computed: true,
},
"public": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -287,7 +312,7 @@ func resourceAwsAmiCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

id := *res.ImageId
id := aws.StringValue(res.ImageId)
d.SetId(id)

if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
Expand Down Expand Up @@ -346,7 +371,7 @@ func resourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
}

image := res.Images[0]
state := *image.State
state := aws.StringValue(image.State)

if state == ec2.ImageStatePending {
// This could happen if a user manually adds an image we didn't create
Expand Down Expand Up @@ -382,6 +407,14 @@ func resourceAwsAmiRead(d *schema.ResourceData, meta interface{}) error {
d.Set("sriov_net_support", image.SriovNetSupport)
d.Set("virtualization_type", image.VirtualizationType)
d.Set("ena_support", image.EnaSupport)
d.Set("usage_operation", image.UsageOperation)
d.Set("platform_details", image.PlatformDetails)
d.Set("hypervisor", image.Hypervisor)
d.Set("image_type", image.ImageType)
d.Set("owner_id", image.OwnerId)
d.Set("public", image.Public)
d.Set("image_owner_alias", image.ImageOwnerAlias)
d.Set("platform", image.Platform)

imageArn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Expand Down Expand Up @@ -500,7 +533,7 @@ func AMIStateRefreshFunc(client *ec2.EC2, id string) resource.StateRefreshFunc {
}

// AMI is valid, so return it's state
return resp.Images[0], *resp.Images[0].State, nil
return resp.Images[0], aws.StringValue(resp.Images[0].State), nil
}
}

Expand Down
32 changes: 32 additions & 0 deletions aws/resource_aws_ami_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,38 @@ func resourceAwsAmiCopy() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"usage_operation": {
Type: schema.TypeString,
Computed: true,
},
"platform_details": {
Type: schema.TypeString,
Computed: true,
},
"image_owner_alias": {
Type: schema.TypeString,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
Computed: true,
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"platform": {
Type: schema.TypeString,
Computed: true,
},
"public": {
Type: schema.TypeBool,
Computed: true,
},
},

// The remaining operations are shared with the generic aws_ami resource,
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_ami_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TestAccAWSAMICopy_basic(t *testing.T) {
testAccCheckAWSAMICopyExists(resourceName, &image),
testAccCheckAWSAMICopyAttributes(&image, rName),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "ec2", regexp.MustCompile(`image/ami-.+`)),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Linux/UNIX"),
resource.TestCheckResourceAttr(resourceName, "image_type", "machine"),
resource.TestCheckResourceAttr(resourceName, "hypervisor", "xen"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
),
},
},
Expand Down
32 changes: 32 additions & 0 deletions aws/resource_aws_ami_from_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ func resourceAwsAmiFromInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"usage_operation": {
Type: schema.TypeString,
Computed: true,
},
"platform_details": {
Type: schema.TypeString,
Computed: true,
},
"image_owner_alias": {
Type: schema.TypeString,
Computed: true,
},
"image_type": {
Type: schema.TypeString,
Computed: true,
},
"hypervisor": {
Type: schema.TypeString,
Computed: true,
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"platform": {
Type: schema.TypeString,
Computed: true,
},
"public": {
Type: schema.TypeBool,
Computed: true,
},
},

// The remaining operations are shared with the generic aws_ami resource,
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_ami_from_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ func TestAccAWSAMIFromInstance_basic(t *testing.T) {
testAccCheckAWSAMIFromInstanceExists(resourceName, &image),
testAccMatchResourceAttrRegionalARNNoAccount(resourceName, "arn", "ec2", regexp.MustCompile(`image/ami-.+`)),
resource.TestCheckResourceAttr(resourceName, "description", "Testing Terraform aws_ami_from_instance resource"),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Linux/UNIX"),
resource.TestCheckResourceAttr(resourceName, "image_type", "machine"),
resource.TestCheckResourceAttr(resourceName, "hypervisor", "xen"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
),
},
},
Expand Down
8 changes: 7 additions & 1 deletion aws/resource_aws_ami_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func TestAccAWSAMI_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "sriov_net_support", "simple"),
resource.TestCheckResourceAttr(resourceName, "virtualization_type", "hvm"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "usage_operation", "RunInstances"),
resource.TestCheckResourceAttr(resourceName, "platform_details", "Linux/UNIX"),
resource.TestCheckResourceAttr(resourceName, "image_type", "machine"),
resource.TestCheckResourceAttr(resourceName, "hypervisor", "xen"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
),
},
{
Expand Down Expand Up @@ -367,7 +372,8 @@ func testAccCheckAmiDestroy(s *terraform.State) error {

if len(resp.Images) > 0 {
state := resp.Images[0].State
return fmt.Errorf("AMI %s still exists in the state: %s.", *resp.Images[0].ImageId, *state)
return fmt.Errorf("AMI %s still exists in the state: %s.", aws.StringValue(resp.Images[0].ImageId),
aws.StringValue(state))
}
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions website/docs/d/ami.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,8 @@ interpolation.
* `tags.#.value` - The value of the tag.
* `virtualization_type` - The type of virtualization of the AMI (ie: `hvm` or
`paravirtual`).
* `usage_operation` - The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
* `platform_details` - The platform details associated with the billing code of the AMI.
* `ena_support` - Specifies whether enhanced networking with ENA is enabled.

[1]: http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html
8 changes: 8 additions & 0 deletions website/docs/r/ami.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ In addition to all arguments above, the following attributes are exported:
* `arn` - The ARN of the AMI.
* `id` - The ID of the created AMI.
* `root_snapshot_id` - The Snapshot ID for the root volume (for EBS-backed AMIs)
* `usage_operation` - The operation of the Amazon EC2 instance and the billing code that is associated with the AMI.
* `platform_details` - The platform details associated with the billing code of the AMI.
* `image_owner_alias` - The AWS account alias (for example, amazon, self) or the AWS account ID of the AMI owner.
* `image_type` - The type of image.
* `hypervisor` - The hypervisor type of the image.
* `owner_id` - The AWS account ID of the image owner.
* `platform` - This value is set to windows for Windows AMIs; otherwise, it is blank.
* `public` - Indicates whether the image has public launch permissions.

## Import

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/ami_copy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ In addition to all arguments above, the following attributes are exported:
* `id` - The ID of the created AMI.

This resource also exports a full set of attributes corresponding to the arguments of the
[`aws_ami`](ami.html) resource, allowing the properties of the created AMI to be used elsewhere in the
[`aws_ami`](/docs/providers/aws/r/ami.html) resource, allowing the properties of the created AMI to be used elsewhere in the
configuration.
2 changes: 1 addition & 1 deletion website/docs/r/ami_from_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ In addition to all arguments above, the following attributes are exported:
* `id` - The ID of the created AMI.

This resource also exports a full set of attributes corresponding to the arguments of the
`aws_ami` resource, allowing the properties of the created AMI to be used elsewhere in the
[`aws_ami`](/docs/providers/aws/r/ami.html) resource, allowing the properties of the created AMI to be used elsewhere in the
configuration.