|
| 1 | +package incapsula |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 5 | +) |
| 6 | + |
| 7 | +func resourceCertificateSigningRequest() *schema.Resource { |
| 8 | + return &schema.Resource{ |
| 9 | + Create: resourceCertificateSigningRequestCreate, |
| 10 | + Read: resourceCertificateSigningRequestRead, |
| 11 | + Update: resourceCertificateSigningRequestUpdate, |
| 12 | + Delete: resourceCertificateSigningRequestDelete, |
| 13 | + |
| 14 | + Schema: map[string]*schema.Schema{ |
| 15 | + // Required Arguments |
| 16 | + "site_id": { |
| 17 | + Description: "Numeric identifier of the site to operate on.", |
| 18 | + Type: schema.TypeString, |
| 19 | + Required: true, |
| 20 | + ForceNew: true, |
| 21 | + }, |
| 22 | + // Optional Arguments |
| 23 | + "domain": { |
| 24 | + Description: "common name. For example: example.com.", |
| 25 | + Type: schema.TypeString, |
| 26 | + Optional: true, |
| 27 | + }, |
| 28 | + "email": { |
| 29 | + Description: "Email address. For example: joe@example.com.", |
| 30 | + Type: schema.TypeString, |
| 31 | + Optional: true, |
| 32 | + }, |
| 33 | + "country": { |
| 34 | + Description: "The two-letter ISO code for the country where your organization is located.", |
| 35 | + Type: schema.TypeString, |
| 36 | + Optional: true, |
| 37 | + }, |
| 38 | + "state": { |
| 39 | + Description: "The state/region where your organization is located. This should not be abbreviated.", |
| 40 | + Type: schema.TypeString, |
| 41 | + Optional: true, |
| 42 | + }, |
| 43 | + "city": { |
| 44 | + Description: "The city where your organization is located.", |
| 45 | + Type: schema.TypeString, |
| 46 | + Optional: true, |
| 47 | + }, |
| 48 | + "organization": { |
| 49 | + Description: "The legal name of your organization. This should not be abbreviated or include suffixes such as Inc., Corp., or LLC.", |
| 50 | + Type: schema.TypeString, |
| 51 | + Optional: true, |
| 52 | + }, |
| 53 | + "organization_unit": { |
| 54 | + Description: "The division of your organization handling the certificate. For example, IT Department.", |
| 55 | + Type: schema.TypeString, |
| 56 | + Optional: true, |
| 57 | + }, |
| 58 | + // Computed Arguments |
| 59 | + "csr_content": { |
| 60 | + Description: "The certificate request data.", |
| 61 | + Type: schema.TypeString, |
| 62 | + Computed: true, |
| 63 | + }, |
| 64 | + }, |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +func resourceCertificateSigningRequestCreate(d *schema.ResourceData, m interface{}) error { |
| 69 | + client := m.(*Client) |
| 70 | + certificateSigningRequestResponse, err := client.CreateCertificateSigningRequest( |
| 71 | + d.Get("site_id").(string), |
| 72 | + d.Get("domain").(string), |
| 73 | + d.Get("email").(string), |
| 74 | + d.Get("country").(string), |
| 75 | + d.Get("state").(string), |
| 76 | + d.Get("city").(string), |
| 77 | + d.Get("organization").(string), |
| 78 | + d.Get("organization_unit").(string), |
| 79 | + ) |
| 80 | + |
| 81 | + if err != nil { |
| 82 | + return err |
| 83 | + } |
| 84 | + |
| 85 | + d.Set("csr_content", certificateSigningRequestResponse.CsrContent) |
| 86 | + |
| 87 | + d.SetId(d.Get("site_id").(string)) |
| 88 | + |
| 89 | + return nil |
| 90 | +} |
| 91 | + |
| 92 | +func resourceCertificateSigningRequestRead(d *schema.ResourceData, m interface{}) error { |
| 93 | + return nil |
| 94 | +} |
| 95 | + |
| 96 | +func resourceCertificateSigningRequestUpdate(d *schema.ResourceData, m interface{}) error { |
| 97 | + if d.HasChange("domain") || |
| 98 | + d.HasChange("email") || |
| 99 | + d.HasChange("country") || |
| 100 | + d.HasChange("state") || |
| 101 | + d.HasChange("city") || |
| 102 | + d.HasChange("organization") || |
| 103 | + d.HasChange("organization_unit") { |
| 104 | + return resourceCertificateSigningRequestCreate(d, m) |
| 105 | + } |
| 106 | + return nil |
| 107 | +} |
| 108 | + |
| 109 | +func resourceCertificateSigningRequestDelete(d *schema.ResourceData, m interface{}) error { |
| 110 | + return nil |
| 111 | +} |
0 commit comments