Skip to content

Commit

Permalink
Prettify tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-codaio committed Feb 23, 2020
1 parent ffc3e58 commit e1737d7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 46 deletions.
66 changes: 37 additions & 29 deletions aws/resource_aws_iot_provisioning_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,44 +120,52 @@ resource "aws_iam_role_policy_attachment" "iot_fleet_provisioning_registration"
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration"
}
data "aws_iam_policy_document" "device_policy" {
statement {
actions = ["iot:Subscribe"]
resources = ["*"]
}
}
resource "aws_iot_policy" "device_policy" {
name = "DevicePolicy"
policy = data.aws_iam_policy_document.device_policy.json
}
resource "aws_iot_provisioning_template" "fleet" {
template_name = "%s"
description = "My provisioning template"
provisioning_role_arn = aws_iam_role.iot_fleet_provisioning.arn
template_body = <<EOF
{
"Parameters": {
"SerialNumber": {
"Type": "String"
},
"AWS::IoT::Certificate::Id": {
"Type": "String"
}
},
"Resources": {
"certificate": {
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "Active"
},
"Type": "AWS::IoT::Certificate"
},
"policy": {
"Properties": {
"PolicyDocument": "{\n \"Version\": \"2012-10-17\",\n \"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": \"iot:*\",\n \"Resource\": \"*\"\n }\n ]\n}"
},
"Type": "AWS::IoT::Policy"
template_body = jsonencode({
Parameters = {
"AWS::IoT::Certificate::Id" = { Type = "String" }
SerialNumber = { Type = "String" }
}
Resources = {
certificate = {
Properties = {
CertificateId = { Ref = "AWS::IoT::Certificate::Id" }
Status = "Active"
}
Type = "AWS::IoT::Certificate"
}
policy = {
Properties = {
PolicyName = aws_iot_policy.device_policy.name
}
Type = "AWS::IoT::Policy"
}
}
}
}
EOF
})
}
`, rName)
}

func testAccAWSIoTProvisioningTemplateConfigTemplateBodyUpdate(rName string) string {
return strings.ReplaceAll(testAccAWSIoTProvisioningTemplateConfigInitialState(rName), "Allow", "Deny")
return strings.ReplaceAll(testAccAWSIoTProvisioningTemplateConfigInitialState(rName), "Active", "Inactive")
}
57 changes: 40 additions & 17 deletions website/docs/r/iot_provisioning_template.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,48 @@ resource "aws_iam_role_policy_attachment" "iot_fleet_provisioning_registration"
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration"
}
data "aws_iam_policy_document" "device_policy" {
statement {
actions = ["iot:Subscribe"]
resources = ["*"]
}
}
resource "aws_iot_policy" "device_policy" {
name = "DevicePolicy"
policy = data.aws_iam_policy_document.device_policy.json
}
resource "aws_iot_provisioning_template" "fleet" {
template_name = "FleetProvisioningTemplate"
description = "My fleet provisioning template"
provisioning_role_arn = aws_iam_role.iot_fleet_provisioning
template_body = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"iot:*"
],
"Effect": "Allow",
"Resource": "*"
template_name = "FleetTemplate"
description = "My provisioning template"
provisioning_role_arn = aws_iam_role.iot_fleet_provisioning.arn
template_body = jsonencode({
Parameters = {
"AWS::IoT::Certificate::Id" = { Type = "String" }
SerialNumber = { Type = "String" }
}
Resources = {
certificate = {
Properties = {
CertificateId = { Ref = "AWS::IoT::Certificate::Id" }
Status = "Active"
}
Type = "AWS::IoT::Certificate"
}
policy = {
Properties = {
PolicyName = aws_iot_policy.device_policy.name
}
Type = "AWS::IoT::Policy"
}
}
]
}
EOF
})
}
```

Expand Down

0 comments on commit e1737d7

Please sign in to comment.