Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated byovpc network config for GCP #1748

Merged
merged 7 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions mws/mws.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,30 @@ type NetworkVPCEndpoints struct {
DataplaneRelayAPI []string `json:"dataplane_relay" tf:"slice_set"`
}

// GcpNetworkInfo is the object that configures byovpc settings for gcp
type GcpNetworkInfo struct {
NetworkProjectId string `json:"network_project_id"`
VpcId string `json:"vpc_id"`
SubnetId string `json:"subnet_id"`
SubnetRegion string `json:"subnet_region"`
PodIpRangeName string `json:"pod_ip_range_name"`
ServiceIpRangeName string `json:"service_ip_range_name"`
}

// Network is the object that contains all the information for BYOVPC
type Network struct {
AccountID string `json:"account_id"`
NetworkID string `json:"network_id,omitempty" tf:"computed"`
NetworkName string `json:"network_name"`
VPCID string `json:"vpc_id"`
SubnetIds []string `json:"subnet_ids" tf:"slice_set"`
VPCID string `json:"vpc_id,omitempty"`
SubnetIds []string `json:"subnet_ids,omitempty" tf:"slice_set"`
VPCEndpoints *NetworkVPCEndpoints `json:"vpc_endpoints,omitempty" tf:"computed,force_new"`
SecurityGroupIds []string `json:"security_group_ids" tf:"slice_set"`
SecurityGroupIds []string `json:"security_group_ids,omitempty" tf:"slice_set"`
VPCStatus string `json:"vpc_status,omitempty" tf:"computed"`
ErrorMessages []NetworkHealth `json:"error_messages,omitempty" tf:"computed"`
WorkspaceID int64 `json:"workspace_id,omitempty" tf:"computed"`
CreationTime int64 `json:"creation_time,omitempty" tf:"computed"`
GcpNetworkInfo *GcpNetworkInfo `json:"gcp_network_info,omitempty"`
}

// VPCEndpoint is the object that contains all the information for registering an VPC endpoint
Expand Down
7 changes: 7 additions & 0 deletions mws/resource_mws_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func ResourceMwsNetworks() *schema.Resource {
s["subnet_ids"].MinItems = 2
s["security_group_ids"].MinItems = 1
s["security_group_ids"].MaxItems = 5

s["vpc_id"].ExactlyOneOf = []string{"vpc_id", "gcp_network_info"}
s["subnet_ids"].ExactlyOneOf = []string{"subnet_ids", "gcp_network_info"}
s["security_group_ids"].ExactlyOneOf = []string{"security_group_ids", "gcp_network_info"}
s["vpc_endpoints"].ConflictsWith = []string{"gcp_network_info"}
s["gcp_network_info"].ConflictsWith = []string{"vpc_id", "subnet_ids", "security_group_ids", "vpc_endpoints"}

return s
})
p := common.NewPairSeparatedID("account_id", "network_id", "/")
Expand Down
86 changes: 86 additions & 0 deletions mws/resource_mws_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,92 @@ func TestResourceNetworkCreate(t *testing.T) {
assert.Equal(t, "abc/nid", d.Id())
}

func TestResourceNetworkCreate_GCP(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.0/accounts/abc/networks",
ExpectedRequest: Network{
AccountID: "abc",
NetworkName: "Open Workers",
GcpNetworkInfo: &GcpNetworkInfo{
NetworkProjectId: "project_a",
VpcId: "vpc_a",
SubnetId: "subnet_a",
SubnetRegion: "region_a",
PodIpRangeName: "pods",
ServiceIpRangeName: "svc",
},
},
Response: Network{
AccountID: "abc",
NetworkID: "nid",
},
},
{
Method: "GET",
Resource: "/api/2.0/accounts/abc/networks/nid",
Response: Network{
NetworkID: "nid",
SecurityGroupIds: []string{"one", "two"},
NetworkName: "Open Workers",
VPCID: "five",
SubnetIds: []string{"four", "three"},
},
},
},
Resource: ResourceMwsNetworks(),
HCL: `
account_id = "abc"
network_name = "Open Workers"
gcp_network_info {
network_project_id = "project_a"
vpc_id = "vpc_a"
subnet_id = "subnet_a"
subnet_region = "region_a"
pod_ip_range_name = "pods"
service_ip_range_name = "svc"
}
`,
Create: true,
}.Apply(t)
assert.NoError(t, err, err)
assert.Equal(t, "abc/nid", d.Id())
}

func TestResourceNetworkCreate_ConflictErrors(t *testing.T) {
_, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{},
Resource: ResourceMwsNetworks(),
HCL: `
account_id = "abc"
network_name = "Open Workers"
security_group_ids = ["one", "two"]
subnet_ids = ["three", "four"]
vpc_id = "five"
vpc_endpoints {
rest_api = ["a","b"]
dataplane_relay = ["b", "c"]
}
gcp_network_info {
network_project_id = "project_a"
vpc_id = "vpc_a"
subnet_id = "subnet_a"
subnet_region = "region_a"
pod_ip_range_name = "pods"
service_ip_range_name = "svc"
}
`,
Create: true,
}.Apply(t)
assert.ErrorContains(t, err, "[gcp_network_info] Conflicting configuration arguments")
assert.ErrorContains(t, err, "[security_group_ids] Invalid combination of arguments")
assert.ErrorContains(t, err, "[subnet_ids] Invalid combination of arguments")
assert.ErrorContains(t, err, "[vpc_endpoints] Conflicting configuration arguments")
assert.ErrorContains(t, err, "[vpc_id] Invalid combination of arguments")
}

func TestResourceNetworkCreate_Error(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down
16 changes: 8 additions & 8 deletions mws/resource_mws_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ type CloudResourceBucket struct {
}

type GCPManagedNetworkConfig struct {
SubnetCIDR string `json:"subnet_cidr"`
GKEClusterPodIPRange string `json:"gke_cluster_pod_ip_range"`
GKEClusterServiceIPRange string `json:"gke_cluster_service_ip_range"`
SubnetCIDR string `json:"subnet_cidr" tf:"force_new"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please do one space instead of two

GKEClusterPodIPRange string `json:"gke_cluster_pod_ip_range" tf:"force_new"`
GKEClusterServiceIPRange string `json:"gke_cluster_service_ip_range" tf:"force_new"`
}

type GCPCommonNetworkConfig struct {
GKEConnectivityType string `json:"gke_connectivity_type"`
GKEClusterMasterIPRange string `json:"gke_cluster_master_ip_range"`
GKEConnectivityType string `json:"gke_connectivity_type" tf:"force_new"`
GKEClusterMasterIPRange string `json:"gke_cluster_master_ip_range" tf:"force_new"`
}

type GCPNetwork struct {
NetworkID string `json:"network_id,omitempty"`
GCPManagedNetworkConfig *GCPManagedNetworkConfig `json:"gcp_managed_network_config,omitempty"`
GCPCommonNetworkConfig *GCPCommonNetworkConfig `json:"gcp_common_network_config"`
NetworkID string `json:"network_id,omitempty" tf:"force_new"`
GCPManagedNetworkConfig *GCPManagedNetworkConfig `json:"gcp_managed_network_config,omitempty" tf:"force_new"`
GCPCommonNetworkConfig *GCPCommonNetworkConfig `json:"gcp_common_network_config,omitempty" tf:"force_new"`
}

type externalCustomerInfo struct {
Expand Down