Skip to content

Commit 73a7d27

Browse files
Merge pull request #144 from drone/CI-13677
fix: [CI-14032]: Add option to specify Amazon EC2 instance metadata a…
2 parents 6f9bdea + bf6c82e commit 73a7d27

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

cmd/drone-autoscaler/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ func setupProvider(c config.Config) (autoscaler.Provider, error) {
322322
amazon.WithVolumeThroughput(c.Amazon.VolumeThroughput),
323323
amazon.WithIamProfileArn(c.Amazon.IamProfileArn),
324324
amazon.WithMarketType(c.Amazon.MarketType),
325+
amazon.WithInstanceMetadataTokens(c.Amazon.IMDSTokens),
325326
), nil
326327
case os.Getenv("OS_USERNAME") != "":
327328
return openstack.New(

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type (
145145
VolumeThroughput int64 `envconfig:"DRONE_AMAZON_VOLUME_THROUGHPUT"`
146146
IamProfileArn string `envconfig:"DRONE_AMAZON_IAM_PROFILE_ARN"`
147147
MarketType string `envconfig:"DRONE_AMAZON_MARKET_TYPE"`
148+
IMDSTokens string `envconfig:"DRONE_AMAZON_IMDS_TOKENS"`
148149
}
149150

150151
DigitalOcean struct {

drivers/amazon/create.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ func (p *provider) create(ctx context.Context, opts autoscaler.InstanceCreateOpt
100100
tags := createCopy(p.tags)
101101
tags["Name"] = opts.Name
102102

103+
var metadataOptions *ec2.InstanceMetadataOptionsRequest
104+
if p.imdsTokens != "" {
105+
metadataOptions = &ec2.InstanceMetadataOptionsRequest{
106+
HttpTokens: aws.String(p.imdsTokens),
107+
}
108+
}
109+
103110
in := &ec2.RunInstancesInput{
104111
KeyName: aws.String(p.key),
105112
ImageId: aws.String(p.image),
@@ -109,6 +116,7 @@ func (p *provider) create(ctx context.Context, opts autoscaler.InstanceCreateOpt
109116
InstanceMarketOptions: marketOptions,
110117
IamInstanceProfile: iamProfile,
111118
UserData: aws.String(base64.StdEncoding.EncodeToString(buf.Bytes())),
119+
MetadataOptions: metadataOptions,
112120
NetworkInterfaces: []*ec2.InstanceNetworkInterfaceSpecification{
113121
{
114122
AssociatePublicIpAddress: aws.Bool(!p.privateIP),

drivers/amazon/option.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ func WithIamProfileArn(t string) Option {
152152
}
153153
}
154154

155+
// WithInstanceMetadataTokens returns an option to set the instance metadata service tokens requiment.
156+
func WithInstanceMetadataTokens(t string) Option {
157+
return func(p *provider) {
158+
p.imdsTokens = t
159+
}
160+
}
161+
155162
// WithMarketType returns an option to set the instance market type.
156163
func WithMarketType(t string) Option {
157164
return func(p *provider) {

drivers/amazon/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type provider struct {
3737
tags map[string]string
3838
iamProfileArn string
3939
spotInstance bool
40+
imdsTokens string
4041
}
4142

4243
func (p *provider) getClient() *ec2.EC2 {

0 commit comments

Comments
 (0)