Skip to content

Commit 04427ba

Browse files
authored
feat: nic-association resource (#64)
1 parent 40534b8 commit 04427ba

16 files changed

Lines changed: 324 additions & 65 deletions

File tree

docs/resources/network_interface.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ resource "multy_subnet" "subnet" {
2424
cidr_block = "10.0.2.0/24"
2525
virtual_network_id = multy_virtual_network.example_vn.id
2626
}
27+
resource "multy_public_ip" "ip" {
28+
name = "test-ip"
29+
cloud = "aws"
30+
location = "eu_west_1"
31+
}
2732
resource "multy_network_interface" "private-nic" {
28-
cloud = "aws"
29-
name = "test-private-nic"
30-
subnet_id = multy_subnet.subnet.id
31-
location = "eu_west_1"
33+
cloud = "aws"
34+
name = "test-private-nic"
35+
subnet_id = multy_subnet.subnet.id
36+
public_ip_id = multy_public_ip.ip.id
37+
location = "eu_west_1"
3238
}
3339
```
3440

@@ -42,6 +48,10 @@ resource "multy_network_interface" "private-nic" {
4248
- `name` (String) Name of Network Interface
4349
- `subnet_id` (String) ID of `subnet` resource
4450

51+
### Optional
52+
53+
- `public_ip_id` (String) ID of `public_ip` resource
54+
4555
### Read-Only
4656

4757
- `id` (String) The ID of this resource.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "multy_network_interface_security_group_association Resource - terraform-provider-multy"
4+
subcategory: ""
5+
description: |-
6+
Provides Multy Network Interface Security Group Association resource
7+
---
8+
9+
# multy_network_interface_security_group_association (Resource)
10+
11+
Provides Multy Network Interface Security Group Association resource
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "multy_network_interface" "nic" {
17+
cloud = "aws"
18+
name = "test-private-nic"
19+
subnet_id = multy_subnet.subnet.id
20+
location = "eu_west_1"
21+
}
22+
resource "multy_network_security_group" "nsg" {
23+
name = "test_nsg"
24+
virtual_network_id = multy_virtual_network.vn.id
25+
cloud = "aws"
26+
location = "eu_west_1"
27+
rule {
28+
protocol = "tcp"
29+
priority = 120
30+
from_port = 22
31+
to_port = 22
32+
cidr_block = "0.0.0.0/0"
33+
direction = "both"
34+
}
35+
}
36+
resource "multy_network_interface_security_group_association" "nic-association" {
37+
network_interface_id = multy_network_interface.nic.id
38+
security_group_id = multy_network_security_group.nsg.id
39+
}
40+
```
41+
42+
<!-- schema generated by tfplugindocs -->
43+
## Schema
44+
45+
### Required
46+
47+
- `network_interface_id` (String) ID of `network_interface` resource
48+
- `security_group_id` (String) ID of `security_group` resource
49+
50+
### Read-Only
51+
52+
- `id` (String) The ID of this resource.
53+
54+

docs/resources/public_ip.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ resource "multy_network_interface" "public-nic" {
2020
location = "eu_west_1"
2121
}
2222
resource "multy_public_ip" "ip" {
23-
name = "test-ip"
24-
network_interface_id = multy_network_interface.public-nic.id
25-
cloud = "aws"
26-
location = "eu_west_1"
23+
name = "test-ip"
24+
cloud = "aws"
25+
location = "eu_west_1"
2726
}
2827
```
2928

@@ -36,10 +35,6 @@ resource "multy_public_ip" "ip" {
3635
- `location` (String) Location to deploy resource into. Read more about regions in [documentation](https://docs.multy.dev/regions)
3736
- `name` (String) Name of Public IP
3837

39-
### Optional
40-
41-
- `network_interface_id` (String) Id of the network interface to associate public IP with
42-
4338
### Read-Only
4439

4540
- `id` (String) The ID of this resource.

examples/resources/multy_network_interface/resource.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ resource "multy_subnet" "subnet" {
99
cidr_block = "10.0.2.0/24"
1010
virtual_network_id = multy_virtual_network.example_vn.id
1111
}
12+
resource "multy_public_ip" "ip" {
13+
name = "test-ip"
14+
cloud = "aws"
15+
location = "eu_west_1"
16+
}
1217
resource "multy_network_interface" "private-nic" {
13-
cloud = "aws"
14-
name = "test-private-nic"
15-
subnet_id = multy_subnet.subnet.id
16-
location = "eu_west_1"
18+
cloud = "aws"
19+
name = "test-private-nic"
20+
subnet_id = multy_subnet.subnet.id
21+
public_ip_id = multy_public_ip.ip.id
22+
location = "eu_west_1"
1723
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
resource "multy_network_interface" "nic" {
2+
cloud = "aws"
3+
name = "test-private-nic"
4+
subnet_id = multy_subnet.subnet.id
5+
location = "eu_west_1"
6+
}
7+
resource "multy_network_security_group" "nsg" {
8+
name = "test_nsg"
9+
virtual_network_id = multy_virtual_network.vn.id
10+
cloud = "aws"
11+
location = "eu_west_1"
12+
rule {
13+
protocol = "tcp"
14+
priority = 120
15+
from_port = 22
16+
to_port = 22
17+
cidr_block = "0.0.0.0/0"
18+
direction = "both"
19+
}
20+
}
21+
resource "multy_network_interface_security_group_association" "nic-association" {
22+
network_interface_id = multy_network_interface.nic.id
23+
security_group_id = multy_network_security_group.nsg.id
24+
}

examples/resources/multy_public_ip/resource.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ resource "multy_network_interface" "public-nic" {
55
location = "eu_west_1"
66
}
77
resource "multy_public_ip" "ip" {
8-
name = "test-ip"
9-
network_interface_id = multy_network_interface.public-nic.id
10-
cloud = "aws"
11-
location = "eu_west_1"
8+
name = "test-ip"
9+
cloud = "aws"
10+
location = "eu_west_1"
1211
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ require (
1010
github.com/hashicorp/terraform-plugin-go v0.8.0
1111
github.com/hashicorp/terraform-plugin-log v0.3.0
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
13-
github.com/multycloud/multy v0.1.43
13+
github.com/multycloud/multy v0.1.45
1414
golang.org/x/exp v0.0.0-20220218215828-6cf2b201936e
1515
google.golang.org/grpc v1.45.0
1616
google.golang.org/protobuf v1.28.0
1717
)
1818

19-
//replace github.com/multycloud/multy v0.1.40 => ../multy
19+
//replace github.com/multycloud/multy v0.1.43 => ../multy
2020

2121
require (
2222
github.com/Azure/azure-sdk-for-go v59.2.0+incompatible // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
371371
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
372372
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
373373
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
374-
github.com/multycloud/multy v0.1.43 h1:/uxVHRU1rvdhMyTqikudQef0pWVBkMDMcETFhmrPF74=
375-
github.com/multycloud/multy v0.1.43/go.mod h1:ZRk8zUP2oOf5Jv72aLbwxqyDchzAVWvlWWXzcUn90jw=
374+
github.com/multycloud/multy v0.1.45 h1:aRU0mn+0j/gwFkZPPEPYAtYDwwrBaEYBxx5kTj3EI9c=
375+
github.com/multycloud/multy v0.1.45/go.mod h1:ZRk8zUP2oOf5Jv72aLbwxqyDchzAVWvlWWXzcUn90jw=
376376
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
377377
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
378378
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=

multy/provider.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,23 @@ func (p *Provider) ConfigureProvider(ctx context.Context, config providerData, r
237237

238238
func (p *Provider) GetResources(_ context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
239239
return map[string]tfsdk.ResourceType{
240-
"multy_virtual_network": ResourceVirtualNetworkType{},
241-
"multy_subnet": ResourceSubnetType{},
242-
"multy_virtual_machine": ResourceVirtualMachineType{},
243-
"multy_network_security_group": ResourceNetworkSecurityGroupType{},
244-
"multy_network_interface": ResourceNetworkInterfaceType{},
245-
"multy_public_ip": ResourcePublicIpType{},
246-
"multy_route_table": ResourceRouteTableType{},
247-
"multy_route_table_association": ResourceRouteTableAssociationType{},
248-
"multy_object_storage_object": ResourceObjectStorageObjectType{},
249-
"multy_object_storage": ResourceObjectStorageType{},
250-
"multy_database": ResourceDatabaseType{},
251-
"multy_vault": ResourceVaultType{},
252-
"multy_vault_secret": ResourceVaultSecretType{},
253-
"multy_vault_access_policy": ResourceVaultAccessPolicyType{},
254-
"multy_kubernetes_cluster": ResourceKubernetesClusterType{},
255-
"multy_kubernetes_node_pool": ResourceKubernetesNodePoolType{},
240+
"multy_virtual_network": ResourceVirtualNetworkType{},
241+
"multy_subnet": ResourceSubnetType{},
242+
"multy_virtual_machine": ResourceVirtualMachineType{},
243+
"multy_network_security_group": ResourceNetworkSecurityGroupType{},
244+
"multy_network_interface": ResourceNetworkInterfaceType{},
245+
"multy_network_interface_security_group_association": ResourceNetworkInterfaceSecurityGroupAssociationType{},
246+
"multy_public_ip": ResourcePublicIpType{},
247+
"multy_route_table": ResourceRouteTableType{},
248+
"multy_route_table_association": ResourceRouteTableAssociationType{},
249+
"multy_object_storage_object": ResourceObjectStorageObjectType{},
250+
"multy_object_storage": ResourceObjectStorageType{},
251+
"multy_database": ResourceDatabaseType{},
252+
"multy_vault": ResourceVaultType{},
253+
"multy_vault_secret": ResourceVaultSecretType{},
254+
"multy_vault_access_policy": ResourceVaultAccessPolicyType{},
255+
"multy_kubernetes_cluster": ResourceKubernetesClusterType{},
256+
"multy_kubernetes_node_pool": ResourceKubernetesNodePoolType{},
256257
}, nil
257258
}
258259

multy/resource_network_interface.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func (r ResourceNetworkInterfaceType) GetSchema(_ context.Context) (tfsdk.Schema
3939
Required: true,
4040
PlanModifiers: []tfsdk.AttributePlanModifier{tfsdk.RequiresReplace()},
4141
},
42+
"public_ip_id": {
43+
Type: types.StringType,
44+
Description: "ID of `public_ip` resource",
45+
Optional: true,
46+
PlanModifiers: []tfsdk.AttributePlanModifier{tfsdk.UseStateForUnknown()},
47+
},
4248
"cloud": common.CloudsSchema,
4349
"location": common.LocationSchema,
4450
},
@@ -97,6 +103,7 @@ type NetworkInterface struct {
97103
Id types.String `tfsdk:"id"`
98104
Name types.String `tfsdk:"name"`
99105
SubnetId types.String `tfsdk:"subnet_id"`
106+
PublicIpId types.String `tfsdk:"public_ip_id"`
100107
Cloud mtypes.EnumValue[commonpb.CloudProvider] `tfsdk:"cloud"`
101108
Location mtypes.EnumValue[commonpb.Location] `tfsdk:"location"`
102109
ResourceGroupId types.String `tfsdk:"resource_group_id"`
@@ -108,6 +115,7 @@ func convertToNetworkInterface(res *resourcespb.NetworkInterfaceResource) Networ
108115
ResourceGroupId: types.String{Value: res.CommonParameters.ResourceGroupId},
109116
Name: types.String{Value: res.Name},
110117
SubnetId: types.String{Value: res.SubnetId},
118+
PublicIpId: common.DefaultToNull[types.String](res.PublicIpId),
111119
Cloud: mtypes.CloudType.NewVal(res.CommonParameters.CloudProvider),
112120
Location: mtypes.LocationType.NewVal(res.CommonParameters.Location),
113121
}
@@ -120,7 +128,8 @@ func convertFromNetworkInterface(plan NetworkInterface) *resourcespb.NetworkInte
120128
Location: plan.Location.Value,
121129
CloudProvider: plan.Cloud.Value,
122130
},
123-
Name: plan.Name.Value,
124-
SubnetId: plan.SubnetId.Value,
131+
Name: plan.Name.Value,
132+
SubnetId: plan.SubnetId.Value,
133+
PublicIpId: plan.PublicIpId.Value,
125134
}
126135
}

0 commit comments

Comments
 (0)