forked from kubernetes/kops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc_dhcpoptions_association.go
94 lines (75 loc) · 2.35 KB
/
vpc_dhcpoptions_association.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package awstasks
import (
"fmt"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/golang/glog"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
)
type VPCDHCPOptionsAssociation struct {
VPC *VPC
DHCPOptions *DHCPOptions
}
func (e *VPCDHCPOptionsAssociation) String() string {
return fi.TaskAsString(e)
}
func (e *VPCDHCPOptionsAssociation) Find(c *fi.Context) (*VPCDHCPOptionsAssociation, error) {
cloud := c.Cloud.(awsup.AWSCloud)
vpcID := e.VPC.ID
dhcpOptionsID := e.DHCPOptions.ID
if vpcID == nil || dhcpOptionsID == nil {
return nil, nil
}
vpc, err := cloud.DescribeVPC(*vpcID)
if err != nil {
return nil, err
}
actual := &VPCDHCPOptionsAssociation{}
actual.VPC = &VPC{ID: vpc.VpcId}
actual.DHCPOptions = &DHCPOptions{ID: vpc.DhcpOptionsId}
return actual, nil
}
func (e *VPCDHCPOptionsAssociation) Run(c *fi.Context) error {
return fi.DefaultDeltaRunMethod(e, c)
}
func (s *VPCDHCPOptionsAssociation) CheckChanges(a, e, changes *VPCDHCPOptionsAssociation) error {
if e.VPC == nil {
return fi.RequiredField("VPC")
}
if e.DHCPOptions == nil {
return fi.RequiredField("DHCPOptions")
}
if a != nil && changes != nil {
if changes.VPC != nil {
// Should be impossible anyway because VPC is our primary key...
return fi.CannotChangeField("VPC")
}
}
return nil
}
func (_ *VPCDHCPOptionsAssociation) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *VPCDHCPOptionsAssociation) error {
if changes.DHCPOptions != nil {
glog.V(2).Infof("calling EC2 AssociateDhcpOptions")
request := &ec2.AssociateDhcpOptionsInput{
VpcId: e.VPC.ID,
DhcpOptionsId: e.DHCPOptions.ID,
}
_, err := t.Cloud.EC2().AssociateDhcpOptions(request)
if err != nil {
return fmt.Errorf("error creating VPCDHCPOptionsAssociation: %v", err)
}
}
return nil // no tags
}
type terraformVPCDHCPOptionsAssociation struct {
VPCID *terraform.Literal `json:"vpc_id"`
DHCPOptionsID *terraform.Literal `json:"dhcp_options_id"`
}
func (_ *VPCDHCPOptionsAssociation) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPCDHCPOptionsAssociation) error {
tf := &terraformVPCDHCPOptionsAssociation{
VPCID: e.VPC.TerraformLink(),
DHCPOptionsID: e.DHCPOptions.TerraformLink(),
}
return t.RenderResource("aws_vpc_dhcp_options_association", *e.VPC.Name, tf)
}