Skip to content

Commit

Permalink
fix custom cert alias and update docs (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgalkin authored Oct 10, 2024
1 parent ab56585 commit 536210b
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tags
env.sh
tags.lock
tags.temp
.todo
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.4.1

BUGFIXES:

- fix custom certificate for aliases
- added descriptions for docs

## 0.4.0

FEATURES:
Expand Down
4 changes: 2 additions & 2 deletions _scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ chmod 0755 $dst
ls -lah $dst

if [[ $* == *--apply* ]]; then
terraform_cmd=apply
terraform_cmd="apply --auto-approve"
fi

if [[ $* == *--debug* ]]; then
cd $git_root/examples/provider
rm -f .terraform.lock.hcl
terraform init -upgrade
TF_LOG=WARN terraform $terraform_cmd --auto-approve
TF_LOG=WARN terraform $terraform_cmd
fi
12 changes: 6 additions & 6 deletions docs/resources/l7alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ description: |-

### Required

- `domain` (String)
- `l7_resource_id` (Number)
- `domain` (String) Domain name of the alias. For example, example.ru
- `l7_resource_id` (Number) Resource ID to which the alias refers

### Optional

- `custom_ssl_crt` (String)
- `custom_ssl_key` (String)
- `use_custom_ssl` (Number)
- `use_letsencrypt_ssl` (Number)
- `custom_ssl_crt` (String) SSL certificate chain in base64
- `custom_ssl_key` (String) Certificate key in base64 format
- `use_custom_ssl` (Number) Use of custom certificate
- `use_letsencrypt_ssl` (Number) Use of SSL certificate from Let's Encrypt. In this case, the certificate will be updated automatically.

### Read-Only

Expand Down
58 changes: 29 additions & 29 deletions docs/resources/l7resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,47 @@ description: |-

### Required

- `l7_resource_name` (String)
- `origins` (Attributes List) (see [below for nested schema](#nestedatt--origins))
- `l7_resource_name` (String) The name of the L7 resource.
- `origins` (Attributes List) A list of origin servers. (see [below for nested schema](#nestedatt--origins))

### Optional

- `cdn` (Number)
- `cdn_host` (String)
- `cdn_proxy_host` (String)
- `custom_ssl_crt` (String)
- `custom_ssl_key` (String)
- `force_ssl` (Number)
- `geoip_list` (String)
- `geoip_mode` (Number)
- `global_whitelist_active` (Number)
- `http_2_https` (Number)
- `https_2_http` (Number)
- `l7_protection_disable` (Number)
- `l7_resource_is_active` (Number)
- `service_http2` (Number)
- `use_custom_ssl` (Number)
- `use_letsencrypt_ssl` (Number)
- `www_redir` (Number)
- `cdn` (Number) Enables (1) or disables (0) CDN usage.
- `cdn_host` (String) The CDN host address.
- `cdn_proxy_host` (String) The CDN proxy host address.
- `custom_ssl_crt` (String) The custom SSL certificate chain in base64 format.
- `custom_ssl_key` (String) The private key of the custom SSL certificate in base64 format.
- `force_ssl` (Number) Forces SSL usage when set to 1.
- `geoip_list` (String) List of GeoIP locations.
- `geoip_mode` (Number) Specifies the GeoIP mode setting.
- `global_whitelist_active` (Number) Enables (1) or disables (0) the global whitelist.
- `http_2_https` (Number) Redirects HTTP to HTTPS when set to 1.
- `https_2_http` (Number) Redirects HTTPS to HTTP when set to 1.
- `l7_protection_disable` (Number) Disables L7 protection when set to 1.
- `l7_resource_is_active` (Number) Indicates whether the L7 resource is active (1) or inactive (0).
- `service_http2` (Number) Enables (1) or disables (0) HTTP/2 support.
- `use_custom_ssl` (Number) Enables (1) or disables (0) the use of a custom SSL certificate.
- `use_letsencrypt_ssl` (Number) Enables (1) or disables (0) the use of a Let's Encrypt SSL certificate.
- `www_redir` (Number) Enables (1) or disables (0) redirection to the 'www' subdomain.

### Read-Only

- `l7_resource_id` (Number)
- `last_updated` (String)
- `protected_ip` (String)
- `l7_resource_id` (Number) The ID of the L7 resource.
- `last_updated` (String) Timestamp of the last update.
- `protected_ip` (String) The protected IP address.

<a id="nestedatt--origins"></a>
### Nested Schema for `origins`

Optional:

- `ip` (String)
- `mode` (String)
- `weight` (Number)
- `ip` (String) The IP address of the origin server.
- `mode` (String) The mode of the origin server (e.g., 'active', 'backup').
- `weight` (Number) The weight assigned to the origin server for load balancing.

Read-Only:

- `created_at` (Number)
- `id` (Number)
- `l7_resource_id` (Number)
- `modified_at` (Number)
- `created_at` (Number) Timestamp when the origin was created.
- `id` (Number) The ID of the origin server.
- `l7_resource_id` (Number) The ID of the L7 resource associated with the origin.
- `modified_at` (Number) Timestamp when the origin was last modified.
18 changes: 11 additions & 7 deletions examples/provider/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ provider "servicepipe" {
}

resource "servicepipe_l7resource" "test" {
l7_resource_name = "galkin-vktest-nlb-sp.runit.cc"
l7_resource_name = "examples-tfprovider-sp.runit.cc"
www_redir = 1
http_2_https = 1
force_ssl = 0

use_custom_ssl = 1
custom_ssl_key = base64encode(var.test_example_com_key)
custom_ssl_crt = base64encode(var.test_example_com_crt)
force_ssl = 1

origins = [
{
Expand All @@ -31,7 +27,15 @@ resource "servicepipe_l7resource" "test" {
}

resource "servicepipe_l7alias" "test-alias" {
domain = "test-app3-vktest.runit.cc"
domain = "route-test98.runit.cc"
l7_resource_id = servicepipe_l7resource.test.l7_resource_id
custom_ssl_key = base64encode(var.test_example_com_key)
custom_ssl_crt = base64encode(var.test_example_com_crt)
use_custom_ssl = 1
}

resource "servicepipe_l7alias" "test-alias2" {
domain = "route-test99.runit.cc"
l7_resource_id = servicepipe_l7resource.test.l7_resource_id
use_letsencrypt_ssl = 1
}
2 changes: 1 addition & 1 deletion internal/pkg/sdkv1/l7alias/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (opts *Alias) Delete(ctx context.Context, client *v1.Client) (*DataDelete,
return result, responseResult, nil
}

// Update deletes a single domain by its id.
// Update updates a single domain by its id.
func (opts *Alias) Update(ctx context.Context, client *v1.Client) (*Data, *v1.ResponseResult, error) {
url := strings.Join([]string{client.Endpoint, l7RAliasPath}, "/")
requestBody, err := json.Marshal(opts)
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/sdkv1/l7alias/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package l7alias

// Alias represents an unmarshalled domain body from API response.
type Alias struct {
// PartnerClientAccountID is the identifier of partner client.
PartnerClientAccountID int64 `json:"partnerClientAccountId,omitempty"`
// ID ресурса, к которому относится алиас
L7ResourceID int64 `json:"l7ResourceId,omitempty"`
// ID аласа
Expand Down
54 changes: 25 additions & 29 deletions internal/provider/l7alias_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,36 @@ func (r *l7resourceAlias) Schema(_ context.Context, _ resource.SchemaRequest, re
Computed: true,
},
"l7_resource_id": schema.Int64Attribute{
Required: true,
Required: true,
Description: "Resource ID to which the alias refers",
},
"domain": schema.StringAttribute{
Required: true,
Required: true,
Description: "Domain name of the alias. For example, example.ru",
},
"use_custom_ssl": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
Description: "Use of custom certificate",
},
"use_letsencrypt_ssl": schema.Int64Attribute{
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
Description: "Use of SSL certificate from Let's Encrypt. In this case, the certificate will be updated automatically.",
},
"custom_ssl_key": schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Description: "Certificate key in base64 format",
},
"custom_ssl_crt": schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Optional: true,
Computed: true,
Default: stringdefault.StaticString(""),
Description: "SSL certificate chain in base64",
},
"last_updated": schema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -328,38 +334,28 @@ func (plan *l7AliasTfModel) CheckPlanVsState(state *l7AliasTfModel, item *l7alia
func (plan *l7AliasTfModel) CheckingPlanAttrIsNull(item l7alias.Alias) (l7alias.Alias, bool) {
update := false

if !plan.L7ResourceID.IsNull() || !plan.L7ResourceID.IsUnknown() {
plan.L7ResourceID = types.Int64Value(item.L7ResourceID)
update = true
}

if !plan.L7AliasID.IsNull() || !plan.L7AliasID.IsUnknown() {
plan.L7AliasID = types.Int64Value(item.L7AliasID)
update = true
}

if !plan.Domain.IsNull() || !plan.Domain.IsUnknown() {
plan.Domain = types.StringValue(item.Domain)
item.Domain = plan.Domain.ValueString()
update = true
}

if !plan.UseCustomSsl.IsNull() || !plan.UseCustomSsl.IsUnknown() {
plan.UseCustomSsl = types.Int64Value(item.UseCustomSsl)
item.UseCustomSsl = plan.UseCustomSsl.ValueInt64()
update = true
}

if !plan.UseLetsencryptSsl.IsNull() || !plan.UseLetsencryptSsl.IsUnknown() {
plan.UseLetsencryptSsl = types.Int64Value(item.UseLetsencryptSsl)
item.UseLetsencryptSsl = plan.UseLetsencryptSsl.ValueInt64()
update = true
}

if !plan.CustomSslKey.IsNull() || !plan.CustomSslKey.IsUnknown() {
plan.CustomSslKey = types.StringValue(item.CustomSslKey)
item.CustomSslKey = plan.CustomSslKey.ValueString()
update = true
}

if !plan.CustomSslCrt.IsNull() || !plan.CustomSslCrt.IsUnknown() {
plan.CustomSslCrt = types.StringValue(item.CustomSslCrt)
item.CustomSslCrt = plan.CustomSslCrt.ValueString()
update = true
}

Expand Down
Loading

0 comments on commit 536210b

Please sign in to comment.