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

Remove TagSpecification from the EC2 instance spec #2025

Closed
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
8 changes: 0 additions & 8 deletions apis/ec2/manualv1alpha1/instances_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,6 @@ type InstanceParameters struct {
// +optional
Tags []Tag `json:"tags,omitempty"`

// The tags to apply to the resources during launch. You can only tag instances
// and volumes on launch. The specified tags are applied to all instances or
// volumes that are created during launch. To tag a resource after it has been
// created, see CreateTags (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html).
// +immutable
// +optional
TagSpecifications []TagSpecification `json:"tagSpecifications,omitempty"`

// The user data to make available to the instance. For more information, see
// Running Commands on Your Linux Instance at Launch (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html)
// (Linux) and Adding User Data (https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html#instancedata-add-user-data)
Expand Down
7 changes: 0 additions & 7 deletions apis/ec2/manualv1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 0 additions & 69 deletions package/crds/ec2.aws.crossplane.io_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1035,75 +1035,6 @@ spec:
type: string
type: object
type: object
tagSpecifications:
description: The tags to apply to the resources during launch.
You can only tag instances and volumes on launch. The specified
tags are applied to all instances or volumes that are created
during launch. To tag a resource after it has been created,
see CreateTags (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html).
items:
description: TagSpecification defines the tags to apply to a
resource when the resource is being created.
properties:
resourceType:
description: "The type of resource to tag. Currently, the
resource types that support tagging on creation are: capacity-reservation
| client-vpn-endpoint | dedicated-host | fleet | fpga-image
| instance | ipv4pool-ec2 | ipv6pool-ec2 | key-pair |
launch-template | natgateway | spot-fleet-request | placement-group
| snapshot | traffic-mirror-filter | traffic-mirror-session
| traffic-mirror-target | transit-gateway | transit-gateway-attachment
| transit-gateway-route-table | vpc-endpoint (for interface
VPC endpoints)| vpc-endpoint-service (for gateway VPC
endpoints) | volume | vpc-flow-log. \n To tag a resource
after it has been created, see CreateTags (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html)."
enum:
- capacity-reservation
- client-vpn-endpoint
- dedicated-host
- fleet
- fpga-image
- instance
- ipv4pool-ec2
- ipv6pool-ec2
- key-pair
- launch-template
- natgateway
- spot-fleet-request
- placement-group
- snapshot
- traffic-mirror-filter
- traffic-mirror-session
- traffic-mirror-target
- transit-gateway
- transit-gateway-attachment
- transit-gateway-route-table
- vpc-endpoint
- vpc-endpoint-service
- volume
- vpc-flow-log
type: string
tags:
description: The tags to apply to the resource
items:
description: Tag defines a tag
properties:
key:
description: Key is the name of the tag.
type: string
value:
description: Value is the value of the tag.
type: string
required:
- key
- value
type: object
type: array
required:
- resourceType
- tags
type: object
type: array
tags:
description: Tags are used as identification helpers between AWS
resources.
Expand Down
33 changes: 16 additions & 17 deletions pkg/clients/ec2/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
const (
// InstanceNotFound is the code that is returned by ec2 when the given InstanceID is not valid
InstanceNotFound = "InvalidInstanceID.NotFound"

// Instance type associated with EC2 instance tags
instanceResourceType = "instance"
)

// InstanceClient is the external client used for Instance Custom Resource
Expand Down Expand Up @@ -819,7 +822,7 @@ func GenerateEC2RunInstancesInput(name string, p *manualv1alpha1.InstanceParamet
RamdiskId: p.RAMDiskID,
SecurityGroupIds: p.SecurityGroupIDs,
SubnetId: p.SubnetID,
TagSpecifications: GenerateEC2TagSpecifications(p.TagSpecifications),
TagSpecifications: GenerateEC2TagSpecifications(p.Tags),
UserData: p.UserData,
}
}
Expand Down Expand Up @@ -852,25 +855,21 @@ func GenerateTags(tags []types.Tag) []manualv1alpha1.Tag {

// GenerateEC2TagSpecifications takes a slice of TagSpecifications and converts it to a
// slice of ec2.TagSpecification
func GenerateEC2TagSpecifications(tagSpecs []manualv1alpha1.TagSpecification) []types.TagSpecification {
if tagSpecs != nil {
res := make([]types.TagSpecification, len(tagSpecs))
for i, ts := range tagSpecs {
res[i] = types.TagSpecification{
ResourceType: types.ResourceType(*ts.ResourceType),
}
func GenerateEC2TagSpecifications(tags []manualv1alpha1.Tag) []types.TagSpecification {
if len(tags) > 0 {
tagSpec := types.TagSpecification{
ResourceType: types.ResourceType(instanceResourceType),
Tags: make([]types.Tag, len(tags)),
}

tags := make([]types.Tag, len(ts.Tags))
for i, t := range ts.Tags {
tags[i] = types.Tag{
Key: aws.String(t.Key),
Value: aws.String(t.Value),
}
for i, t := range tags {
tagSpec.Tags[i] = types.Tag{
Key: aws.String(t.Key),
Value: aws.String(t.Value),
}

res[i].Tags = tags
}
return res

return []types.TagSpecification{tagSpec}
}
return nil
}
Expand Down
11 changes: 3 additions & 8 deletions pkg/clients/ec2/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,10 @@ func TestGenerateEC2RunInstancesInput(t *testing.T) {
groupID,
},
SubnetID: aws.String(subnetID),
TagSpecifications: []manualv1alpha1.TagSpecification{
Tags: []manualv1alpha1.Tag{
{
ResourceType: aws.String(tagResourceType),
Tags: []manualv1alpha1.Tag{
{
Key: tagsKey,
Value: tagsVal,
},
},
Key: tagsKey,
Value: tagsVal,
},
},
UserData: aws.String(userData),
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ec2/instance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ func (e *external) Create(ctx context.Context, mgd resource.Managed) (managed.Ex
return managed.ExternalCreation{}, errors.New(errUnexpectedObject)
}

result, err := e.client.RunInstances(ctx,
ec2.GenerateEC2RunInstancesInput(mgd.GetName(), &cr.Spec.ForProvider),
)
input := ec2.GenerateEC2RunInstancesInput(mgd.GetName(), &cr.Spec.ForProvider)

result, err := e.client.RunInstances(ctx, input)
if err != nil {
return managed.ExternalCreation{}, errorutils.Wrap(err, errCreate)
}
Expand Down
Loading