Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 050a6a9

Browse files
ndegoryDavid Chung
authored andcommitted
Terraform plugin private IP and logicalID allocation (#395)
Signed-off-by: Nicolas Degory <[email protected]>
1 parent 5a9cddb commit 050a6a9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

examples/instance/terraform/plugin.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,20 @@ func (p *plugin) Provision(spec instance.Spec) (*instance.ID, error) {
389389
m["LogicalID"] = string(*spec.LogicalID)
390390
}
391391
}
392+
switch properties.Type {
393+
case "aws_instance":
394+
if p, exists := properties.Value["private_ip"]; exists {
395+
if p == "INSTANCE_LOGICAL_ID" {
396+
if spec.LogicalID != nil {
397+
// set private IP to logical ID
398+
properties.Value["private_ip"] = string(*spec.LogicalID)
399+
} else {
400+
// reset private IP (the tag is not relevant in this context)
401+
delete(properties.Value, "private_ip")
402+
}
403+
}
404+
}
405+
}
392406

393407
// merge the inits
394408
switch properties.Type {

examples/instance/terraform/plugin_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestUsage(t *testing.T) {
4848
"key_name": "PUBKEY",
4949
"vpc_security_group_ids" : ["${aws_security_group.default.id}"],
5050
"subnet_id": "${aws_subnet.default.id}",
51+
"private_ip": "INSTANCE_LOGICAL_ID",
5152
"tags" : {
5253
"Name" : "web4",
5354
"InstancePlugin" : "terraform"

0 commit comments

Comments
 (0)