-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Add support for AWS IoT #6961
Closed
Closed
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
4ddaaf7
Fix deps conflict
jhedev 6921142
Add basic support for AWS IoT things
jhedev 94616fd
Add schemas for the remaining IoT resources
jhedev b7e0608
Get principals support working
jhedev d49b60b
Implement IoT certificate functionality
jhedev 9bcc40e
Implement IoT policy functionality
jhedev e6ace1e
Make IoT policy implementation compile
jhedev fbab587
Add some implementation for IoT policy attachment
jhedev 29bb099
Correct schema description of IoT topic rule
jhedev 5320b3b
Add tests for AWS IoT thing
jhedev 30bd454
Do not store pem of cert
jhedev 5aec619
Force recreation of cert if CSR has changed
jhedev 2315b7d
Fixes for IoT certificate
jhedev b468cc7
Add sql version to schema of IoT topic rule
jhedev 178e233
Add tests for aws iot certificate
jhedev 902637a
More tests for aws iot thing
jhedev 4286d08
Add aws iot policy test
jhedev 1ffa2c4
Some fixes for iot policy attachment
jhedev c785050
Implement functionality for IoT topic rule
jhedev b6cd40b
Add IoT topic rule tests
jhedev 8bb3a78
Start documenting AWS IoT resources
jhedev 10932d5
Add some new TODOs
jhedev cfcd9c6
Get basic policy attachment test working
jhedev 6d56073
Add csr.pem
jhedev 53ef1c2
Get update of attached principals for IoT thing working
jhedev 08450f4
Fix csr.pem path
jhedev ecdbef5
Add ARN as computed attribute to IoT thing
jhedev 68c82df
Document attributes of IoT policies
jhedev d56f682
Correct returns
jhedev 44a2462
Fix compilation
jhedev 38c9238
Implement update function
jhedev c39b418
Fix merge
jhedev 5386afe
Remove godeps directory
jhedev 7c0e43d
Some improvements for IoT topic rule
jhedev 828e41b
vendor: Add AWS IoT dependency
jhedev 1515e9b
Update documentation for topic rule
jhedev 50a1ea9
Use AWS SDK 1.4.2
01e3d0e
Can't cast *schema.Set to []string
01e549c
Fix path to csr.pem in IoT thing test
85df881
AWS does not want spaces in attribute
0e44158
Check all errors
jhedev f117dd6
Update interface of resource_aws_iot_policy_attachment
jhedev 6ba2968
Update documentation to mirror new interface of aws_iot_policy_attach…
jhedev 9033080
bring IoT dependency up to v1.5.13
c9ce4f0
Minor corrections for the iot certificate resource
jhedev 591dc27
Minor corrections for the iot policy resource
jhedev ccb178a
Always force new if there is change to a policy attachment
jhedev a4bc7c2
Minor changes to the read funtion of the iot thing resource
jhedev 10f9ac9
Minor fix
jhedev 3e45a2c
Fix principal and policy order in IoT policy attachment
jhedev 0aab8e3
Fix dynamodb implementation
jhedev 370027f
Update AWS IoT dep
jhedev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,146 @@ | ||
package aws | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iot" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsIotCertificate() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsIotCertificateCreate, | ||
Read: resourceAwsIotCertificateRead, | ||
Update: resourceAwsIotCertificateUpdate, | ||
Delete: resourceAwsIotCertificateDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"csr": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"active": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Required: true, | ||
}, | ||
"arn": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsIotCertificateCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).iotconn | ||
|
||
log.Printf("[DEBUG] Creating certificate from csr") | ||
out, err := conn.CreateCertificateFromCsr(&iot.CreateCertificateFromCsrInput{ | ||
CertificateSigningRequest: aws.String(d.Get("csr").(string)), | ||
SetAsActive: aws.Bool(d.Get("active").(bool)), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return err | ||
} | ||
log.Printf("[DEBUG] Created certificate from csr") | ||
|
||
d.SetId(*out.CertificateId) | ||
|
||
return resourceAwsIotCertificateRead(d, meta) | ||
} | ||
|
||
func resourceAwsIotCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
|
||
conn := meta.(*AWSClient).iotconn | ||
|
||
out, err := conn.DescribeCertificate(&iot.DescribeCertificateInput{ | ||
CertificateId: aws.String(d.Id()), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return err | ||
} | ||
|
||
d.Set("arn", out.CertificateDescription.CertificateArn) | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsIotCertificateUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).iotconn | ||
|
||
if d.HasChange("csr") { | ||
// First create certificate with new CSR | ||
out, err := conn.CreateCertificateFromCsr(&iot.CreateCertificateFromCsrInput{ | ||
CertificateSigningRequest: aws.String(d.Get("csr").(string)), | ||
SetAsActive: aws.Bool(d.Get("active").(bool)), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return nil | ||
} | ||
|
||
// If everything worked, make the old one inactive | ||
_, err = conn.UpdateCertificate(&iot.UpdateCertificateInput{ | ||
CertificateId: aws.String(d.Id()), | ||
NewStatus: aws.String("INACTIVE"), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return err | ||
} | ||
|
||
d.SetId(*out.CertificateId) | ||
|
||
} else { | ||
|
||
if d.HasChange("active") { | ||
status := "INACTIVE" | ||
if d.Get("active").(bool) { | ||
status = "ACTIVE" | ||
} | ||
|
||
_, err := conn.UpdateCertificate(&iot.UpdateCertificateInput{ | ||
CertificateId: aws.String(d.Id()), | ||
NewStatus: aws.String(status), | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return resourceAwsIotCertificateRead(d, meta) | ||
} | ||
|
||
func resourceAwsIotCertificateDelete(d *schema.ResourceData, meta interface{}) error { | ||
|
||
conn := meta.(*AWSClient).iotconn | ||
|
||
_, err := conn.UpdateCertificate(&iot.UpdateCertificateInput{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this action take a period of time? If we try and do this and AWS is performing an action, then the Delete may fail |
||
CertificateId: aws.String(d.Id()), | ||
NewStatus: aws.String("INACTIVE"), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR], %s", err) | ||
return err | ||
} | ||
|
||
_, err = conn.DeleteCertificate(&iot.DeleteCertificateInput{ | ||
CertificateId: aws.String(d.Id()), | ||
}) | ||
|
||
if err != nil { | ||
log.Printf("[ERROR] %s", err) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
69 changes: 69 additions & 0 deletions
69
builtin/providers/aws/resource_aws_iot_certificate_test.go
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,69 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/service/iot" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAWSIoTCertificate_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAWSIoTCertificateDestroy_basic, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccAWSIoTCertificate_basic, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSIoTCertificateExists_basic("aws_iot_certificate.foo_cert"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAWSIoTCertificateDestroy_basic(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).iotconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_iot_certificate" { | ||
continue | ||
} | ||
|
||
out, err := conn.ListCertificates(&iot.ListCertificatesInput{}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, t := range out.Certificates { | ||
if *t.CertificateId == rs.Primary.ID { | ||
return fmt.Errorf("IoT certificate still exists:\n%s", t) | ||
} | ||
} | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccCheckAWSIoTCertificateExists_basic(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
_, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
var testAccAWSIoTCertificate_basic = ` | ||
resource "aws_iot_certificate" "foo_cert" { | ||
csr = "${file("test-fixtures/csr.pem")}" | ||
active = true | ||
} | ||
` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to set these here