Skip to content

Commit

Permalink
ACME設定がnilで上書きされてしまう不具合修正
Browse files Browse the repository at this point in the history
  • Loading branch information
lvctr committed Oct 22, 2024
1 parent 3d8cf6a commit e9857ef
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sakuracloud/data_source_sakuracloud_proxylb.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,31 @@ func dataSourceSakuraCloudProxyLB() *schema.Resource {
},
},
},
"letsencrypt": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "The flag to accept the current Let's Encrypt terms of service(see: https://letsencrypt.org/repository/). This must be set `true` explicitly",
},
"common_name": {
Type: schema.TypeString,
Computed: true,
Description: "The common name of the certificate",
},
"subject_alt_names": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Computed: true,
Description: "The subject alternative names of the certificate",
},
},
},
},
"icon_id": schemaDataSourceIconID(resourceName),
"description": schemaDataSourceDescription(resourceName),
"tags": schemaDataSourceTags(resourceName),
Expand Down
31 changes: 31 additions & 0 deletions sakuracloud/resource_sakuracloud_proxylb.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,33 @@ func resourceSakuraCloudProxyLB() *schema.Resource {
},
},
},
"letsencrypt": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "The flag to accept the current Let's Encrypt terms of service(see: https://letsencrypt.org/repository/). This must be set `true` explicitly",
},
"common_name": {
Type: schema.TypeString,
Computed: true,
Description: "The common name of the certificate",
},
"subject_alt_names": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Computed: true,
Description: "The subject alternative names of the certificate",
},
},
},
},
"icon_id": schemaResourceIconID(resourceName),
"description": schemaResourceDescription(resourceName),
"tags": schemaResourceTags(resourceName),
Expand Down Expand Up @@ -603,6 +630,7 @@ func setProxyLBResourceData(ctx context.Context, d *schema.ResourceData, client
// even if certificate is deleted, it will not result in an error
return diag.FromErr(err)
}

health, err := proxyLBOp.HealthStatus(ctx, data.ID)
if err != nil {
return diag.FromErr(err)
Expand Down Expand Up @@ -642,6 +670,9 @@ func setProxyLBResourceData(ctx context.Context, d *schema.ResourceData, client
if err := d.Set("rule", flattenProxyLBRules(data)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("letsencrypt", flattenProxyLBACMESetting(data)); err != nil {
return diag.FromErr(err)
}
if err := d.Set("certificate", flattenProxyLBCerts(certs)); err != nil {
return diag.FromErr(err)
}
Expand Down
28 changes: 28 additions & 0 deletions sakuracloud/structure_proxylb.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func expandProxyLBCreateRequest(d *schema.ResourceData) *iaas.ProxyLBCreateReque
BindPorts: expandProxyLBBindPorts(d),
Servers: expandProxyLBServers(d),
Rules: expandProxyLBRules(d),
LetsEncrypt: expandProxyLBACMESetting(d),
StickySession: expandProxyLBStickySession(d),
Gzip: expandProxyLBGzip(d),
BackendHttpKeepAlive: expandProxyLBBackendHttpKeepAlive(d),
Expand All @@ -50,6 +51,7 @@ func expandProxyLBUpdateRequest(d *schema.ResourceData) *iaas.ProxyLBUpdateReque
BindPorts: expandProxyLBBindPorts(d),
Servers: expandProxyLBServers(d),
Rules: expandProxyLBRules(d),
LetsEncrypt: expandProxyLBACMESetting(d),
StickySession: expandProxyLBStickySession(d),
Gzip: expandProxyLBGzip(d),
BackendHttpKeepAlive: expandProxyLBBackendHttpKeepAlive(d),
Expand Down Expand Up @@ -415,3 +417,29 @@ func expandProxyLBCerts(d resourceValueGettable) *iaas.ProxyLBCertificates {
}
return nil
}

func flattenProxyLBACMESetting(proxyLB *iaas.ProxyLB) []interface{} {
var results []interface{}
if proxyLB.LetsEncrypt != nil {
results = []interface{}{
map[string]interface{}{
"enabled": proxyLB.LetsEncrypt.Enabled,
"common_name": proxyLB.LetsEncrypt.CommonName,
"subject_alt_names": proxyLB.LetsEncrypt.SubjectAltNames,
},
}
}
return results
}

func expandProxyLBACMESetting(d resourceValueGettable) *iaas.ProxyLBACMESetting {
if acmeSettings, ok := getListFromResource(d, "letsencrypt"); ok && len(acmeSettings) > 0 {
values := mapToResourceData(acmeSettings[0].(map[string]interface{}))
return &iaas.ProxyLBACMESetting{
CommonName: values.Get("common_name").(string),
Enabled: values.Get("enabled").(bool),
SubjectAltNames: expandSubjectAltNames(values),
}
}
return nil
}

0 comments on commit e9857ef

Please sign in to comment.