Skip to content

Commit

Permalink
feat: [CCM-11423] Support for import of AWS ALB and Azure AppGateway …
Browse files Browse the repository at this point in the history
…as AutoStopping Loadbalancer (#707)

* Introduced importing of Azure AppGateway for AutoStopping LB creation

* Support for import ALB as access point in AutoStopping

* Added support for specifying existing SSL certificate on importing Azure AppGateway

* Import Azure AppGateway for AutoStopping - tested version

* Added Azure app gateway import attributes to datasource

* Added example for import azure app gateway

* Support for creating Azure AppGateway as AutoStopping LB

* AutoStoppingRule - Made default LB delete option to be false by default for deleting cloud resources

* Resource file modifications for AutoStopping AWS ALB and Azure AppGateway

* Added example file for AutoStopping ALB import

* Docs for AutoStopping LBs

* Changelog

* Removed valid value set for optional attribute SKU size of Azure AppGateway in AutoStopping as the value is not mandatory
  • Loading branch information
shalinlk committed Oct 12, 2023
1 parent 29a4d0c commit d7a2631
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .changelog/707.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
- Support for import of ALB as AutoStopping Loadbalancer
- Support for import of AppGateway as AutoStopping Loadbalancer
```
1 change: 1 addition & 0 deletions docs/data-sources/autostopping_aws_alb.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data "harness_autostopping_aws_alb" "test" {

### Optional

- `alb_arn` (String) Arn of AWS ALB to be imported. Required only for importing existing ALB
- `certificate_id` (String)
- `route53_hosted_zone_id` (String) Route 53 hosted zone id
- `security_groups` (List of String) Security Group to define the security rules that determine the inbound and outbound traffic
Expand Down
9 changes: 7 additions & 2 deletions docs/data-sources/autostopping_azure_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ data "harness_autostopping_azure_gateway" "test" {

- `azure_func_region` (String) Region in which azure cloud function will be provisioned
- `cloud_connector_id` (String) Id of the cloud connector
- `frontend_ip` (String)
- `host_name` (String) Hostname for the proxy
- `name` (String) Name of the proxy
- `region` (String) Region in which cloud resources are hosted
- `resource_group` (String) Resource group in which cloud resources are hosted
- `vpc` (String) VPC in which cloud resources are hosted

### Optional

- `app_gateway_id` (String) ID of Azure AppGateway for importing
- `certificate_id` (String) ID of existing SSL certificate from AppGateway being imported. Required only for SSL based rules
- `frontend_ip` (String) ID of IP address to be used. Required only for creating new AppGateway. See https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-components#static-versus-dynamic-public-ip-address for more details
- `sku_size` (String) Size of machine used for the gateway
- `subnet_id` (String) Subnet in which cloud resources are hosted
- `vpc` (String) VPC in which cloud resources are hosted

### Read-Only

Expand Down
12 changes: 12 additions & 0 deletions docs/resources/autostopping_aws_alb.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ resource "harness_autostopping_aws_alb" "test" {
security_groups = ["sg1", "sg2"]
route53_hosted_zone_id = "/hostedzone/zone_id"
}
resource "harness_autostopping_aws_alb" "harness_alb" {
name = "harness_alb"
cloud_connector_id = "cloud_connector_id"
host_name = "host.name"
alb_arn = "arn:aws:elasticloadbalancing:region:aws_account_id:loadbalancer/app/harness_alb/id"
region = "region"
vpc = "vpc"
security_groups = ["sg-0"]
route53_hosted_zone_id = "/hostedzone/zone_id"
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -37,6 +48,7 @@ resource "harness_autostopping_aws_alb" "test" {

### Optional

- `alb_arn` (String) Arn of AWS ALB to be imported. Required only for importing existing ALB
- `certificate_id` (String)
- `route53_hosted_zone_id` (String) Route 53 hosted zone id
- `security_groups` (List of String) Security Group to define the security rules that determine the inbound and outbound traffic
Expand Down
25 changes: 21 additions & 4 deletions docs/resources/autostopping_azure_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ resource "harness_autostopping_azure_gateway" "test" {
frontend_ip = "/subscriptions/subscription_id/resourceGroups/resource_group/providers/Microsoft.Network/publicIPAddresses/publicip"
sku_size = "sku2"
}
resource "harness_autostopping_azure_gateway" "import_test" {
name = "import_test"
cloud_connector_id = "cloud_connector_id"
host_name = "host_name"
region = "westus2"
resource_group = "test_resource_group"
app_gateway_id = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/applicationGateways/TestAppGateway"
certificate_id = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/applicationGateways/TestAppGateway/sslCertificates/certificate_name"
azure_func_region = "westus2"
vpc = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/virtualNetworks/test_resource_group_vnet"
}
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -34,14 +46,19 @@ resource "harness_autostopping_azure_gateway" "test" {

- `azure_func_region` (String) Region in which azure cloud function will be provisioned
- `cloud_connector_id` (String) Id of the cloud connector
- `frontend_ip` (String)
- `host_name` (String) Hostname for the proxy
- `name` (String) Name of the proxy
- `region` (String) Region in which cloud resources are hosted
- `resource_group` (String) Resource group in which cloud resources are hosted
- `sku_size` (String) Size of machine used for the gateway
- `subnet_id` (String) Subnet in which cloud resources are hosted
- `vpc` (String) VPC in which cloud resources are hosted
- `vpc` (String) VNet in which cloud resources are hosted. Required only for creating new AppGateway

### Optional

- `app_gateway_id` (String) ID of Azure AppGateway for importing. Required only for importing exiging AppGateway
- `certificate_id` (String) ID of existing SSL certificate from AppGateway being imported. Required only for importing existing AppGateway. Required only for SSL based rules
- `frontend_ip` (String) ID of IP address to be used. Required only for creating new AppGateway. See https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-components#static-versus-dynamic-public-ip-address for more details
- `sku_size` (String) Size of machine used for the gateway. Required only for creating new AppGateway
- `subnet_id` (String) Subnet in which cloud resources are hosted. Required only for creating new AppGateway

### Read-Only

Expand Down
10 changes: 10 additions & 0 deletions examples/resources/harness_autostopping_aws_alb/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ resource "harness_autostopping_aws_alb" "test" {
route53_hosted_zone_id = "/hostedzone/zone_id"
}

resource "harness_autostopping_aws_alb" "harness_alb" {
name = "harness_alb"
cloud_connector_id = "cloud_connector_id"
host_name = "host.name"
alb_arn = "arn:aws:elasticloadbalancing:region:aws_account_id:loadbalancer/app/harness_alb/id"
region = "region"
vpc = "vpc"
security_groups = ["sg-0"]
route53_hosted_zone_id = "/hostedzone/zone_id"
}
12 changes: 12 additions & 0 deletions examples/resources/harness_autostopping_azure_gateway/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ resource "harness_autostopping_azure_gateway" "test" {
frontend_ip = "/subscriptions/subscription_id/resourceGroups/resource_group/providers/Microsoft.Network/publicIPAddresses/publicip"
sku_size = "sku2"
}

resource "harness_autostopping_azure_gateway" "import_test" {
name = "import_test"
cloud_connector_id = "cloud_connector_id"
host_name = "host_name"
region = "westus2"
resource_group = "test_resource_group"
app_gateway_id = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/applicationGateways/TestAppGateway"
certificate_id = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/applicationGateways/TestAppGateway/sslCertificates/certificate_name"
azure_func_region = "westus2"
vpc = "/subscriptions/subscription_id/resourceGroups/test_resource_group/providers/Microsoft.Network/virtualNetworks/test_resource_group_vnet"
}
10 changes: 9 additions & 1 deletion internal/service/platform/autostopping/load_balancer/aws_alb.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func ResourceAwsALB() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"alb_arn": {
Description: "Arn of AWS ALB to be imported. Required only for importing existing ALB",
Type: schema.TypeString,
Optional: true,
},
},
}

Expand All @@ -75,6 +80,9 @@ func ResourceAwsALB() *schema.Resource {

func resourceAwsALBCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb := buildLoadBalancer(d, c.AccountId, "aws", "")
lb, err := buildLoadBalancer(d, c.AccountId, "aws", "")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func DataSourceAwsALB() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"alb_arn": {
Description: "Arn of AWS ALB to be imported. Required only for importing existing ALB",
Type: schema.TypeString,
Optional: true,
},
},
}
return resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func ResourceAWSProxy() *schema.Resource {

func resourceAWSProxyCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb := buildLoadBalancer(d, c.AccountId, "aws", "autostopping_proxy")
lb, err := buildLoadBalancer(d, c.AccountId, "aws", "autostopping_proxy")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,39 @@ func ResourceAzureGateway() *schema.Resource {
Required: true,
},
"vpc": {
Description: "VPC in which cloud resources are hosted",
Description: "VNet in which cloud resources are hosted. Required only for creating new AppGateway",
Type: schema.TypeString,
Required: true,
},
"subnet_id": {
Description: "Subnet in which cloud resources are hosted",
Description: "Subnet in which cloud resources are hosted. Required only for creating new AppGateway",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"azure_func_region": {
Description: "Region in which azure cloud function will be provisioned",
Type: schema.TypeString,
Required: true,
},
"frontend_ip": {
Description: "",
Description: "ID of IP address to be used. Required only for creating new AppGateway. See https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-components#static-versus-dynamic-public-ip-address for more details",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"sku_size": {
Description: "Size of machine used for the gateway",
Description: "Size of machine used for the gateway. Required only for creating new AppGateway",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"app_gateway_id": {
Description: "ID of Azure AppGateway for importing. Required only for importing exiging AppGateway",
Type: schema.TypeString,
Optional: true,
},
"certificate_id": {
Description: "ID of existing SSL certificate from AppGateway being imported. Required only for importing existing AppGateway. Required only for SSL based rules",
Type: schema.TypeString,
Optional: true,
},
},
}
Expand All @@ -82,6 +92,9 @@ func ResourceAzureGateway() *schema.Resource {

func resourceAzureGatewayCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb := buildLoadBalancer(d, c.AccountId, "azure", "app_gateway")
lb, err := buildLoadBalancer(d, c.AccountId, "azure", "app_gateway")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,32 @@ func DataSourceAzureGateway() *schema.Resource {
"subnet_id": {
Description: "Subnet in which cloud resources are hosted",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"azure_func_region": {
Description: "Region in which azure cloud function will be provisioned",
Type: schema.TypeString,
Required: true,
},
"frontend_ip": {
Description: "",
Description: "ID of IP address to be used. Required only for creating new AppGateway. See https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-components#static-versus-dynamic-public-ip-address for more details",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"sku_size": {
Description: "Size of machine used for the gateway",
Type: schema.TypeString,
Required: true,
Optional: true,
},
"app_gateway_id": {
Description: "ID of Azure AppGateway for importing",
Type: schema.TypeString,
Optional: true,
},
"certificate_id": {
Description: "ID of existing SSL certificate from AppGateway being imported. Required only for SSL based rules",
Type: schema.TypeString,
Optional: true,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func ResourceAzureProxy() *schema.Resource {

func resourceAzureProxyCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb := buildLoadBalancer(d, c.AccountId, "azure", "autostopping_proxy")
lb, err := buildLoadBalancer(d, c.AccountId, "azure", "autostopping_proxy")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func ResourceGCPProxy() *schema.Resource {

func resourceGCPProxyCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
lb := buildLoadBalancer(d, c.AccountId, "gcp", "autostopping_proxy")
lb, err := buildLoadBalancer(d, c.AccountId, "gcp", "autostopping_proxy")
if err != nil {
return diag.FromErr(err)
}
return resourceLoadBalancerCreateOrUpdate(ctx, d, meta, lb)
}
Loading

0 comments on commit d7a2631

Please sign in to comment.