-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from grokify/add/CloudWAFCertificate
add Cloud WAF Certificate support
- Loading branch information
Showing
9 changed files
with
523 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
### Example Usage | ||
|
||
```hcl-terraform | ||
resource "sigsci_corp_cloudwaf_certificate" "test_corp_cloudwaf_certificate" { | ||
name = "Test Cloud WAF Certificate" | ||
certificate_body = <<CERT | ||
-----BEGIN CERTIFICATE----- | ||
[encoded certificate] | ||
-----END CERTIFICATE----- | ||
CERT | ||
certificate_chain = <<CHAIN | ||
-----BEGIN CERTIFICATE----- | ||
[encoded certificate chain] | ||
-----END CERTIFICATE----- | ||
CHAIN | ||
private_key = <<PRIVATEKEY | ||
-----BEGIN PRIVATE KEY----- | ||
[encoded privatekey]] | ||
----END PRIVATE KEY----- | ||
PRIVATEKEY | ||
} | ||
``` | ||
|
||
### Argument Reference | ||
- `name` - (Required) Friendly name to identify a CloudWAF certificate. | ||
- `certificate_body` - (Required) Body of the certificate in PEM format. | ||
- `certificate_chain` - (Optional) Certificate chain in PEM format. | ||
- `private_key` - (Required) Private key of the certificate in PEM format - must be unencrypted. | ||
|
||
### Attributes Reference | ||
In addition to all arguments, the following fields are also available | ||
- `id` - CloudWAF certificate unique identifier. | ||
- `common_name` - Common name of the uploaded certificate. | ||
- `expires_at` - TimeStamp for when certificate expires in RFC3339 date time format. | ||
- `fingerprint` - SHA1 fingerprint of the certififcate. | ||
- `status` - Current status of the certificate - could be one of "unknown", "active", "pendingverification", "expired", "error". | ||
- `subject_alternative_names` - Subject alternative names from the uploaded certificate. | ||
|
||
### Import | ||
You can import corp lists with the generic site import formula | ||
|
||
Example: | ||
```shell script | ||
$ terraform import sigsci_corp_cloudwaf_certificate.test id | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package provider | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/signalsciences/go-sigsci" | ||
) | ||
|
||
func resourceCorpCloudWAFCertificate() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceCorpCloudWAFCertificateCreate, | ||
Read: resourceCorpCloudWAFCertificateRead, | ||
Update: resourceCorpCloudWAFCertificateUpdate, | ||
Delete: resourceCorpCloudWAFCertificateDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "Friendly name to identify a CloudWAF certificate", | ||
Required: true, | ||
}, | ||
"certificate_body": { | ||
Type: schema.TypeString, | ||
Description: "Body of the certificate in PEM format", | ||
Required: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: suppressEquivalentTrimSpaceDiffs, | ||
}, | ||
"certificate_chain": { | ||
Type: schema.TypeString, | ||
Description: "Certificate chain in PEM format", | ||
Optional: true, | ||
DiffSuppressFunc: suppressEquivalentTrimSpaceDiffs, | ||
}, | ||
"private_key": { | ||
Type: schema.TypeString, | ||
Description: "Private key of the certificate in PEM format - must be unencrypted", | ||
Required: true, | ||
ForceNew: true, | ||
Sensitive: true, | ||
}, | ||
"common_name": { | ||
Type: schema.TypeString, | ||
Description: "Common name of the uploaded certificate", | ||
Computed: true, | ||
}, | ||
"expires_at": { | ||
Type: schema.TypeString, | ||
Description: "TimeStamp for when certificate expires in RFC3339 date time format", | ||
Computed: true, | ||
}, | ||
"fingerprint": { | ||
Type: schema.TypeString, | ||
Description: "SHA1 fingerprint of the certififcate", | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Description: `Current status of the certificate - could be one of "unknown", "active", "pendingverification", "expired", "error"`, | ||
Computed: true, | ||
}, | ||
"subject_alternative_names": { | ||
Type: schema.TypeSet, | ||
Description: "Subject alternative names from the uploaded certificate", | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceCorpCloudWAFCertificateCreate(d *schema.ResourceData, m interface{}) error { | ||
pm := m.(providerMetadata) | ||
sc := pm.Client | ||
|
||
resp, err := sc.UploadCloudWAFCertificate(pm.Corp, sigsci.UploadCloudWAFCertificateBody{ | ||
CloudWAFCertificateBase: sigsci.CloudWAFCertificateBase{ | ||
Name: d.Get("name").(string), | ||
CertificateBody: strings.TrimSpace(d.Get("certificate_body").(string)), | ||
CertificateChain: strings.TrimSpace(d.Get("certificate_chain").(string)), | ||
}, | ||
PrivateKey: strings.TrimSpace(d.Get("private_key").(string)), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(resp.ID) | ||
|
||
return resourceCorpCloudWAFCertificateRead(d, m) | ||
} | ||
|
||
func resourceCorpCloudWAFCertificateRead(d *schema.ResourceData, m interface{}) error { | ||
pm := m.(providerMetadata) | ||
sc := pm.Client | ||
|
||
cwaf, err := sc.GetCloudWAFCertificate(pm.Corp, d.Id()) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.SetId(d.Id()) | ||
err = d.Set("name", cwaf.Name) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("certificate_body", strings.TrimSpace(cwaf.CertificateBody)) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("certificate_chain", strings.TrimSpace(cwaf.CertificateChain)) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("common_name", cwaf.CommonName) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("expires_at", cwaf.ExpiresAt) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("fingerprint", cwaf.Fingerprint) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("status", cwaf.Status) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("subject_alternative_names", flattenStringArray(cwaf.SubjectAlternativeNames)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceCorpCloudWAFCertificateUpdate(d *schema.ResourceData, m interface{}) error { | ||
pm := m.(providerMetadata) | ||
sc := pm.Client | ||
|
||
_, err := sc.UpdateCloudWAFCertificate(pm.Corp, d.Id(), sigsci.UpdateCloudWAFCertificateBody{ | ||
Name: d.Get("name").(string), | ||
}) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return resourceCorpCloudWAFCertificateRead(d, m) | ||
} | ||
|
||
func resourceCorpCloudWAFCertificateDelete(d *schema.ResourceData, m interface{}) error { | ||
pm := m.(providerMetadata) | ||
sc := pm.Client | ||
|
||
err := sc.DeleteCloudWAFCertificate(pm.Corp, d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
d.SetId("") | ||
return nil | ||
} |
Oops, something went wrong.