generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 40
/
infra_aws_lambda.go
118 lines (100 loc) · 3.04 KB
/
infra_aws_lambda.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package environment
import (
"github.com/harness/harness-go-sdk/harness/cd/cac"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func infraDetailsAwsLambda() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"cloud_provider_name": {
Description: "The name of the cloud provider to connect with.",
Type: schema.TypeString,
Required: true,
},
"iam_role": {
Description: "The IAM role to use.",
Type: schema.TypeString,
Optional: true,
},
"region": {
Description: "The region to deploy to.",
Type: schema.TypeString,
Required: true,
},
"security_group_ids": {
Description: "The security group ids to apply to the ecs service.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"subnet_ids": {
Description: "The subnet ids to apply to the ecs service.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"vpc_id": {
Description: "The VPC ids to use when selecting the instances.",
Type: schema.TypeString,
Optional: true,
},
},
}
}
func expandAwsLambdaConfiguration(d []interface{}, infraDef *cac.InfrastructureDefinition) {
if len(d) == 0 {
return
}
config := d[0].(map[string]interface{})
details := &cac.InfrastructureAwsLambda{}
if attr := config["cloud_provider_name"]; attr != "" {
details.CloudProviderName = attr.(string)
}
if attr := config["iam_role"]; attr != "" {
details.IamRole = attr.(string)
}
if attr := config["region"]; attr != "" {
details.Region = attr.(string)
}
if attr := config["security_group_ids"]; attr != nil {
sgs := []string{}
for _, sg := range attr.(*schema.Set).List() {
sgs = append(sgs, sg.(string))
}
if len(sgs) > 0 {
details.SecurityGroupIds = sgs
}
}
if attr := config["subnet_ids"]; attr != nil {
subnets := []string{}
for _, subnet := range attr.(*schema.Set).List() {
subnets = append(subnets, subnet.(string))
}
if len(subnets) > 0 {
details.SubnetIds = subnets
}
}
if attr := config["vpc_id"]; attr != "" {
details.VpcId = attr.(string)
}
infraDef.InfrastructureDetail = details.ToInfrastructureDetail()
}
func flattenAwsLambdaConfiguration(d *schema.ResourceData, infraDef *cac.InfrastructureDefinition) []interface{} {
results := []interface{}{}
if len(infraDef.InfrastructureDetail) == 0 {
return results
}
detail := infraDef.InfrastructureDetail[0]
if detail.Type != cac.InfrastructureTypes.AwsLambda {
return results
}
detailConfig := map[string]interface{}{}
infraDetail := detail.ToAwsLambda()
detailConfig["cloud_provider_name"] = infraDetail.CloudProviderName
detailConfig["iam_role"] = infraDetail.IamRole
detailConfig["region"] = infraDetail.Region
detailConfig["security_group_ids"] = infraDetail.SecurityGroupIds
detailConfig["subnet_ids"] = infraDetail.SubnetIds
detailConfig["vpc_id"] = infraDetail.VpcId
return append(results, detailConfig)
}