Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions data/data/alibabacloud/bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ locals {
},
var.ali_extra_tags,
)
is_external = var.ali_publish_strategy == "External" ? true : false
}

provider "alicloud" {
Expand Down Expand Up @@ -137,7 +138,7 @@ resource "alicloud_instance" "bootstrap" {
image_id = var.ali_image_id
vswitch_id = var.vswitch_ids[0]
security_groups = [alicloud_security_group.sg_bootstrap.id, var.sg_master_id]
internet_max_bandwidth_out = 5
internet_max_bandwidth_out = local.is_external ? 5 : 0
role_name = alicloud_ram_role.role.name

system_disk_name = "${local.prefix}_sys_disk-bootstrap"
Expand All @@ -162,4 +163,4 @@ resource "alicloud_slb_backend_server" "slb_attachment_bootstraps" {
server_id = alicloud_instance.bootstrap.id
weight = 90
}
}
}
2 changes: 1 addition & 1 deletion data/data/alibabacloud/bootstrap/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output "bootstrap_ip" {
value = data.alicloud_instances.bootstrap_data.instances.0.public_ip
value = local.is_external ? data.alicloud_instances.bootstrap_data.instances.0.public_ip : data.alicloud_instances.bootstrap_data.instances.0.private_ip
}
1 change: 1 addition & 0 deletions data/data/alibabacloud/cluster/dns/privatezone.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ locals {
prefix = var.cluster_id
cluster_name = split(".", var.cluster_domain)[0]
private_zone_id = var.private_zone_id == "" ? alicloud_pvtz_zone.pvtz.0.id : var.private_zone_id
is_external = var.publish_strategy == "External" ? true : false
}

// Using this data source can open Private Zone service automatically.
Expand Down
5 changes: 5 additions & 0 deletions data/data/alibabacloud/cluster/dns/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ variable "tags" {
type = map(string)
description = "Tags to be applied to created resources."
}

variable "publish_strategy" {
type = string
description = "The publishing strategy for endpoints like load balancers"
}
5 changes: 5 additions & 0 deletions data/data/alibabacloud/cluster/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
description = "Created By OpenShift Installer"
is_external = var.ali_publish_strategy == "External" ? true : false
tags = merge(
{
"GISV" = "ocp",
Expand Down Expand Up @@ -38,6 +39,7 @@ module "vpc" {
resource_group_id = module.resource_group.resource_group_id
vpc_cidr_block = var.machine_v4_cidrs[0]
tags = local.tags
publish_strategy = var.ali_publish_strategy
}

module "dns" {
Expand All @@ -51,6 +53,7 @@ module "dns" {
slb_external_ip = module.vpc.slb_external_ip
slb_internal_ip = module.vpc.slb_internal_ip
tags = local.tags
publish_strategy = var.ali_publish_strategy
}

module "ram" {
Expand All @@ -68,6 +71,7 @@ module "master" {
az_to_vswitch_id = module.vpc.az_to_vswitch_id
sg_id = module.vpc.sg_master_id
slb_ids = module.vpc.slb_ids
slb_group_length = module.vpc.slb_group_length
instance_type = var.ali_master_instance_type
instance_count = var.master_count
image_id = var.ali_image_id
Expand All @@ -76,4 +80,5 @@ module "master" {
user_data_ign = var.ignition_master
role_name = module.ram.role_master_name
tags = local.tags
publish_strategy = var.ali_publish_strategy
}
2 changes: 1 addition & 1 deletion data/data/alibabacloud/cluster/master/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "alicloud_instance" "master" {
}

resource "alicloud_slb_backend_server" "slb_attachment_masters" {
count = "${length(var.slb_ids) * length(alicloud_instance.master.*.id)}"
count = "${var.slb_group_length * length(alicloud_instance.master.*.id)}"
load_balancer_id = "${element(var.slb_ids, ceil(count.index / length(alicloud_instance.master.*.id)))}"
backend_servers {
server_id = "${element(alicloud_instance.master.*.id, count.index)}"
Expand Down
9 changes: 9 additions & 0 deletions data/data/alibabacloud/cluster/master/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ variable "slb_ids" {
type = list(string)
}

variable "slb_group_length" {
description = "The length of the 'slb_ids' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
}

variable "instance_count" {
type = string
}
Expand Down Expand Up @@ -67,3 +71,8 @@ variable "tags" {
type = map(string)
description = "Tags to be applied to created resources."
}

variable "publish_strategy" {
type = string
description = "The cluster publishing strategy, either Internal or External"
}
8 changes: 6 additions & 2 deletions data/data/alibabacloud/cluster/vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ output "eip_ip" {
}

output "slb_ids" {
value = [alicloud_slb_load_balancer.slb_external.id, alicloud_slb_load_balancer.slb_internal.id]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can keep the same slb_ids output.

output "slb_ids" {
  value = concat(alicloud_slb_load_balancer.slb_external[*].id, [alicloud_slb_load_balancer.slb_internal.id])
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jianli-wei Maybe need your help to test the updated code

value = concat(alicloud_slb_load_balancer.slb_external[*].id, [alicloud_slb_load_balancer.slb_internal.id])
}

output "slb_group_length" {
value = length(concat(alicloud_slb_load_balancer.slb_external[*].id, [alicloud_slb_load_balancer.slb_internal.id]))
}

output "slb_external_ip" {
value = alicloud_slb_load_balancer.slb_external.address
value = local.is_external ? alicloud_slb_load_balancer.slb_external[0].address : null
}

output "slb_internal_ip" {
Expand Down
6 changes: 5 additions & 1 deletion data/data/alibabacloud/cluster/vpc/slb.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

resource "alicloud_slb_load_balancer" "slb_external" {
count = local.is_external ? 1 : 0

resource_group_id = var.resource_group_id
load_balancer_name = "${local.prefix}-slb-external"
address_type = "internet"
Expand All @@ -14,7 +16,9 @@ resource "alicloud_slb_load_balancer" "slb_external" {
}

resource "alicloud_slb_listener" "listener_external_6443" {
load_balancer_id = alicloud_slb_load_balancer.slb_external.id
count = local.is_external ? 1 : 0

load_balancer_id = alicloud_slb_load_balancer.slb_external[0].id
backend_port = 6443
frontend_port = 6443
protocol = "tcp"
Expand Down
5 changes: 5 additions & 0 deletions data/data/alibabacloud/cluster/vpc/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ variable "tags" {
type = map(string)
description = "Tags to be applied to created resources."
}

variable "publish_strategy" {
type = string
description = "The publishing strategy for endpoints like load balancers"
}
1 change: 1 addition & 0 deletions data/data/alibabacloud/cluster/vpc/vpc.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ locals {
prefix = var.cluster_id
vpc_id = var.vpc_id == "" ? alicloud_vpc.vpc.0.id : var.vpc_id
vswitch_ids = length(var.vswitch_ids) == 0 ? alicloud_vswitch.vswitches.*.id : var.vswitch_ids
is_external = var.publish_strategy == "External" ? true : false
}

data "alicloud_vswitches" "vswitches" {
Expand Down
5 changes: 5 additions & 0 deletions data/data/alibabacloud/variables-alibabacloud.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ variable "ali_vswitch_ids" {
type = list(string)
}

variable "ali_publish_strategy" {
type = string
description = "The cluster publishing strategy, either Internal or External"
}

variable "ali_private_zone_id" {
type = string
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/tfvars/alibabacloud/alibabacloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type config struct {
ExtraTags map[string]string `json:"ali_extra_tags"`
IgnitionBucket string `json:"ali_ignition_bucket"`
BootstrapIgnitionStub string `json:"ali_bootstrap_stub_ignition"`
PublishStrategy string `json:"ali_publish_strategy"`
}

// TFVarsSources contains the parameters to be converted into Terraform variables
Expand Down Expand Up @@ -96,6 +97,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
SystemDiskCategory: masterConfig.SystemDisk.Category,
ExtraTags: tags,
IgnitionBucket: sources.IgnitionBucket,
PublishStrategy: string(sources.Publish),
}

stubIgn, err := bootstrap.GenerateIgnitionShimWithCertBundle(sources.IgnitionPresignedURL, sources.AdditionalTrustBundle)
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/validation/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func ValidateInstallConfig(c *types.InstallConfig) field.ErrorList {

if c.Publish == types.InternalPublishingStrategy {
switch platformName := c.Platform.Name(); platformName {
case aws.Name, azure.Name, gcp.Name:
case aws.Name, azure.Name, gcp.Name, alibabacloud.Name:
default:
allErrs = append(allErrs, field.Invalid(field.NewPath("publish"), c.Publish, fmt.Sprintf("Internal publish strategy is not supported on %q platform", platformName)))
}
Expand Down